本文整理汇总了C++中AAsset_read函数的典型用法代码示例。如果您正苦于以下问题:C++ AAsset_read函数的具体用法?C++ AAsset_read怎么用?C++ AAsset_read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AAsset_read函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadFileAsset
void ReadFileAsset(const tstring & path, star::SerializedData & data)
{
auto app = star::StarEngine::GetInstance()->GetAndroidApp();
auto manager = app->activity->assetManager;
AAsset* asset = AAssetManager_open(
manager,
star::string_cast<sstring>(path.c_str()).c_str(),
AASSET_MODE_UNKNOWN
);
star::Logger::GetInstance()->Log(asset != NULL,
_T("Couldn't find '") + path + _T("'."));
data.size = AAsset_getLength(asset);
data.data = new schar[sizeof(schar) * data.size];
AAsset_read(asset, data.data, data.size);
AAsset_close(asset);
}
示例2: writeLog
bool FileReader::read(unsigned int count, void*buffer)
{
writeLog("%d %x %x", count, buffer, asset);
if(asset != nullptr)
{
writeLog("not null or sumthin");
if(AAsset_read(asset, buffer,count) >=0)
{
writeLog("everything went better than expedition");
return true;
}
}
writeLog("Null asset");
return false;
}
示例3: DEBUGPRINT
size_t FileInput::read(unsigned char *buffer, size_t size)
{
if(!m_asset || !buffer)
{
Console::Print(Console::Error, "Could not read from file.");
return 0;
}
DEBUGPRINT("Reading %i bytes from asset %x", size, m_asset);
int returnval = AAsset_read(m_asset, buffer, size);
DEBUGPRINT("AAsset_read returned %i", returnval);
return returnval;
}
示例4: vertexShaderStream
char* Renderer::LoadKernelFromAssets(const string * path)
{
#ifdef PLATFORM_WINDOWS
string prefix = "kernelsPC/";
#else
string prefix = "kernels/";
#endif
string suffix = ".glsl";
string fPath = prefix + *path + suffix;
#ifdef PLATFORM_WINDOWS
fPath = Renderer::GetInstance()->ASSET_PATH + fPath;
string sCode;
ifstream vertexShaderStream(fPath.c_str(), ios::in);
if (vertexShaderStream.is_open())
{
string Line = "";
while (getline(vertexShaderStream, Line))
{
sCode += "\n" + Line;
}
vertexShaderStream.close();
}
int length = sCode.length();
char* ret = new char[length + 1];
strcpy(ret, sCode.c_str());
ret[length] = '\0';
return ret;
#else
AAssetManager* mgr = System::GetInstance()->GetEngineData()->app->activity->assetManager;
AAsset* shaderAsset = AAssetManager_open(mgr, fPath.c_str(), AASSET_MODE_UNKNOWN);
unsigned int length = AAsset_getLength(shaderAsset);
char * code = new char[length + 1];
AAsset_read(shaderAsset, (void*)code, length);
code[length] = '\0';
return code;
#endif
}
示例5: File_Read
WRes File_Read(CSzFile *p, void *data, size_t *size)
{
size_t originalSize = *size;
if (originalSize == 0)
return 0;
#ifdef USE_WINDOWS_FILE
*size = 0;
do
{
DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
DWORD processed = 0;
BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);
data = (void *)((Byte *)data + processed);
originalSize -= processed;
*size += processed;
if (!res)
return GetLastError();
if (processed == 0)
break;
}
while (originalSize > 0);
return 0;
#else
if(p->mgr)
{
msg_Dbg("file read");
#ifndef ANDROID22
if(p->asset)
*size = AAsset_read(p->asset,data,originalSize);
#endif
if (*size == originalSize)
return 0;
return -1;
}
else
{
*size = fread(data, 1, originalSize, p->file);
if (*size == originalSize)
return 0;
return ferror(p->file);
}
#endif
}
示例6: jsModulesDir
bool JniJSModulesUnbundle::isUnbundle(
AAssetManager *assetManager,
const std::string& assetName) {
if (!assetManager) {
return false;
}
auto magicFileName = jsModulesDir(assetName) + MAGIC_FILE_NAME;
auto asset = openAsset(assetManager, magicFileName.c_str());
if (asset == nullptr) {
return false;
}
magic_number_t fileHeader = 0;
AAsset_read(asset.get(), &fileHeader, sizeof(fileHeader));
return fileHeader == htole32(MAGIC_FILE_HEADER);
}
示例7: esFileRead
///
// esFileRead()
//
// Wrapper for platform specific File read
//
static size_t esFileRead ( esFile *pFile, int bytesToRead, void *buffer )
{
size_t bytesRead = 0;
if ( pFile == NULL )
{
return bytesRead;
}
#ifdef ANDROID
bytesRead = AAsset_read ( pFile, buffer, bytesToRead );
#else
bytesRead = fread ( buffer, bytesToRead, 1, pFile );
#endif
return bytesRead;
}
示例8: LoadMesh
/**
* Load a scene from a supported 3D file format
*
* @param filename Name of the file (or asset) to load
* @param flags (Optional) Set of ASSIMP processing flags
*
* @return Returns true if the scene has been loaded
*/
bool LoadMesh(const std::string& filename, int flags = defaultFlags)
{
#if defined(__ANDROID__)
// Meshes are stored inside the apk on Android (compressed)
// So they need to be loaded via the asset manager
AAsset* asset = AAssetManager_open(assetManager, filename.c_str(), AASSET_MODE_STREAMING);
assert(asset);
size_t size = AAsset_getLength(asset);
assert(size > 0);
void *meshData = malloc(size);
AAsset_read(asset, meshData, size);
AAsset_close(asset);
pScene = Importer.ReadFileFromMemory(meshData, size, flags);
free(meshData);
#else
pScene = Importer.ReadFile(filename.c_str(), flags);
#endif
if (pScene)
{
m_Entries.clear();
m_Entries.resize(pScene->mNumMeshes);
// Read in all meshes in the scene
for (auto i = 0; i < m_Entries.size(); i++)
{
m_Entries[i].vertexBase = numVertices;
numVertices += pScene->mMeshes[i]->mNumVertices;
const aiMesh* paiMesh = pScene->mMeshes[i];
InitMesh(&m_Entries[i], paiMesh, pScene);
}
return true;
}
else
{
printf("Error parsing '%s': '%s'\n", filename.c_str(), Importer.GetErrorString());
#if defined(__ANDROID__)
LOGE("Error parsing '%s': '%s'", filename.c_str(), Importer.GetErrorString());
#endif
return false;
}
}
示例9: loadCompressedTexture
bool loadCompressedTexture(GLenum target, int level, GLenum internalFormat, int width,
int height, const std::string& fileName)
{
#if defined(SUPPORT_ANDROID)
AAsset* asset = AAssetManager_open(ctx.assetManager, fileName.c_str(), O_RDONLY);
if (!asset)
{
LOGW("Unable to open asset %s", fileName.c_str());
return false;
}
off_t size = AAsset_getLength(asset);
void* pixels = malloc(size);
AAsset_read(asset, pixels, size);
AAsset_close(asset);
#else // !SUPPORT_ANDROID
int fd = open(fileName.c_str(), O_RDONLY);
if (fd == -1)
{
perror("open");
return false;
}
struct stat sb;
if (fstat(fd, &sb) == -1)
{
perror("stat");
return false;
}
off_t size = sb.st_size;
void* pixels = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
#endif // !SUPPORT_ANDROID
glCompressedTexImage2D(target, level, internalFormat, width, height, 0, size, pixels);
#if defined(SUPPORT_ANDROID)
free(pixels);
#else
munmap(pixels, sb.st_size);
close(fd);
#endif
ASSERT_GL();
return true;
}
示例10: androidExtract
bool androidExtract( const std::string& name ) {
const char* pFile = name.c_str();
std::string newPath = androidGetPath(pFile);
AAssetDir* a;
if ( androidExtracted(name.c_str()) ) {
FLOG_DEBUG("File %s already extracted", name.c_str());
return true;
}
AAsset* asset = AAssetManager_open(gActivity->assetManager, name.c_str(),
AASSET_MODE_STREAMING);
std::string assetContent;
if (asset != NULL) {
// Find size
off_t assetSize = AAsset_getLength(asset);
// Prepare input buffer
assetContent.resize(assetSize);
// Store input buffer
AAsset_read(asset, &assetContent[0], assetSize);
// Close
AAsset_close(asset);
// Prepare output buffer
std::ofstream assetExtracted(newPath.c_str(),
std::ios::out | std::ios::binary);
if (!assetExtracted) {
FLOG_ERROR("File %s not extracted", newPath.c_str());
return false;
}
// Write output buffer into a file
assetExtracted.write(assetContent.c_str(), assetSize);
assetExtracted.close();
FLOG_DEBUG("File extracted");
return true;
} else {
FLOG_ERROR("File %s not extracted. Returning empty string", name.c_str());
return false;
}
}
示例11: BEHAVIAC_LOGERROR
bool CFileSystem::ReadFile(Handle file, void* pBuffer, uint32_t nNumberOfBytesToRead, uint32_t* pNumberOfBytesRead) {
if (!file) {
BEHAVIAC_LOGERROR("File not open");
return 0;
}
#if BEHAVIAC_CCDEFINE_ANDROID && (BEHAVIAC_CCDEFINE_ANDROID_VER > 8)
size_t ret = AAsset_read((AAsset*)file, pBuffer, nNumberOfBytesToRead);
#else
size_t ret = fread(pBuffer, 1, nNumberOfBytesToRead, (FILE*)file);
#endif
if (pNumberOfBytesRead) {
*pNumberOfBytesRead = ret;
}
return true;
}
示例12: 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;
}
示例13: fopen
char *
VSShaderLib::textFileRead(std::string fileName) {
char *content = NULL;
#ifndef __ANDROID_API__
FILE *fp;
size_t count=0;
if (fileName != "") {
fp = fopen(fileName.c_str(),"rt");
if (fp != NULL) {
fseek(fp, 0, SEEK_END);
count = ftell(fp);
rewind(fp);
if (count > 0) {
content = (char *)malloc(sizeof(char) * (count+1));
count = fread(content, sizeof(char), count, fp);
content[count] = '\0';
}
fclose(fp);
}
}
return content;
#else
AAsset* asset = AAssetManager_open(s_AssetManager, fileName.c_str(), AASSET_MODE_UNKNOWN);
const char *loc = "VSShaderLib::readText";
if (NULL == asset) {
__android_log_print(ANDROID_LOG_ERROR, loc, "%s", "_ASSET_NOT_FOUND_");
return content;
}
size_t size = (size_t)AAsset_getLength(asset);
content = (char*)malloc(sizeof(char)*size + 1);
AAsset_read(asset, content, size);
content[size] = '\0';
__android_log_print(ANDROID_LOG_DEBUG, loc, "%s", content);
AAsset_close(asset);
return content;
#endif
}
示例14: AAssetManager_open
FileUtils::FileData FileUtils::getFileData(const char* fileName)
{
DebugLog::print( "FileUtils::getFileData(%s)", fileName );
AAsset* asset = AAssetManager_open(g_aassetManager, (const char *) fileName, AASSET_MODE_UNKNOWN);
if (NULL == asset) {
DebugLog::print("Failed !");
return FileData();
}
long size = AAsset_getLength(asset);
FileData res = findFreeFileDataSlot(size);
res.size = size;
AAsset_read (asset, res.bytes, size);
AAsset_close(asset);
return res;
}
示例15: androidExtractAll
bool androidExtractAll() {
AAssetDir* assetDir = AAssetManager_openDir(gActivity->assetManager, "");
const char* filename = (const char*)NULL;
std::string assetContent;
while ((filename = AAssetDir_getNextFileName(assetDir)) != NULL) {
std::string newPath = androidGetPath(filename);
AAsset* asset = AAssetManager_open(gActivity->assetManager, filename,
AASSET_MODE_STREAMING);
FLOG_DEBUG("File %s opened for extraction ...", filename );
// Find size
off_t assetSize = AAsset_getLength(asset);
// Prepare input buffer
assetContent.resize(assetSize);
// Store input buffer
AAsset_read(asset, &assetContent[0], assetSize);
// Close
AAsset_close(asset);
// Check if file exists
std::ifstream f(newPath.c_str());
if (f.good()) {
f.close();
FLOG_DEBUG("Asset %s already extracted", filename);
} else {
// Prepare output buffer
std::ofstream assetExtracted(newPath.c_str(),
std::ios::out | std::ios::binary);
if (!assetExtracted) {
FLOG_ERROR("File %s not extracted", newPath.c_str());
return false;
}
// Write output buffer into a file
assetExtracted.write(assetContent.c_str(), assetSize);
assetExtracted.close();
FLOG_DEBUG("File %s extracted", filename);
}
}
return true;
AAssetDir_close(assetDir);
}