std::vector<SString> SharedUtil::FindFiles(const SString& strMatch, bool bFiles, bool bDirectories, bool bSortByDate) { std::vector<SString> strResult; std::multimap<uint64, SString> sortMap; DIR* Dir; struct dirent* DirEntry; // Extract any filename matching characters SString strFileMatch; SString strSearchDirectory = PathJoin(PathConform(strMatch).SplitLeft("/", &strFileMatch, -1), "/"); if ((Dir = opendir(strSearchDirectory))) { while ((DirEntry = readdir(Dir)) != NULL) { // Skip dotted entries if (strcmp(DirEntry->d_name, ".") && strcmp(DirEntry->d_name, "..")) { struct stat Info; bool bIsDir = false; // Do wildcard matching if required if (!strFileMatch.empty() && !WildcardMatch(strFileMatch, DirEntry->d_name)) { continue; } SString strPath = PathJoin(strSearchDirectory, DirEntry->d_name); // Determine the file stats if (lstat(strPath, &Info) != -1) bIsDir = S_ISDIR(Info.st_mode); if (bIsDir ? bDirectories : bFiles) { if (bSortByDate) { SString strAbsPath = strSearchDirectory + DirEntry->d_name; struct stat attrib; stat(strAbsPath, &attrib); MapInsert(sortMap, (uint64)attrib.st_mtime, SStringX(DirEntry->d_name)); } else strResult.push_back(DirEntry->d_name); } } } closedir(Dir); } // Resolve sorted map if required if (!sortMap.empty()) { for (std::multimap<uint64, SString>::iterator iter = sortMap.begin(); iter != sortMap.end(); ++iter) strResult.push_back(iter->second); } return strResult; }
static void staticPathList(std::list<CString>& paths, std::set<CString>& folders, const CString& startDir, const CString& folder, BOOL recursive) { CString strDirectory = PathJoin(startDir, folder); CFileFind finder; BOOL bWorking = finder.FindFile(strDirectory + _T("\\*.*")); while (bWorking) { bWorking = finder.FindNextFile(); CString filename = finder.GetFileName(); if (filename == "." || filename == "..") continue; if (finder.IsDirectory()) { if (recursive) { staticPathList(paths, folders, startDir, PathJoin(folder, filename), recursive); } folders.insert(PathJoin(folder, filename)); } else { paths.push_back(PathJoin(folder, filename)); } } }
void TestPath() { printf("TestPath()\n"); assert(Canonicalize("", "") == ""); assert(Canonicalize("", "baker") == "baker"); assert(Canonicalize("able", "") == "able"); assert(Canonicalize("able", "baker") == "able/baker"); assert(Canonicalize("able/", "baker") == "able/baker"); assert(Canonicalize("baker/charlie", "#delta") == "delta"); assert(Canonicalize("baker/charlie", "#") == ""); assert(Canonicalize("baker/charlie", "#../external") == "../external"); assert(Canonicalize("baker/charlie", "..") == "baker"); assert(Canonicalize("baker/charlie", "delta") == "baker/charlie/delta"); assert(Canonicalize("baker/charlie", "../delta") == "baker/delta"); assert(Canonicalize("baker/charlie/", "../delta") == "baker/delta"); assert(Canonicalize("baker/charlie", "../../delta") == "delta"); assert(Canonicalize("baker/charlie", "../..") == ""); assert(Canonicalize("baker/charlie", "../../../external") == "../external"); assert(Canonicalize("baker/charlie", "#:test") == ":test"); assert(PathJoin("a/b/c", "x/y/z") == "a/b/c/x/y/z"); assert(PathJoin("a/b/..", "x/y/z") == "a/b/../x/y/z"); assert(PathJoin("../..", "../x/y/z") == "../../../x/y/z"); assert(IsAbsolute("hello") == false); assert(IsAbsolute("hello/there") == false); assert(IsAbsolute("../hello") == false); assert(IsAbsolute("../../hello/there") == false); assert(IsAbsolute("/hello") == true); assert(IsAbsolute("c:/hello/there") == true); assert(IsAbsolute("C:/hello/there") == true); assert(IsAbsolute("c:\\hello\\there") == true); assert(IsAbsolute("C:\\hello\\there") == true); }
void CCrashHandler::Init ( const SString& strInServerPath ) { SString strServerPath = strInServerPath; if ( strServerPath == "" ) strServerPath = GetSystemCurrentDirectory(); ms_strDumpPath = PathJoin( strServerPath, SERVER_DUMP_PATH ); // Set a global filter #ifdef WIN32 SetCrashHandlerFilter ( HandleExceptionGlobal ); #else // Prepare initial dumpfile name time_t pTime = time( NULL ); struct tm* tm = localtime( &pTime ); SString strFilename( "server_%s_%04d%02d%02d_%02d%02d.dmp", MTA_DM_BUILDTAG_LONG, tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min ); ms_strDumpPathFilename = PathJoin( ms_strDumpPath, strFilename ); MakeSureDirExists( ms_strDumpPathFilename ); #ifdef WITH_BACKTRACE_ONLY signal ( SIGSEGV, HandleExceptionGlobal ); #else google_breakpad::MinidumpDescriptor descriptor( ms_strDumpPath ); static google_breakpad::ExceptionHandler eh( descriptor, NULL, DumpCallback, NULL, true, -1 ); #endif #endif }
// Searches for an existing header file. Returns true and fills in // *header_path if it finds one. bool FindHeader(const string& src_dir, const Target* t, const Context* context, const string& header_file, bool is_quoted, string* header_path) { // TODO: handle absolute header file names, // (e.g. #include "/abs/path/header.h" or "c:/somefile.h") if (is_quoted) { // First look in the directory where the source file was found. string path = PathJoin(src_dir, header_file); if (FileExists(path)) { *header_path = path; return true; } } for (size_t i = 0; i < t->inc_dirs().size(); i++) { // TODO: handle absolute inc_dirs string path = PathJoin(context->tree_root(), t->inc_dirs()[i]); path = PathJoin(path, header_file); if (FileExists(path)) { *header_path = path; return true; } } return false; }
// Linux crash callback when using google-breakpad bool DumpCallback( const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded ) { // Set inital dump file name (Safeish) File::Rename( descriptor.path(), ms_strDumpPathFilename ); // Set final dump file name (Not so safe) time_t pTime = time( NULL ); struct tm* tm = localtime( &pTime ); SString strFilename( "server_%s_%04d%02d%02d_%02d%02d.dmp", MTA_DM_BUILDTAG_LONG, tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min ); SString strFinalDumpPathFilename = PathJoin( ms_strDumpPath, strFilename ); File::Rename( ms_strDumpPathFilename, strFinalDumpPathFilename ); SaveBacktraceSummary(); FileSave( PathJoin( ms_strDumpPath, "server_pending_upload_filename" ), strFinalDumpPathFilename ); // Return false to indicate exception has not been handled (and allow core dump?) return false; }
SString CResourceFile::GetCachedPathFilename(bool bForceClientCachePath) { if (IsNoClientCache() == false || bForceClientCachePath) return PathJoin(g_pServerInterface->GetServerModPath(), "resource-cache", "http-client-files", m_resource->GetName(), GetName()); else return PathJoin(g_pServerInterface->GetServerModPath(), "resource-cache", "http-client-files-no-client-cache", m_resource->GetName(), GetName()); }
void MUSImporter::PlayMusic(char* name) { char FName[_MAX_PATH]; if (strnicmp( name, "mx9000", 6 ) == 0) { //iwd2 PathJoin(FName, "mx9000", name, NULL); } else if (strnicmp( name, "mx0000", 6 ) == 0) { //iwd PathJoin(FName, "mx0000", name, NULL); } else if (strnicmp( name, "SPC", 3 ) != 0) { //bg2 char File[_MAX_PATH]; snprintf(File, _MAX_PATH, "%s%s", PLName, name); PathJoin(FName, PLName, File, NULL); } else { strncpy(FName, name, _MAX_PATH); } ResourceHolder<SoundMgr> sound(FName, manager); if (sound) { int soundID = core->GetAudioDrv()->CreateStream( sound ); if (soundID == -1) { core->GetAudioDrv()->Stop(); } } else { core->GetAudioDrv()->Stop(); } printf( "Playing: %s\n", FName ); }
static bool PathExists(BIFEntry *entry, const char *path) { PathJoin(entry->path, path, entry->name, NULL); if (file_exists(entry->path)) { return true; } PathJoin(entry->path, path, AddCBF(entry->name), NULL); if (file_exists(entry->path)) { return true; } return false; }
static void SaveBacktraceSummary() { // Collect backtrace information void * buffer [ 100 ]; int iAmount = backtrace ( buffer, sizeof buffer ); iAmount = std::min < int > ( iAmount, NUMELMS( buffer ) ); char ** symbols = backtrace_symbols ( buffer, iAmount ); // Generate a .log file time_t pTime = time ( NULL ); struct tm * tm = localtime ( &pTime ); SString sFileName; sFileName.Format ( "server_%s_%04d%02d%02d_%02d%02d.log", MTA_DM_BUILDTYPE, tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min ); SString sContent; sContent += SString ( "MTA:SA Server v%s-r%d-%s crash report.\n", MTA_DM_VERSIONSTRING, MTASA_VERSION_BUILD, MTA_DM_BUILDTYPE ); sContent += SString ( "%04d-%02d-%02d %02d:%02d\n", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min ); sContent += SString ( "Caught %d addresses ...\n\n", iAmount ); sContent += "Backtrace:\n"; for ( int i = 0; i < iAmount; i++ ) { if ( symbols [ i ] ) { sContent += SString ( "#%d - %s\n", i, symbols [ i ] ); } } sContent += std::string( 80, '-' ) + "\n"; // Write the content to the file and close MakeSureDirExists ( PathJoin( ms_strDumpPath, sFileName ) ); FileAppend( PathJoin( ms_strDumpPath, sFileName ), sContent ); FileAppend( PathJoin( ms_strDumpPath, "server_pending_upload.log" ), sContent ); free ( symbols ); // Try to close window gracefully if ( !g_bSilent && !g_bNoCurses && m_wndInput ) { if ( m_wndMenu ) { delwin ( m_wndMenu ); m_wndMenu = NULL; } delwin ( m_wndInput ); m_wndInput = NULL; endwin ( ); } }
////////////////////////////////////////////////////////// // // CInstallManager::_InstallNewsItems // // // ////////////////////////////////////////////////////////// SString CInstallManager::_InstallNewsItems ( void ) { // Get install news queue CArgMap queue; queue.SetFromString ( GetApplicationSetting ( "news-install" ) ); SetApplicationSetting ( "news-install", "" ); std::vector < SString > keyList; queue.GetKeys ( keyList ); for ( uint i = 0 ; i < keyList.size () ; i++ ) { // Install each file SString strDate = keyList[i]; SString strFileLocation = queue.Get ( strDate ); // Save cwd SString strSavedDir = GetSystemCurrentDirectory (); // Calc and make target dir SString strTargetDir = PathJoin ( GetMTADataPath (), "news", strDate ); MkDir ( strTargetDir ); // Extract into target dir SetCurrentDirectory ( strTargetDir ); // Try to extract the files if ( !ExtractFiles ( strFileLocation ) ) { // If extract failed and update file is an exe, try to run it if ( ExtractExtension ( strFileLocation ).CompareI ( "exe" ) ) ShellExecuteBlocking ( "open", strFileLocation, "-s" ); } // Restore cwd SetCurrentDirectory ( strSavedDir ); // Check result if ( FileExists ( PathJoin ( strTargetDir, "files.xml" ) ) ) { SetApplicationSettingInt ( "news-updated", 1 ); AddReportLog ( 2051, SString ( "InstallNewsItems ok for '%s'", *strDate ) ); } else { AddReportLog ( 4048, SString ( "InstallNewsItems failed with '%s' '%s' '%s'", *strDate, *strFileLocation, *strTargetDir ) ); } } return "ok"; }
/////////////////////////////////////////////////////////////// // // CServerIdManagerImpl::CServerIdManagerImpl // // // /////////////////////////////////////////////////////////////// CServerIdManagerImpl::CServerIdManagerImpl ( void ) { // Calc private dir root m_strServerIdLookupBaseDir = PathJoin ( g_pClientGame->GetFileCacheRoot(), MTA_SERVERID_LOOKUP_DIR ); MakeSureDirExists ( PathJoin ( m_strServerIdLookupBaseDir, "" ) ); // Calc temp dir path incase of server id error m_strTempErrorDir = PathJoin ( m_strServerIdLookupBaseDir, "_error" ); // If temp dir has been used, clean it if ( DirectoryExists ( m_strTempErrorDir ) ) DelTree ( m_strTempErrorDir, m_strServerIdLookupBaseDir ); LoadServerIdMap (); }
CachedFileStream::CachedFileStream(CachedFileStream* cfs, int startpos, int size, bool autoFree) { this->size = size; this->startpos = startpos; this->autoFree = autoFree; char cpath[_MAX_PATH]; PathJoin( cpath, core->CachePath, cfs->filename, NULL ); str = _fopen( cpath, "rb" ); if (str == NULL) { str = _fopen( cfs->originalfile, "rb" ); if (str == NULL) { printf( "Can't open stream (maybe leaking?)\n" ); return; } strncpy( originalfile, cfs->originalfile, sizeof(originalfile) ); strncpy( filename, cfs->filename, sizeof(filename) ); } else { strncpy( originalfile, cpath, sizeof(originalfile) ); strncpy( filename, cfs->filename, sizeof(filename) ); } #ifdef _DEBUG core->CachedFileStreamPtrCount++; #endif _fseek( str, startpos, SEEK_SET ); Pos = 0; }
// // Toggle hook on/off. // Enable caching and faster loading of clothes files // void CMultiplayerSA::SetFastClothesLoading(EFastClothesLoading fastClothesLoading) { if (m_FastClothesLoading == fastClothesLoading) return; m_FastClothesLoading = fastClothesLoading; // Handle auto setting if (fastClothesLoading == FAST_CLOTHES_AUTO) { // Disable if less than 512MB installed ram long long llSystemRamKB = GetWMITotalPhysicalMemory() / 1024LL; if (llSystemRamKB > 0 && llSystemRamKB < 512 * 1024) fastClothesLoading = FAST_CLOTHES_OFF; } if (fastClothesLoading != FAST_CLOTHES_OFF) { // Load and cache player.img SString strGTASAPath = GetCommonRegistryValue("", "GTA:SA Path"); SString strFilename = PathJoin(strGTASAPath, "models", "player.img"); FileLoad(strFilename, m_PlayerImgCache); } else { // Remove cached data - Note: This method ensures the memory is actually freed std::vector<char>().swap(m_PlayerImgCache); } // Update the cache pointer if (!m_PlayerImgCache.empty()) ms_PlayerImgCachePtr = &m_PlayerImgCache[0]; else ms_PlayerImgCachePtr = NULL; }
/////////////////////////////////////////////////////////////// // // CServerIdManagerImpl::StaticSaveServerIdMap // // // /////////////////////////////////////////////////////////////// void CServerIdManagerImpl::StaticSaveServerIdMap ( void ) { CXMLFile* pConfigFile = g_pCore->GetXML ()->CreateXML ( PathJoin ( g_pClientGame->GetFileCacheRoot(), MTA_SERVERID_LOOKUP_XML ) ); if ( !pConfigFile ) return; pConfigFile->Reset (); CXMLNode* pRoot = pConfigFile->GetRootNode (); if ( !pRoot ) pRoot = pConfigFile->CreateRootNode ( "root" ); // Transfer each item from m_ServerIdMap into the file for ( std::map < CServerIdKey, CServerIdInfo >::iterator it = ms_ServerIdMap.begin () ; it != ms_ServerIdMap.end () ; ++it ) { const SString& strId = it->first.strId; const SString& strDir = it->second.strDir; CXMLNode* pSubNode = pRoot->CreateSubNode ( "id" ); pSubNode->SetTagContent ( strId ); pSubNode->GetAttributes().Create ( "dir" )->SetValue ( strDir ); } pConfigFile->Write (); delete pConfigFile; }
////////////////////////////////////////////////////////// // // CInstallManager::GetLauncherPathFilename // // Get path to launch exe // ////////////////////////////////////////////////////////// SString CInstallManager::GetLauncherPathFilename ( void ) { SString strLocation = m_pSequencer->GetVariable ( INSTALL_LOCATION ); SString strResult = PathJoin ( strLocation == "far" ? GetSystemCurrentDirectory () : GetMTASAPath (), MTA_EXE_NAME ); AddReportLog ( 1062, SString ( "GetLauncherPathFilename %s", *strResult ) ); return strResult; }
std::vector < SString > SharedUtil::FindFiles ( const SString& strMatch, bool bFiles, bool bDirectories ) { std::vector < SString > strResult; DIR *Dir; struct dirent *DirEntry; if ( ( Dir = opendir ( strMatch ) ) ) { while ( ( DirEntry = readdir ( Dir ) ) != NULL ) { // Skip dotted entries if ( strcmp ( DirEntry->d_name, "." ) && strcmp ( DirEntry->d_name, ".." ) ) { struct stat Info; bool bIsDir = false; SString strPath = PathJoin ( strMatch, DirEntry->d_name ); // Determine the file stats if ( lstat ( strPath, &Info ) != -1 ) bIsDir = S_ISDIR ( Info.st_mode ); if ( bIsDir ? bDirectories : bFiles ) strResult.push_back ( DirEntry->d_name ); } } } return strResult; }
/////////////////////////////////////////////////////////////// // // CServerIdManagerImpl::LoadServerIdMap // // Load server id data from xml file // /////////////////////////////////////////////////////////////// bool CServerIdManagerImpl::LoadServerIdMap ( void ) { // Load config XML file CXMLFile* pConfigFile = g_pCore->GetXML ()->CreateXML ( PathJoin ( g_pClientGame->GetFileCacheRoot(), MTA_SERVERID_LOOKUP_XML ) ); if ( !pConfigFile ) return false; pConfigFile->Parse (); CXMLNode* pRoot = pConfigFile->GetRootNode (); if ( !pRoot ) pRoot = pConfigFile->CreateRootNode ( "root" ); m_ServerIdMap.clear (); // Read each node for ( uint i = 0 ; i < pRoot->GetSubNodeCount () ; i++ ) { CXMLNode* pSubNode = pRoot->GetSubNode ( i ); CServerIdKey key; CServerIdInfo info; key.strId = pSubNode->GetTagContent (); if ( CXMLAttribute* pAttribute = pSubNode->GetAttributes().Find ( "dir" ) ) info.strDir = pAttribute->GetValue (); if ( !info.strDir.empty () ) MapSet ( m_ServerIdMap, key, info ); } // Maybe one day remove unwanted directories delete pConfigFile; return true; }
SString SharedUtil::MakeUniquePath ( const SString& strInPathFilename ) { const SString strPathFilename = PathConform ( strInPathFilename ); SString strBeforeUniqueChar, strAfterUniqueChar; SString strPath, strFilename; ExtractFilename ( strPathFilename, &strPath, &strFilename ); SString strMain, strExt; if ( ExtractExtension ( strFilename, &strMain, &strExt ) ) { strBeforeUniqueChar = PathJoin ( strPath, strMain ); strAfterUniqueChar = "." + strExt; } else { strBeforeUniqueChar = strPathFilename; strAfterUniqueChar = ""; } SString strTest = strPathFilename; int iCount = 1; #ifdef WIN32 while ( GetFileAttributes ( strTest ) != INVALID_FILE_ATTRIBUTES ) #else while ( DirectoryExists ( strTest ) || FileExists ( strTest ) ) #endif { strTest = SString ( "%s_%d%s", strBeforeUniqueChar.c_str (), iCount++, strAfterUniqueChar.c_str () ); } return strTest; }
/////////////////////////////////////////////////////////////// // // CPerfStatBandwidthUsageImpl::CPerfStatBandwidthUsageImpl // // // /////////////////////////////////////////////////////////////// CPerfStatBandwidthUsageImpl::CPerfStatBandwidthUsageImpl ( void ) { m_strCategoryName = "Bandwidth usage"; SString strDatabaseFilename = PathJoin ( g_pGame->GetConfig ()->GetSystemDatabasesPath (), "stats.db" ); m_DatabaseConnection = g_pGame->GetDatabaseManager ()->Connect ( "sqlite", strDatabaseFilename ); LoadStats (); }
void PathUtilsSuite_TestPathJoin( PathUtilsSuiteData* data ) { char searchPaths[1024]; unsigned len; PathJoin( searchPaths, 1, "." ); len = strlen( searchPaths ); searchPaths[len] = ':'; PathJoin( &searchPaths[len + 1], 2, ".", "data" ); len = strlen( searchPaths ); searchPaths[len] = ':'; PathJoin( &searchPaths[len + 1], 6, "..", "..", "..", "does", "not", "exist" ); pcu_check_streq( searchPaths, ".:./data:../../../does/not/exist" ); }
Holder<SaveGame> SaveGameIterator::GetSaveGame(const char *slotname) { if (!slotname) { return NULL; } int prtrt = 0; char Path[_MAX_PATH]; //lets leave space for the filenames PathJoin(Path, core->SavePath, SaveDir(), slotname, NULL); char savegameName[_MAX_PATH]={0}; int savegameNumber = 0; int cnt = sscanf( slotname, SAVEGAME_DIRECTORY_MATCHER, &savegameNumber, savegameName ); //maximum pathlength == 240, without 8+3 filenames if ( (cnt != 2) || (strlen(Path)>240) ) { printf( "Invalid savegame directory '%s' in %s.\n", slotname, Path ); return NULL; } DirectoryIterator dir(Path); if (!dir) { return NULL; } do { if (strnicmp( dir.GetName(), "PORTRT", 6 ) == 0) prtrt++; } while (++dir); SaveGame* sg = new SaveGame( Path, savegameName, core->GameNameResRef, slotname, prtrt, savegameNumber ); return sg; }
// Factory. Res Object::Create(const Context* context, const string& path, const Json::Value& value, Object** object) { *object = NULL; string name = PathJoin(path, value["name"].asString()); if (!value.isMember("type")) { return Res(ERR_PARSE, "object '" + name + "' has no type"); } if (!value["type"].isString()) { return Res(ERR_PARSE, "object type is not a string"); } const string& type = value["type"].asString(); if (type == "exe") { *object = new ExeTarget(); } else if (type == "lib") { *object = new LibTarget(); } else if (type == "external_lib") { *object = new ExternalLibTarget(); } else if (type == "generic") { *object = new GenericTarget(); } else if (type == "config") { *object = new Config(); } else { return Res(ERR_PARSE, "unknown type: " + type); } assert(object); return (*object)->Init(context, name, value); }
bool SaveGameIterator::RescanSaveGames() { // delete old entries save_slots.clear(); char Path[_MAX_PATH]; PathJoin(Path, core->SavePath, SaveDir(), NULL); DirectoryIterator dir(Path); // create the save game directory at first access if (!dir) { mkdir(Path,S_IWRITE|S_IREAD|S_IEXEC); chmod(Path,S_IWRITE|S_IREAD|S_IEXEC); dir.Rewind(); } if (!dir) { //If we cannot open the Directory return false; } std::set<char*,iless> slots; do { const char *name = dir.GetName(); if (dir.IsDirectory() && IsSaveGameSlot( Path, name )) { slots.insert(strdup(name)); } } while (++dir); for (std::set<char*,iless>::iterator i = slots.begin(); i != slots.end(); i++) { save_slots.push_back(GetSaveGame(*i)); free(*i); } return true; }
// On success, currdir_relative_to_root will be a canonical path. Res FindRoot(string* absolute_root, string* currdir_relative_to_root) { string currdir = GetCurrentDir(); // Look for root dir. Root dir is marked by the presence of a // "root.dmb" file. string root = currdir; for (;;) { if (FileExists(PathJoin(root, "root.dmb"))) { break; } if (HasParentDir(root)) { root = ParentDir(root); } else { return Res(ERR, "Can't find root.dmb in ancestor directories"); } } *absolute_root = root; const char* remainder = currdir.c_str() + root.length(); if (remainder[0] == '/') { remainder++; } *currdir_relative_to_root = remainder; assert(currdir_relative_to_root->size() == 0 || (*currdir_relative_to_root)[currdir_relative_to_root->length() - 1] != '/'); return Res(OK); }
////////////////////////////////////////////////////////// // // GetPatchRequirementAltModules // // Return true if checksum for some dlls will cause problems // ////////////////////////////////////////////////////////// bool GetPatchRequirementAltModules( void ) { // Only do file check once per launch static bool bDone = false; static bool bMismatch = false; if ( !bDone ) { SString strGTAPath = GetGTAPath(); if ( !strGTAPath.empty() ) { struct { const char* szMd5; const char* szFilename; } fileList[] = { { "309D860FC8137E5FE9E7056C33B4B8BE", "eax.dll" }, { "0602F672BA595716E64EC4040E6DE376", "ogg.dll" }, { "2840F08DD9753A5B13C60D6D1C165C9A", "vorbis.dll" }, { "2B7B803311D2B228F065C45D13E1AEB2", "vorbisfile.dll" } }; for ( uint i = 0 ; i < NUMELMS( fileList ) ; i++ ) { SString strPathFilename = PathJoin( strGTAPath, fileList[i].szFilename ); SString strMd5 = CMD5Hasher::CalculateHexString( strPathFilename ); if ( strMd5.CompareI( fileList[i].szMd5 ) == false ) bMismatch = true; } } bDone = true; if ( bMismatch ) WriteDebugEvent( "PatchRequirementAltModules: Need to use alt modules" ); } return bMismatch; }
string Canonicalize(const string& base_dir, const string& relative_path) { if (relative_path.size() && relative_path[0] == '#') { // '#' indicates a path relative to the project root. return string(relative_path, 1); } return PathJoin(base_dir, relative_path); }
sMenuItem* CMainMenu::CreateItem(unsigned char menuType, const char* szFilename, CVector2D vecRelPosition) { CGUIStaticImage* pImage = reinterpret_cast<CGUIStaticImage*>(m_pManager->CreateStaticImage()); if (g_pCore->GetLocalization()->IsLocalized()) { if (!pImage->LoadFromFile(PathJoin(g_pCore->GetLocalization()->GetLanguageDirectory(), szFilename))) pImage->LoadFromFile(PathJoin("cgui/images", szFilename)); } else pImage->LoadFromFile(PathJoin("cgui/images", szFilename)); // Make our positions absolute int iPosX = vecRelPosition.fX * m_iMenuSizeX; int iPosY = vecRelPosition.fY * m_iMenuSizeY; // Make our sizes relative to the size of menu, but in absolute coordinates CVector2D vecNativeSize; pImage->GetNativeSize(vecNativeSize); int iSizeX = (vecNativeSize.fX / NATIVE_RES_X) * m_iMenuSizeX; int iSizeY = (vecNativeSize.fY / NATIVE_RES_Y) * m_iMenuSizeY; // Mark our bounding box's bottom value. m_menuBY = (iPosY + (iSizeY * CORE_MTA_HOVER_SCALE) / 2) + m_iYOff; m_menuBY += BODGE_FACTOR_2; // Reduced their size down to unhovered size. iSizeX = iSizeX * CORE_MTA_NORMAL_SCALE; iSizeY = iSizeY * CORE_MTA_NORMAL_SCALE; // Grab our draw position from which we enlarge from iPosY = iPosY - (iSizeY / 2); pImage->SetParent(m_pCanvas); pImage->SetPosition(CVector2D(iPosX, iPosY), false); pImage->SetSize(CVector2D(iSizeX, iSizeY), false); pImage->SetProperty("InheritsAlpha", "False"); pImage->SetAlpha(CORE_MTA_NORMAL_ALPHA); sMenuItem* s = new sMenuItem(); s->menuType = menuType; s->drawPositionX = vecRelPosition.fX * m_iMenuSizeX; s->drawPositionY = vecRelPosition.fY * m_iMenuSizeY; s->nativeSizeX = vecNativeSize.fX; s->nativeSizeY = vecNativeSize.fY; s->image = pImage; return s; }
////////////////////////////////////////////////////////// // // HandleNotUsedMainMenu // // Called when a problem occured before the main menu was used by user // If fullscreen, then maybe change fullscreen mode // ////////////////////////////////////////////////////////// void HandleNotUsedMainMenu ( void ) { AddReportLog( 9310, "Loader - HandleNotUsedMainMenu" ); { // Slighty hacky way of checking in-game settings SString strCoreConfigFilename = CalcMTASAPath( PathJoin( "mta", "config", "coreconfig.xml" ) ); SString strCoreConfig; FileLoad( strCoreConfigFilename, strCoreConfig ); SString strWindowed = strCoreConfig.SplitRight( "<display_windowed>" ).Left( 1 ); SString strFullscreenStyle = strCoreConfig.SplitRight( "<display_fullscreen_style>" ).Left( 1 ); if ( strFullscreenStyle == "1" ) { AddReportLog( 9315, "Loader - HandleNotUsedMainMenu - Already Borderless window" ); } else if ( !strWindowed.empty() && !strFullscreenStyle.empty()) { if ( strWindowed == "0" && strFullscreenStyle == "0" ) // 0=FULLSCREEN_STANDARD { // Inform user SString strMessage = _("Are you having problems running MTA:SA?.\n\nDo you want to change the following setting?"); strMessage += "\n" + _("Fullscreen mode:") + " -> " + _("Borderless window"); HideSplash(); int iResponse = MessageBoxUTF8 ( NULL, strMessage, "MTA: San Andreas", MB_YESNO | MB_ICONQUESTION | MB_TOPMOST ); if ( iResponse == IDYES ) { // Very hacky way of changing in-game settings strCoreConfig = strCoreConfig.Replace( "<display_fullscreen_style>0", "<display_fullscreen_style>1" ); FileSave( strCoreConfigFilename, strCoreConfig ); AddReportLog( 9311, "Loader - HandleNotUsedMainMenu - User change to Borderless window" ); } else AddReportLog( 9313, "Loader - HandleNotUsedMainMenu - User said no" ); } else AddReportLog( 9314, "Loader - HandleNotUsedMainMenu - Mode not fullscreen standard" ); } else { // If no valid settings file yet, do the change without asking strCoreConfig = "<mainconfig><settings><display_fullscreen_style>1</display_fullscreen_style></settings></mainconfig>"; FileSave( strCoreConfigFilename, strCoreConfig ); AddReportLog( 9312, "Loader - HandleNotUsedMainMenu - Set Borderless window" ); } } // Check if Evolve is active for ( auto processId : MyEnumProcesses( true ) ) { SString strFilename = ExtractFilename( GetProcessPathFilename( processId ) ); if ( strFilename.BeginsWithI( "Evolve" ) ) { SString strMessage = _("Are you having problems running MTA:SA?.\n\nTry disabling the following products for GTA and MTA:"); strMessage += "\n\nEvolve"; DisplayErrorMessageBox ( strMessage, _E("CL43"), "not-used-menu-evolve" ); break; } } }
static void CreateSavePath(char *Path, int index, const char *slotname) { PathJoin( Path, core->SavePath, SaveDir(), NULL ); //if the path exists in different case, don't make it again mkdir(Path,S_IWRITE|S_IREAD|S_IEXEC); chmod(Path,S_IWRITE|S_IREAD|S_IEXEC); //keep the first part we already determined existing char dir[_MAX_PATH]; snprintf( dir, _MAX_PATH, "%09d-%s", index, slotname ); PathJoin(Path, Path, dir, NULL); //this is required in case the old slot wasn't recognised but still there core->DelTree(Path, false); mkdir(Path,S_IWRITE|S_IREAD|S_IEXEC); chmod(Path,S_IWRITE|S_IREAD|S_IEXEC); }