/*========================================================= Streaming::LoadArchives Purpose: Initializes some global variables and loads all active archives into streaming memory except PLAYER.IMG. Binary offsets: (1.0 US and 1.0 EU): 0x005B82C0 =========================================================*/ void __cdecl LoadArchives( void ) { // Initialize some unknown globals. *(unsigned int*)0x008E4C90 = 0xFFFFFFFF; *(unsigned int*)0x008E4C94 = 0xFFFFFFFF; *(unsigned int*)0x008E4C98 = 0xFFFFFFFF; *(unsigned int*)0x008E4C9C = 0xFFFFFFFF; *(unsigned int*)0x008E4C8C = 0; *(unsigned int*)0x008E4CA0 = 0xFFFFFFFF; // ??? *VAR_NumResourceEntries = GetMainArchiveSize(); for ( unsigned int n = 0; n < MAX_GTA_IMG_ARCHIVES; n++ ) { IMGFile& file = imgArchives[n]; if ( file.name[0] == '\0' ) break; // We do not load player IMGs. if ( !file.isNotPlayerImg ) continue; // Load the IMG archive. LoadArchive( file, n ); } *(unsigned int*)0x008E4C64 = 0; *VAR_NumResourceEntries = *VAR_NumResourceEntries / 2048; }
/** * WriteToDisk writes the cache out to disk. Callers of WriteToDisk need to call WaitOnWriteThread * to make sure there isn't a write happening on another thread */ void StartupCache::WriteToDisk() { nsresult rv; mStartupWriteInitiated = true; if (mTable.Count() == 0) return; nsCOMPtr<nsIZipWriter> zipW = do_CreateInstance("@mozilla.org/zipwriter;1"); if (!zipW) return; rv = zipW->Open(mFile, PR_RDWR | PR_CREATE_FILE); if (NS_FAILED(rv)) { NS_WARNING("could not open zipfile for write"); return; } // If we didn't have an mArchive member, that means that we failed to // open the startup cache for reading. Therefore, we need to record // the time of creation in a zipfile comment; this will be useful for // Telemetry statistics. PRTime now = PR_Now(); if (!mArchive) { nsCString comment; comment.Assign((char *)&now, sizeof(now)); zipW->SetComment(comment); } nsCOMPtr<nsIStringInputStream> stream = do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv); if (NS_FAILED(rv)) { NS_WARNING("Couldn't create string input stream."); return; } CacheWriteHolder holder; holder.stream = stream; holder.writer = zipW; holder.time = now; for (auto key = mPendingWrites.begin(); key != mPendingWrites.end(); key++) { CacheCloseHelper(*key, mTable.Get(*key), &holder); } mPendingWrites.Clear(); mTable.Clear(); // Close the archive so Windows doesn't choke. mArchive = nullptr; zipW->Close(); // We succesfully wrote the archive to disk; mark the disk file as trusted gIgnoreDiskCache = false; // Our reader's view of the archive is outdated now, reload it. LoadArchive(gPostFlushAgeAction); return; }
void ArchiveManager::LoadSkippedArchives(const char* ArchiveDirectory) { if (*LoadedArchives == 0) return; for (IDirectoryIterator Itr(ArchiveDirectory, "*.bsa"); !Itr.Done(); Itr.Next()) { std::string FileName(Itr.Get()->cFileName); FileName = FileName.substr(FileName.rfind("\\") + 1); bool IsLoaded = false; for (ArchiveListT::Iterator Itr = (*LoadedArchives)->Begin(); !Itr.End() && Itr.Get(); ++Itr) { std::string LoadedFileName(Itr.Get()->fileName); LoadedFileName = LoadedFileName.substr(LoadedFileName.rfind("\\") + 1); if (!_stricmp(LoadedFileName.c_str(), FileName.c_str())) { IsLoaded = true; break; } } if (IsLoaded == false) { LoadArchive(FileName.c_str(), 0, 0); BGSEECONSOLE_MESSAGE("Loaded %s", FileName.c_str()); } } }
void CMainWindow::OnFileOpen() { Framework::Win32::CFileDialog dialog; const TCHAR* filter = _T("All Supported Files\0*.zip; *.rar; *.psf; *.minipsf; *.psf2; *.minipsf2; *.psfp; *.minipsfp;*") PLAYLIST_EXTENSION _T("\0") PLAYLIST_FILTER ARCHIVE_FILTER PSF_FILTER PSF2_FILTER PSFP_FILTER; dialog.m_OFN.lpstrFilter = filter; if(dialog.SummonOpen(m_hWnd)) { boost::filesystem::path filePath(dialog.GetPath()); std::wstring fileExtension = filePath.extension().wstring(); if(!wcsicmp(fileExtension.c_str(), PLAYLIST_EXTENSION)) { LoadPlaylist(filePath); } else if(!wcsicmp(fileExtension.c_str(), L".rar") || !wcsicmp(fileExtension.c_str(), L".zip")) { LoadArchive(filePath); } else { LoadSingleFile(filePath); } } }
void StartupCache::InvalidateCache() { WaitOnWriteThread(); mTable.Clear(); mArchive = NULL; mFile->Remove(false); LoadArchive(gPostFlushAgeAction); }
void StartupCache::InvalidateCache() { WaitOnWriteThread(); mTable.Clear(); mArchive = NULL; nsresult rv = mFile->Remove(false); if (NS_FAILED(rv) && rv != NS_ERROR_FILE_TARGET_DOES_NOT_EXIST && rv != NS_ERROR_FILE_NOT_FOUND) { gIgnoreDiskCache = true; return; } gIgnoreDiskCache = false; LoadArchive(gPostFlushAgeAction); }
void StartupCache::InvalidateCache() { WaitOnWriteThread(); mTable.Clear(); mArchive = nullptr; nsresult rv = mFile->Remove(false); if (NS_FAILED(rv) && rv != NS_ERROR_FILE_TARGET_DOES_NOT_EXIST && rv != NS_ERROR_FILE_NOT_FOUND) { gIgnoreDiskCache = true; mozilla::Telemetry::Accumulate(Telemetry::STARTUP_CACHE_INVALID, true); return; } gIgnoreDiskCache = false; LoadArchive(gPostFlushAgeAction); }
/** * WriteToDisk writes the cache out to disk. Callers of WriteToDisk need to call WaitOnWriteThread * to make sure there isn't a write happening on another thread */ void StartupCache::WriteToDisk() { nsresult rv; mStartupWriteInitiated = PR_TRUE; if (mTable.Count() == 0) return; nsCOMPtr<nsIZipWriter> zipW = do_CreateInstance("@mozilla.org/zipwriter;1"); if (!zipW) return; rv = zipW->Open(mFile, PR_RDWR | PR_CREATE_FILE); if (NS_FAILED(rv)) { NS_WARNING("could not open zipfile for write"); return; } nsCOMPtr<nsIStringInputStream> stream = do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv); if (NS_FAILED(rv)) { NS_WARNING("Couldn't create string input stream."); return; } CacheWriteHolder holder; holder.stream = stream; holder.writer = zipW; holder.time = PR_Now(); mTable.Enumerate(CacheCloseHelper, &holder); // Close the archive so Windows doesn't choke. mArchive = NULL; zipW->Close(); // our reader's view of the archive is outdated now, reload it. LoadArchive(); return; }
nsresult StartupCache::Init() { // workaround for bug 653936 nsCOMPtr<nsIProtocolHandler> jarInitializer(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "jar")); nsresult rv; mTable.Init(); #ifdef DEBUG mWriteObjectMap.Init(); #endif // This allows to override the startup cache filename // which is useful from xpcshell, when there is no ProfLDS directory to keep cache in. char *env = PR_GetEnv("MOZ_STARTUP_CACHE"); if (env) { rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(env), false, getter_AddRefs(mFile)); } else { nsCOMPtr<nsIFile> file; rv = NS_GetSpecialDirectory("ProfLDS", getter_AddRefs(file)); if (NS_FAILED(rv)) { // return silently, this will fail in mochitests's xpcshell process. return rv; } nsCOMPtr<nsIFile> profDir; NS_GetSpecialDirectory("ProfDS", getter_AddRefs(profDir)); if (profDir) { bool same; if (NS_SUCCEEDED(profDir->Equals(file, &same)) && !same) { // We no longer store the startup cache in the main profile // directory, so we should cleanup the old one. if (NS_SUCCEEDED( profDir->AppendNative(NS_LITERAL_CSTRING("startupCache")))) { profDir->Remove(true); } } } rv = file->AppendNative(NS_LITERAL_CSTRING("startupCache")); NS_ENSURE_SUCCESS(rv, rv); // Try to create the directory if it's not there yet rv = file->Create(nsIFile::DIRECTORY_TYPE, 0777); if (NS_FAILED(rv) && rv != NS_ERROR_FILE_ALREADY_EXISTS) return rv; rv = file->AppendNative(NS_LITERAL_CSTRING(sStartupCacheName)); NS_ENSURE_SUCCESS(rv, rv); mFile = do_QueryInterface(file); } NS_ENSURE_TRUE(mFile, NS_ERROR_UNEXPECTED); mObserverService = do_GetService("@mozilla.org/observer-service;1"); if (!mObserverService) { NS_WARNING("Could not get observerService."); return NS_ERROR_UNEXPECTED; } mListener = new StartupCacheListener(); rv = mObserverService->AddObserver(mListener, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); NS_ENSURE_SUCCESS(rv, rv); rv = mObserverService->AddObserver(mListener, "startupcache-invalidate", false); NS_ENSURE_SUCCESS(rv, rv); rv = LoadArchive(RECORD_AGE); // Sometimes we don't have a cache yet, that's ok. // If it's corrupted, just remove it and start over. if (gIgnoreDiskCache || (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND)) { NS_WARNING("Failed to load startupcache file correctly, removing!"); InvalidateCache(); } mMappingReporter = new StartupCacheMappingReporter(); mDataReporter = new StartupCacheDataReporter(); NS_RegisterMemoryReporter(mMappingReporter); NS_RegisterMemoryReporter(mDataReporter); return NS_OK; }