// // Case insensitive version of Replace() // WString WString::ReplaceI ( const wchar_t* szOld, const wchar_t* szNew, bool bSearchJustReplaced ) const { WString strOldUpper = WStringX ( szOld ).ToUpper (); // Check if anything to replace first size_t idx = 0; if( ( idx = this->ToUpper ().find ( strOldUpper, idx ) ) == npos ) return *this; size_t iOldLength = wcslen ( szOld ); size_t iNewLength = wcslen ( szNew ); WString strResult = *this; do { strResult.replace ( idx, iOldLength, szNew ); if ( !bSearchJustReplaced ) idx += iNewLength; } while( ( idx = strResult.ToUpper ().find ( strOldUpper, idx ) ) != npos ); return strResult; }
////////////////////////////////////////////////////////// // // CheckAntiVirusStatus // // Maybe warn user if no anti-virus running // ////////////////////////////////////////////////////////// void CheckAntiVirusStatus( void ) { // Get data from WMI std::vector < SString > enabledList; std::vector < SString > disabledList; GetWMIAntiVirusStatus( enabledList, disabledList ); // Get status from WSC WSC_SECURITY_PROVIDER_HEALTH health = (WSC_SECURITY_PROVIDER_HEALTH)-1; if ( _WscGetSecurityProviderHealth ) { _WscGetSecurityProviderHealth( WSC_SECURITY_PROVIDER_ANTIVIRUS, &health ); } // Dump results SString strStatus( "AV health: %s (%d)", *EnumToString( health ), health ); for ( uint i = 0 ; i < enabledList.size() ; i++ ) strStatus += SString( " [Ena%d:%s]", i, *enabledList[i] ); for ( uint i = 0 ; i < disabledList.size() ; i++ ) strStatus += SString( " [Dis%d:%s]", i, *disabledList[i] ); WriteDebugEvent( strStatus ); // Maybe show dialog if av not found if ( enabledList.empty() && health != WSC_SECURITY_PROVIDER_HEALTH_GOOD ) { bool bEnableScaremongering = ( health != WSC_SECURITY_PROVIDER_HEALTH_NOTMONITORED ); if ( bEnableScaremongering ) { const char* avProducts[] = { "antivirus", "anti-virus", "Avast", "AVG", "Avira", "NOD32", "ESET", "F-Secure", "Faronics", "Kaspersky", "McAfee", "Norton", "Symantec", "Panda", "Trend Micro", }; // Check for anti-virus helper dlls before actual scaremongering HMODULE aModules[1024]; DWORD cbNeeded; if ( EnumProcessModules( GetCurrentProcess(), aModules, sizeof(aModules), &cbNeeded) ) { DWORD cModules = cbNeeded / sizeof(HMODULE); for ( uint i = 0 ; i < cModules ; i++ ) { if( aModules[i] != 0 ) { WCHAR szModulePathFileName[1024] = L""; GetModuleFileNameExW ( GetCurrentProcess(), aModules[i], szModulePathFileName, NUMELMS(szModulePathFileName) ); SLibVersionInfo libVersionInfo; GetLibVersionInfo ( ToUTF8( szModulePathFileName ), &libVersionInfo ); for( uint i = 0 ; i < NUMELMS( avProducts ) ; i++ ) { if ( libVersionInfo.strCompanyName.ContainsI( avProducts[i] ) || libVersionInfo.strProductName.ContainsI( avProducts[i] ) ) { bEnableScaremongering = false; WriteDebugEvent( SString( "AV (module) maybe found %s [%d](%s,%s)", *WStringX( szModulePathFileName ).ToAnsi(), i, *libVersionInfo.strCompanyName, *libVersionInfo.strProductName ) ); } } } } if ( bEnableScaremongering ) WriteDebugEvent( SString( "AV Searched %d dlls, but could not find av helper", cModules ) ); } if ( bEnableScaremongering ) { std::vector < DWORD > processIdList = MyEnumProcesses(); for ( uint i = 0; i < processIdList.size (); i++ ) { DWORD processId = processIdList[i]; // Skip 64 bit processes to avoid errors if ( !Is32bitProcess ( processId ) ) continue; std::vector < SString > filenameList = GetPossibleProcessPathFilenames ( processId ); for ( uint i = 0; i < filenameList.size (); i++ ) { const SString& strProcessPathFileName = filenameList[i]; SLibVersionInfo libVersionInfo; if ( GetLibVersionInfo ( strProcessPathFileName, &libVersionInfo ) ) { for( uint i = 0 ; i < NUMELMS( avProducts ) ; i++ ) { if ( libVersionInfo.strCompanyName.ContainsI( avProducts[i] ) || libVersionInfo.strProductName.ContainsI( avProducts[i] ) ) { bEnableScaremongering = false; WriteDebugEvent( SString( "AV (process) maybe found %s [%d](%s,%s)", *strProcessPathFileName, i, *libVersionInfo.strCompanyName, *libVersionInfo.strProductName ) ); } } } } } if ( bEnableScaremongering ) WriteDebugEvent( SString( "AV Searched %d processes, but could not find av helper", processIdList.size() ) ); } } ShowNoAvDialog( g_hInstance, bEnableScaremongering ); HideNoAvDialog (); } }
void WString::AssignLeft ( const wchar_t* szOther, uint uiMaxLength ) { assign ( WStringX ( szOther ).Left ( uiMaxLength ) ); }
////////////////////////////////////////////////////////// // // HandleDuplicateLaunching // // Handle duplicate launching, or running from mtasa:// URI ? // ////////////////////////////////////////////////////////// void HandleDuplicateLaunching( void ) { LPSTR lpCmdLine = GetCommandLine(); int iRecheckTimeLimit = 2000; while ( ! CreateSingleInstanceMutex () ) { if ( strcmp ( lpCmdLine, "" ) != 0 ) { HWND hwMTAWindow = FindWindow( NULL, "MTA: San Andreas" ); #ifdef MTA_DEBUG if( hwMTAWindow == NULL ) hwMTAWindow = FindWindow( NULL, "MTA: San Andreas [DEBUG]" ); #endif if( hwMTAWindow != NULL ) { LPWSTR szCommandLine = GetCommandLineW (); int numArgs; LPWSTR* aCommandLineArgs = CommandLineToArgvW ( szCommandLine, &numArgs ); for ( int i = 1; i < numArgs; ++i ) { if ( WStringX( aCommandLineArgs[i] ).BeginsWith( L"mtasa://" ) ) { WString wideConnectInfo = aCommandLineArgs[i]; SString strConnectInfo = ToUTF8 ( wideConnectInfo ); COPYDATASTRUCT cdStruct; cdStruct.cbData = strConnectInfo.length () + 1; cdStruct.lpData = const_cast<char *> ( strConnectInfo.c_str () ); cdStruct.dwData = URI_CONNECT; SendMessage( hwMTAWindow, WM_COPYDATA, NULL, (LPARAM)&cdStruct ); break; } } } else { if ( iRecheckTimeLimit > 0 ) { // Sleep a little bit and check the mutex again Sleep ( 500 ); iRecheckTimeLimit -= 500; continue; } SString strMessage; strMessage += _( "Trouble restarting MTA:SA\n\n" "If the problem persists, open Task Manager and\n" "stop the 'gta_sa.exe' and 'Multi Theft Auto.exe' processes\n\n\n" "Try to launch MTA:SA again?" ); if ( MessageBoxUTF8( 0, strMessage, _("Error")+_E("CL04"), MB_ICONWARNING | MB_YESNO | MB_TOPMOST ) == IDYES ) // Trouble restarting MTA:SA { TerminateGTAIfRunning (); TerminateOtherMTAIfRunning (); ShellExecuteNonBlocking( "open", PathJoin ( GetMTASAPath (), MTA_EXE_NAME ), lpCmdLine ); } return ExitProcess( EXIT_ERROR ); } } else { if ( !IsGTARunning () && !IsOtherMTARunning () ) { MessageBoxUTF8 ( 0, _("Another instance of MTA is already running.\n\nIf this problem persists, please restart your computer"), _("Error")+_E("CL05"), MB_ICONERROR | MB_TOPMOST ); } else if ( MessageBoxUTF8( 0, _("Another instance of MTA is already running.\n\nDo you want to terminate it?"), _("Error")+_E("CL06"), MB_ICONQUESTION | MB_YESNO | MB_TOPMOST ) == IDYES ) { TerminateGTAIfRunning (); TerminateOtherMTAIfRunning (); ShellExecuteNonBlocking( "open", PathJoin ( GetMTASAPath (), MTA_EXE_NAME ), lpCmdLine ); } } return ExitProcess( EXIT_ERROR ); } }