////////////////////////////////////////////////////////// // // 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; } } }
/////////////////////////////////////////////////////////////// // // CDatabaseConnectionSqlite::Query // // // /////////////////////////////////////////////////////////////// bool CDatabaseConnectionSqlite::Query ( const SString& strQuery, CRegistryResult& registryResult ) { // VACUUM query does not work with transactions if ( strQuery.BeginsWithI( "VACUUM" ) ) EndAutomaticTransaction (); else BeginAutomaticTransaction (); return QueryInternal ( strQuery, registryResult ); }
// Remove base path from the start of abs path SString SharedUtil::PathMakeRelative ( const SString& strInBasePath, const SString& strInAbsPath ) { SString strBasePath = PathConform ( strInBasePath ); SString strAbsPath = PathConform ( strInAbsPath ); if ( strAbsPath.BeginsWithI ( strBasePath ) ) { return strAbsPath.SubStr ( strBasePath.length () ).TrimStart ( PATH_SEPERATOR ); } return strAbsPath; }
/////////////////////////////////////////////////////////////// // // MyShellExecute // // Returns true if successful // /////////////////////////////////////////////////////////////// static bool MyShellExecute ( bool bBlocking, const SString& strAction, const SString& strInFile, const SString& strInParameters = "", const SString& strDirectory = "", int nShowCmd = SW_SHOWNORMAL ) { SString strFile = strInFile; SString strParameters = strInParameters; if ( strAction == "open" && strFile.BeginsWithI ( "http://" ) && strParameters.empty () ) { strParameters = "url.dll,FileProtocolHandler " + strFile; strFile = "rundll32.exe"; } if ( bBlocking ) { SHELLEXECUTEINFO info; memset( &info, 0, sizeof ( info ) ); info.cbSize = sizeof ( info ); info.fMask = SEE_MASK_NOCLOSEPROCESS; info.lpVerb = strAction; info.lpFile = strFile; info.lpParameters = strParameters; info.lpDirectory = strDirectory; info.nShow = nShowCmd; bool bResult = ShellExecuteExA( &info ) != FALSE; if ( info.hProcess ) { WaitForSingleObject ( info.hProcess, INFINITE ); CloseHandle ( info.hProcess ); } return bResult; } else { int iResult = (int)ShellExecute ( NULL, strAction, strFile, strParameters, strDirectory, nShowCmd ); return iResult > 32; } }
bool CAccountManager::IntegrityCheck () { // Check database integrity { CRegistryResult result; bool bOk = m_pDatabaseManager->QueryWithResultf ( m_hDbConnection, &result, "PRAGMA integrity_check" ); // Get result as a string SString strResult; if ( result->nRows && result->nColumns ) { CRegistryResultCell& cell = result->Data.front()[0]; if ( cell.nType == SQLITE_TEXT ) strResult = std::string ( (const char *)cell.pVal, cell.nLength - 1 ); } // Process result if ( !bOk || !strResult.BeginsWithI ( "ok" ) ) { CLogger::ErrorPrintf ( "%s", *strResult ); CLogger::ErrorPrintf ( "%s\n", *m_pDatabaseManager->GetLastErrorMessage () ); CLogger::ErrorPrintf ( "Errors were encountered loading '%s' database\n", *ExtractFilename ( PathConform ( "internal.db" ) ) ); CLogger::ErrorPrintf ( "Maybe now is the perfect time to panic.\n" ); CLogger::ErrorPrintf ( "See - http://wiki.multitheftauto.com/wiki/fixdb\n" ); CLogger::ErrorPrintf ( "************************\n" ); // Allow server to continue } } // Check can update file { m_pDatabaseManager->Execf ( m_hDbConnection, "DROP TABLE IF EXISTS write_test" ); m_pDatabaseManager->Execf ( m_hDbConnection, "CREATE TABLE IF NOT EXISTS write_test (id INTEGER PRIMARY KEY, value INTEGER)" ); m_pDatabaseManager->Execf ( m_hDbConnection, "INSERT OR IGNORE INTO write_test (id, value) VALUES(1,2)" ) ; bool bOk = m_pDatabaseManager->QueryWithResultf ( m_hDbConnection, NULL, "UPDATE write_test SET value=3 WHERE id=1" ); if ( !bOk ) { CLogger::ErrorPrintf ( "%s\n", *m_pDatabaseManager->GetLastErrorMessage () ); CLogger::ErrorPrintf ( "Errors were encountered updating '%s' database\n", *ExtractFilename ( PathConform ( "internal.db" ) ) ); CLogger::ErrorPrintf ( "Database might have incorrect file permissions, or locked by another process, or damaged.\n" ); CLogger::ErrorPrintf ( "See - http://wiki.multitheftauto.com/wiki/fixdb\n" ); CLogger::ErrorPrintf ( "************************\n" ); return false; } m_pDatabaseManager->Execf ( m_hDbConnection, "DROP TABLE write_test" ); } // Do compact if required if ( g_pGame->GetConfig()->ShouldCompactInternalDatabases() ) { CLogger::LogPrintf ( "Compacting accounts database '%s' ...\n", *ExtractFilename ( PathConform ( "internal.db" ) ) ); CRegistryResult result; bool bOk = m_pDatabaseManager->QueryWithResultf ( m_hDbConnection, &result, "VACUUM" ); // Get result as a string SString strResult; if ( result->nRows && result->nColumns ) { CRegistryResultCell& cell = result->Data.front()[0]; if ( cell.nType == SQLITE_TEXT ) strResult = std::string ( (const char *)cell.pVal, cell.nLength - 1 ); } // Process result if ( !bOk ) { CLogger::ErrorPrintf ( "%s", *strResult ); CLogger::ErrorPrintf ( "%s\n", *m_pDatabaseManager->GetLastErrorMessage () ); CLogger::ErrorPrintf ( "Errors were encountered compacting '%s' database\n", *ExtractFilename ( PathConform ( "internal.db" ) ) ); CLogger::ErrorPrintf ( "Maybe now is the perfect time to panic.\n" ); CLogger::ErrorPrintf ( "See - http://wiki.multitheftauto.com/wiki/fixdb\n" ); CLogger::ErrorPrintf ( "************************\n" ); // Allow server to continue } } return true; }
bool CRegistry::IntegrityCheck ( void ) { // Check database integrity { CRegistryResult result; bool bOk = Query( &result, "PRAGMA integrity_check" ); // Get result as a string SString strResult; if ( result->nRows && result->nColumns ) { CRegistryResultCell& cell = result->Data.front()[0]; if ( cell.nType == SQLITE_TEXT ) strResult = std::string ( (const char *)cell.pVal, cell.nLength - 1 ); } // Process result if ( !bOk || !strResult.BeginsWithI ( "ok" ) ) { CLogger::ErrorPrintf ( "%s", *strResult ); CLogger::ErrorPrintf ( "%s\n", GetLastError ().c_str() ); CLogger::ErrorPrintf ( "Errors were encountered loading '%s' database\n", *ExtractFilename ( PathConform ( m_strFileName ) ) ); CLogger::ErrorPrintf ( "Maybe now is the perfect time to panic.\n" ); CLogger::ErrorPrintf ( "See - http://wiki.multitheftauto.com/wiki/fixdb\n" ); CLogger::ErrorPrintf ( "************************\n" ); return false; } } // Do compact if required if ( g_pGame->GetConfig()->ShouldCompactInternalDatabases() ) { CLogger::LogPrintf ( "Compacting database '%s' ...\n", *ExtractFilename ( PathConform ( m_strFileName ) ) ); CRegistryResult result; bool bOk = Query( &result, "VACUUM" ); // Get result as a string SString strResult; if ( result->nRows && result->nColumns ) { CRegistryResultCell& cell = result->Data.front()[0]; if ( cell.nType == SQLITE_TEXT ) strResult = std::string ( (const char *)cell.pVal, cell.nLength - 1 ); } // Process result if ( !bOk ) { CLogger::ErrorPrintf ( "%s", *strResult ); CLogger::ErrorPrintf ( "%s\n", GetLastError ().c_str() ); CLogger::ErrorPrintf ( "Errors were encountered compacting '%s' database\n", *ExtractFilename ( PathConform ( m_strFileName ) ) ); CLogger::ErrorPrintf ( "Maybe now is the perfect time to panic.\n" ); CLogger::ErrorPrintf ( "See - http://wiki.multitheftauto.com/wiki/fixdb\n" ); CLogger::ErrorPrintf ( "************************\n" ); // Allow server to continue } } return true; }
bool CRegistry::Query ( CRegistryResult* pResult, const char* szQuery, va_list vl ) { // Clear result if ( pResult ) *pResult = CRegistryResult (); if ( m_bOpened == false ) { SetLastErrorMessage ( "SQLite3 was not opened, cannot perform query!", szQuery ); return false; } SString strParsedQuery; for ( unsigned int i = 0; szQuery[i] != '\0'; i++ ) { if ( szQuery[i] != SQL_VARIABLE_PLACEHOLDER ) { strParsedQuery += szQuery[i]; } else { switch ( va_arg( vl, int ) ) { case SQLITE_INTEGER: { int iValue = va_arg( vl, int ); strParsedQuery += SString ( "%d", iValue ); } break; case SQLITE_FLOAT: { double fValue = va_arg( vl, double ); strParsedQuery += SString ( "%f", fValue ); } break; case SQLITE_TEXT: { const char* szValue = va_arg( vl, const char* ); assert ( szValue ); strParsedQuery += SString ( "'%s'", SQLEscape ( szValue, true, false ).c_str () ); } break; case SQLITE_BLOB: { strParsedQuery += "CANT_DO_BLOBS_M8"; } break; case SQLITE_NULL: { strParsedQuery += "NULL"; } break; default: // someone passed a value without specifying its type assert ( 0 ); break; } } } va_end ( vl ); // VACUUM query does not work with transactions if ( strParsedQuery.BeginsWithI( "VACUUM" ) ) EndAutomaticTransaction (); else BeginAutomaticTransaction (); return QueryInternal ( strParsedQuery.c_str (), pResult ); }