pbool PIni::load(const pchar *filename) { // // Look for the file in the specified path // const pchar* pathList[] = { ".", pPathGetApplicationDirectory(), pPathGetExternalStoragePath(), }; for (size_t i = 0; i < sizeof(pathList) / sizeof(pathList[0]); ++i) { if (pathList[i] != P_NULL) { PString cfgPath = PString(pathList[i]) + PString(pPathGetDelimiter()) + PString(filename); PFile *fp = pfopen(cfgPath.c_str(), "rb"); if (fp != P_NULL) { if (ini_parse_file((FILE *)(fp), iniHandler_internal, this) < 0) { PLOG_ERROR("Failed to parse %s", cfgPath.c_str()); pfclose(fp); return false; } pfclose(fp); return true; } } } // // Look for the ini file in asset // PAsset asset = pAssetOpen(filename); if (pAssetIsValid(&asset)) { PIniBufferObject iniBufferObject; iniBufferObject.m_buffer = (const pchar*)pAssetGetBuffer(&asset); iniBufferObject.m_bufferSize = pAssetGetSize(&asset); iniBufferObject.m_position = 0; if (ini_parse_buffer(&iniBufferObject, iniHandler_internal, this) < 0) { PLOG_ERROR("Failed to parse %s", filename); pAssetClose(&asset); return false; } pAssetClose(&asset); return true; } PLOG_ERROR("Failed to find %s", filename); return false; }
void PStreamAsset::close() { if (pAssetIsValid(&m_asset)) { pAssetClose(&m_asset); } }