當前位置: 首頁>>代碼示例>>C++>>正文


C++ AAsset_close函數代碼示例

本文整理匯總了C++中AAsset_close函數的典型用法代碼示例。如果您正苦於以下問題:C++ AAsset_close函數的具體用法?C++ AAsset_close怎麽用?C++ AAsset_close使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了AAsset_close函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: AAssetManager_open

  void Sound_Buffer::init_SLES(const String &filename) {
    if(dynamic_cast<Sound_Renderer_SLES *>(&get_Sound().get_Renderer())) {
      // use asset manager to open asset by filename
      AAsset* asset = AAssetManager_open(File_Ops::get_AAssetManager(), (filename + ".wav").c_str(), AASSET_MODE_UNKNOWN);
      if(!asset)
        throw Sound_Buffer_Init_Failure();

      // open asset as file descriptor
      off_t start, length;
      int fd = AAsset_openFileDescriptor(asset, &start, &length);
      assert(0 <= fd);
      AAsset_close(asset);

      // configure audio source
      loc_fd = {SL_DATALOCATOR_ANDROIDFD, fd, start, length};
      format_mime = {SL_DATAFORMAT_MIME, NULL, SL_CONTAINERTYPE_UNSPECIFIED};
      audioSrc = {&loc_fd, &format_mime};
    }
  }
開發者ID:Sonophoto,項目名稱:Soar-SC,代碼行數:19,代碼來源:Sound_Buffer.cpp

示例2: AAssetManager_open

GLubyte* FileReader::loadTGA(const std::string &fileName, tgaHeader &header)
{
	AAsset* asset = AAssetManager_open(FileReader::manager, fileName.c_str(), AASSET_MODE_UNKNOWN);
	if(asset == NULL)
	{
		writeLog("Asset = NULL");
	}
    AAsset_read(asset, &header.idLength, 1);
    AAsset_read(asset, &header.colorMapType, 1);
    AAsset_read(asset, &header.type, 1);
    AAsset_seek(asset, 9, SEEK_CUR);
    AAsset_read(asset, &header.width, 2);
    AAsset_read(asset, &header.height, 2);
    AAsset_read(asset, &header.depth, 1);
    AAsset_read(asset, &header.descriptor, 1);
    AAsset_seek(asset, header.idLength, SEEK_CUR);
    
	//writeLog("spritewidth: %d, height: %d, depth: %d", header.width, header.height, header.depth);

    //24bit / 8 = 3 (RGB), 32bit / 8 = 4 (RGBA)
    int componentCount = header.depth/8;
    
    int size = componentCount * header.width * header.height;
    GLubyte* data = new GLubyte[size];
    
    AAsset_read(asset, data, size);
    
    //data is now BGRA so we format it to RGBA
    for(int i = 0; i < size; i += componentCount)
    {
        GLubyte temp = data[i];
        
        //Switch red and blue
        data[i] = data[i+2];
        data[i+2] = temp;
    }
    
    AAsset_close(asset);

	return data;

}
開發者ID:NeoLeijona,項目名稱:EVO,代碼行數:42,代碼來源:FileReader.cpp

示例3: j_moc_init

/*
 * For native implementation for java methods, if it's static method
 * belongs to class itself, then second parameter should be jclass(it
 * refers to MocClient here), otherwise, it should be jobject because
 * it's just instance of specified class.
 */
static jboolean
j_moc_init(JNIEnv *env, jobject obj,
        jobject assetManager, jstring fileStr)
{
    char *fileChars = NULL;
    if (fileStr) {
        fileChars = (char*) (*env)->GetStringUTFChars(env, fileStr, NULL);
        LOGI("moc client would to be initialized by file %s.", fileChars);
    } else {
        fileChars = "conf/mocclient.hdf";
        LOGI("moc client would to be initialized by default configurations.");
    }

    AAssetManager *manager = AAssetManager_fromJava(env, assetManager);
    assert(manager != NULL);

    AAsset *file = AAssetManager_open(manager, "conf/mocclient.hdf", AASSET_MODE_UNKNOWN);
    if (file == NULL) {
        LOGE("sepecified file does not exists in apk.");
    }

    /* read contents from config file */
    off_t bufferSize = AAsset_getLength(file);
    char *buffer     = (char*) malloc(bufferSize + 1);
    buffer[bufferSize] = 0;

    AAsset_read(file, buffer, bufferSize);

    /* close file */
    AAsset_close(file);

     moc_init_frombuf(buffer);

    /*
     * initial module calback hash table
     * but it only supports bang module currently
     */
    hash_init(&registed_callback_module_table, hash_str_hash, hash_str_comp, NULL);
    hash_insert(registed_callback_module_table, (void*) "bang", (void*) j_moc_regist_callback_bang);

    return true;
}
開發者ID:bigclean,項目名稱:moc,代碼行數:48,代碼來源:j_moc.c

示例4: Java_com_ly_widget_GifDrawable_loadGifAsset

JNIEXPORT jlong JNICALL Java_com_ly_widget_GifDrawable_loadGifAsset(JNIEnv * env, jobject  obj, jobject assetManager, jstring filepath, jarray size)
{
  int error;

  AAssetManager *mgr = AAssetManager_fromJava(env, assetManager);
  const char *native_file_path = (*env)->GetStringUTFChars(env, filepath, 0);
  AAsset* asset = AAssetManager_open(mgr, native_file_path, AASSET_MODE_UNKNOWN);
  off_t start, length;
  fd = AAsset_openFileDescriptor(asset, &start, &length);
  bytesLeft = length;
  lseek(fd, start, SEEK_SET);
  if (fd < 0) {
    return 0;
  }
  GifFileType* gif = DGifOpen(NULL,&readFunc,&error);
  error = DGifSlurp(gif);
  (*env)->ReleaseStringUTFChars(env, filepath, native_file_path);
  AAsset_close(asset);
  return loadGif(env, gif, size);
}
開發者ID:ly20050516,項目名稱:AndroidDemo,代碼行數:20,代碼來源:libgifdrawable.c

示例5: _exists

	bool _exists(const std::string &ipath) { // check for existance in platform-specific filesystem
		if (ipath.empty() || ipath.front() == '/' || ipath.compare(0, 2, "..") == 0 || ipath.find("/..") != String::npos) {
			return false;
		}

	    auto mngr = spjni::getAssetManager();
	    if (!mngr) {
	    	return false;
	    }

		auto path = _getAssetsPath(ipath);

	    AAsset* aa = AAssetManager_open(mngr, path.c_str(), AASSET_MODE_UNKNOWN);
	    if (aa) {
	    	AAsset_close(aa);
	    	return true;
	    }

	    return false;
	}
開發者ID:SBKarr,項目名稱:stappler,代碼行數:20,代碼來源:SPFilesystem.cpp

示例6: AAssetManager_open

bool FileUtilsAndroid::isFileExist(const std::string &fileName) {
	if (fileName.empty()) {
		return false;
	}
	bool result = false;
	if (fileName[0] != '/') {
		AAsset* asset = AAssetManager_open(assetmanager, fileName.c_str(), AASSET_MODE_UNKNOWN);
		if (asset) {
			result = true;
			AAsset_close(asset);
		}
	} else {
		FILE *fp = fopen(fileName.c_str(), "r");
		if (fp) {
			fclose(fp);
			result = true;
		}
	}
	return result;
}
開發者ID:BobLChen,項目名稱:opengl-es-2d-3d,代碼行數:20,代碼來源:FileUtilsAndroid.cpp

示例7: AAssetManager_open

std::string gg::Util::loadFile(const std::string &fileName)
{
	//TODO: check for invalid filenames
	AAsset* asset = AAssetManager_open(gg::AssetManager::manager, fileName.c_str(), AASSET_MODE_UNKNOWN);
	off_t length = AAsset_getLength(asset);

	char* text = new char[length+1];
	if(AAsset_read(asset, text, length) < 1)
	{
		writeLog("File not loaded! Error! Error!");
	}

	text[length] = 0;

	AAsset_close(asset);
	text[length] = 0;
	std::string r(text);

	return r;
}
開發者ID:Hangyakusha,項目名稱:TeamNoHope,代碼行數:20,代碼來源:utilAndroid.cpp

示例8: do_file_exists

bool do_file_exists(const std::string& fname)
{
	std::ifstream file(fname.c_str(), std::ios_base::binary);
	if(file.rdstate() == 0) {
        file.close();
        return true;
	}
	AAssetManager* assetManager = GetJavaAssetManager();
	AAsset* asset;
	if(fname[0] == '.' && fname[1] == '/') {
		asset = AAssetManager_open(assetManager, fname.substr(2).c_str(), AASSET_MODE_UNKNOWN);
	} else {
		asset = AAssetManager_open(assetManager, fname.c_str(), AASSET_MODE_UNKNOWN);
	}
    if(asset) {
        AAsset_close(asset);
        return true;
    }
    return false;
}
開發者ID:Marjoe,項目名稱:frogatto,代碼行數:20,代碼來源:filesystem-android.cpp

示例9: getFileDescriptor

int getFileDescriptor(const char * filename, off_t & start, off_t & length)
{
	JniMethodInfo methodInfo;
	if (! getStaticMethodInfo(methodInfo, ASSET_MANAGER_GETTER, "()Landroid/content/res/AssetManager;"))
	{
		methodInfo.env->DeleteLocalRef(methodInfo.classID);
		return FILE_NOT_FOUND;
	}
	jobject assetManager = methodInfo.env->CallStaticObjectMethod(methodInfo.classID, methodInfo.methodID);
	methodInfo.env->DeleteLocalRef(methodInfo.classID);

	AAssetManager* (*AAssetManager_fromJava)(JNIEnv* env, jobject assetManager);
	AAssetManager_fromJava = (AAssetManager* (*)(JNIEnv* env, jobject assetManager))
		dlsym(s_pAndroidHandle, "AAssetManager_fromJava");
	AAssetManager* mgr = AAssetManager_fromJava(methodInfo.env, assetManager);
	assert(NULL != mgr);

	AAsset* (*AAssetManager_open)(AAssetManager* mgr, const char* filename, int mode);
	AAssetManager_open = (AAsset* (*)(AAssetManager* mgr, const char* filename, int mode))
		dlsym(s_pAndroidHandle, "AAssetManager_open");
	AAsset* Asset = AAssetManager_open(mgr, filename, AASSET_MODE_UNKNOWN);
	if (NULL == Asset)
	{
		LOGD("file not found! Stop preload file: %s", filename);
		return FILE_NOT_FOUND;
	}

	// open asset as file descriptor
	int (*AAsset_openFileDescriptor)(AAsset* asset, off_t* outStart, off_t* outLength);
	AAsset_openFileDescriptor = (int (*)(AAsset* asset, off_t* outStart, off_t* outLength))
		dlsym(s_pAndroidHandle, "AAsset_openFileDescriptor");
	int fd = AAsset_openFileDescriptor(Asset, &start, &length);
	assert(0 <= fd);

	void (*AAsset_close)(AAsset* asset);
	AAsset_close = (void (*)(AAsset* asset))
		dlsym(s_pAndroidHandle, "AAsset_close");
	AAsset_close(Asset);

	return fd;
}
開發者ID:xahgo,項目名稱:tama,代碼行數:41,代碼來源:OpenSLEngine.cpp

示例10: _spUtil_readFile

char* _spUtil_readFile (const char* path, int* length) {

	AAssetManager* assetManager = (AAssetManager*) get_asset_manager();

	AAsset* asset = AAssetManager_open(assetManager, (const char *) path, AASSET_MODE_UNKNOWN);

	if (NULL == asset) {
		__android_log_print(ANDROID_LOG_ERROR, "SpineAndroid", "Asset (%s) not found", path);
		return NULL;
	}

	long size = AAsset_getLength(asset);

	*length = size;

	char* buffer = (char*) malloc (sizeof(char)*size);
	AAsset_read (asset,buffer,size);
	AAsset_close(asset);

	return buffer;
}
開發者ID:jasonpolites,項目名稱:spine-runtimes,代碼行數:21,代碼來源:spine_extension.cpp

示例11: assetReadSync

static void assetReadSync(JXValue *results, int argc) {
  char *filename = JX_GetString(&results[0]);

  AAsset *asset =
      AAssetManager_open(assetManager, filename, AASSET_MODE_UNKNOWN);

  free(filename);
  if (asset) {
    off_t fileSize = AAsset_getLength(asset);
    void *data = malloc(fileSize);
    int read_len = AAsset_read(asset, data, fileSize);

    JX_SetBuffer(&results[argc], (char *)data, read_len);
    free(data);
    AAsset_close(asset);
    return;
  }

  const char *err = "File doesn't exist";
  JX_SetError(&results[argc], err, strlen(err));
}
開發者ID:heocon8319,項目名稱:thingengine-platform-android,代碼行數:21,代碼來源:jxcore.cpp

示例12: IsFile

bool IsFile(const tstring& sPath)
{
	InitializeAssetManager();

	AAsset* pAsset = AAssetManager_open(g_pAssetManager, sPath.c_str(), AASSET_MODE_STREAMING);
	if (pAsset)
	{
		AAsset_close(pAsset);
		return true;
	}

	struct stat stFileInfo;
	bool blnReturn;
	int intStat;

	// Attempt to get the file attributes
	intStat = stat(sPath.c_str(), &stFileInfo);
	if(intStat == 0 && S_ISREG(stFileInfo.st_mode))
		return true;
	else
		return false;
}
開發者ID:BSVino,項目名稱:ViewbackMonitor,代碼行數:22,代碼來源:platform_android.cpp

示例13: AAssetManager_open

bool FileUtilsAndroid::isFileExistInternal(const std::string& strFilePath) const
{
    if (strFilePath.empty())
    {
        return false;
    }

    bool bFound = false;
    
    // Check whether file exists in apk.
    if (strFilePath[0] != '/')
    {
        const char* s = strFilePath.c_str();

        // Found "assets/" at the beginning of the path and we don't want it
        if (strFilePath.find(_defaultResRootPath) == 0) s += strlen("assets/");

        if (FileUtilsAndroid::assetmanager) {
            AAsset* aa = AAssetManager_open(FileUtilsAndroid::assetmanager, s, AASSET_MODE_UNKNOWN);
            if (aa)
            {
                bFound = true;
                AAsset_close(aa);
            } else {
                // CCLOG("[AssetManager] ... in APK %s, found = false!", strFilePath.c_str());
            }
        }
    }
    else
    {
        FILE *fp = fopen(strFilePath.c_str(), "r");
        if(fp)
        {
            bFound = true;
            fclose(fp);
        }
    }
    return bFound;
}
開發者ID:SBKarr,項目名稱:stappler-deps,代碼行數:39,代碼來源:CCFileUtils-android.cpp

示例14: LoadShader

int LoadShader(GLuint Shader, char *Filename)
{
	AAsset *stream;
	char *buffer;
	int length;

	if((stream=AAssetManager_open(assetManager, Filename, AASSET_MODE_BUFFER))==NULL)
		return 0;

	length=AAsset_getLength(stream);

	buffer=(char *)malloc(length+1);
	AAsset_read(stream, buffer, length);
	buffer[length]='\0';

	glShaderSource(Shader, 1, (const char **)&buffer, &length);

	AAsset_close(stream);
	free(buffer);

	return 1;
}
開發者ID:seishuku,項目名稱:gauges,代碼行數:22,代碼來源:main.c

示例15: test_apk

/********************************************************************
 * Test for asset
 *******************************************************************/
void test_apk(struct android_app* state)
{
    AAssetManager* mgr = state->activity->assetManager;
    AAsset* asset = AAssetManager_open(mgr,
                                       "fuck.txt", AASSET_MODE_UNKNOWN);

    if(asset == NULL)
    {
        LOGI("assets == NULL");
    }

    off_t size = AAsset_getLength(asset);
    LOGI("size=%d",size);

    char* buffer = new char[size+1];
    buffer[size] = 0;

    int num_read = AAsset_read(asset, buffer, size);
    //LOGI(buffer);

    AAsset_close(asset);
}
開發者ID:gaoguanglei,項目名稱:Android-OpenGL-ES-2.0-Effects,代碼行數:25,代碼來源:android_main.cpp


注:本文中的AAsset_close函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。