void DiskCachingFileLoaderCache::InitCache(const std::string &path) { cacheSize_ = 0; indexCount_ = 0; oldestGeneration_ = 0; maxBlocks_ = MAX_BLOCKS_LOWER_BOUND; flags_ = 0; generation_ = 0; const std::string cacheFilePath = MakeCacheFilePath(path); bool fileLoaded = LoadCacheFile(cacheFilePath); // We do some basic locking to protect against two things: crashes and concurrency. // Concurrency will break the file. Crashes will probably leave it inconsistent. if (fileLoaded && !LockCacheFile(true)) { if (RemoveCacheFile(cacheFilePath)) { // Create a new one. fileLoaded = false; } else { // Couldn't remove, in use? Give up on caching. CloseFileHandle(); } } if (!fileLoaded) { CreateCacheFile(cacheFilePath); if (!LockCacheFile(true)) { CloseFileHandle(); } } }
void CEnumStrGenerator::Init(const std::vector<TString>& scanPathList, const TCHAR* pszCacheFileName) { if (!LoadCacheFile(pszCacheFileName)) { for(uint32_t i = 0; i < scanPathList.size(); ++i) { ScanEnumInDirectory(scanPathList[i].c_str()); } SaveCacheFile(pszCacheFileName); } m_bInitFlag = true; }
long Cx_PluginLoader::InLoadPlugins(const std::vector<std::wstring>& filenames, bool enableDelayLoading) { long count = 0; std::vector<std::wstring>::const_iterator it; if (!filenames.empty()) { if (enableDelayLoading) { LoadCacheFile(filenames.front().c_str()); } for (it = filenames.begin(); it != filenames.end(); ++it) { if (LoadPluginOrDelay(it->c_str(), enableDelayLoading)) { count++; } } } return count; }