SString SharedUtil::GetReportLogContents ( void ) { SString strReportFilename = PathJoin ( GetMTADataPath (), "report.log" ); // Load file into a string std::vector < char > buffer; FileLoad ( strReportFilename, buffer ); buffer.push_back ( 0 ); return &buffer[0]; }
void SharedUtil::AddReportLog ( uint uiId, const SString& strText ) { SString strPathFilename = PathJoin ( GetMTADataPath (), "report.log" ); MakeSureDirExists ( strPathFilename ); SString strMessage ( "%u: %s %s - %s\n", uiId, GetTimeString ( true, false ).c_str (), GetReportLogHeaderText ().c_str (), strText.c_str () ); FileAppend ( strPathFilename, &strMessage.at ( 0 ), strMessage.length () ); #if MTA_DEBUG OutputDebugLine ( SStringX ( "[ReportLog] " ) + strMessage ); #endif }
////////////////////////////////////////////////////////// // // 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"; }
void CCrashDumpWriter::DumpMiniDump ( _EXCEPTION_POINTERS* pException, CExceptionInformation* pExceptionInformation ) { WriteDebugEvent ( "CCrashDumpWriter::DumpMiniDump" ); // Try to load the DLL in our directory HMODULE hDll = NULL; char szDbgHelpPath [MAX_PATH]; if ( GetModuleFileNameA ( NULL, szDbgHelpPath, MAX_PATH ) ) { char* pSlash = _tcsrchr ( szDbgHelpPath, '\\' ); if ( pSlash ) { _tcscpy ( pSlash + 1, "DBGHELP.DLL" ); hDll = LoadLibrary ( szDbgHelpPath ); } } // If we couldn't load the one in our dir, load any version available if ( !hDll ) { hDll = LoadLibrary( "DBGHELP.DLL" ); } if ( !hDll ) AddReportLog( 9201, "CCrashDumpWriter::DumpMiniDump - Could not load DBGHELP.DLL" ); // We could load a dll? if ( hDll ) { // Grab the MiniDumpWriteDump proc address MINIDUMPWRITEDUMP pDump = reinterpret_cast < MINIDUMPWRITEDUMP > ( GetProcAddress( hDll, "MiniDumpWriteDump" ) ); if ( !pDump ) AddReportLog( 9202, "CCrashDumpWriter::DumpMiniDump - Could not find MiniDumpWriteDump" ); if ( pDump ) { // Create the file HANDLE hFile = CreateFile ( CalcMTASAPath ( "mta\\core.dmp" ), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); if ( hFile == INVALID_HANDLE_VALUE ) AddReportLog( 9203, SString( "CCrashDumpWriter::DumpMiniDump - Could not create '%s'", *CalcMTASAPath ( "mta\\core.dmp" ) ) ); if ( hFile != INVALID_HANDLE_VALUE ) { // Create an exception information struct _MINIDUMP_EXCEPTION_INFORMATION ExInfo; ExInfo.ThreadId = GetCurrentThreadId (); ExInfo.ExceptionPointers = pException; ExInfo.ClientPointers = FALSE; // Write the dump BOOL bResult = pDump ( GetCurrentProcess(), GetCurrentProcessId(), hFile, (MINIDUMP_TYPE)( MiniDumpNormal | MiniDumpWithIndirectlyReferencedMemory ), &ExInfo, NULL, NULL ); if ( !bResult ) AddReportLog( 9204, SString( "CCrashDumpWriter::DumpMiniDump - MiniDumpWriteDump failed (%08x)", GetLastError() ) ); else WriteDebugEvent ( "CCrashDumpWriter::DumpMiniDump - MiniDumpWriteDump succeeded" ); // Close the dumpfile CloseHandle ( hFile ); // Grab the current time // Ask windows for the system time. SYSTEMTIME SystemTime; GetLocalTime ( &SystemTime ); // Create the dump directory CreateDirectory ( CalcMTASAPath ( "mta\\dumps" ), 0 ); CreateDirectory ( CalcMTASAPath ( "mta\\dumps\\private" ), 0 ); SString strModuleName = pExceptionInformation->GetModuleBaseName (); strModuleName = strModuleName.ReplaceI ( ".dll", "" ).Replace ( ".exe", "" ).Replace ( "_", "" ).Replace ( ".", "" ).Replace ( "-", "" ); if ( strModuleName.length () == 0 ) strModuleName = "unknown"; SString strMTAVersionFull = SString ( "%s.%s", MTA_DM_BUILDTAG_LONG, *GetApplicationSetting ( "mta-version-ext" ).SplitRight ( ".", NULL, -2 ) ); SString strSerialPart = GetApplicationSetting ( "serial" ).substr ( 0, 5 ); uint uiServerIP = GetApplicationSettingInt ( "last-server-ip" ); uint uiServerPort = GetApplicationSettingInt ( "last-server-port" ); int uiServerTime = GetApplicationSettingInt ( "last-server-time" ); int uiServerDuration = _time32 ( NULL ) - uiServerTime; uiServerDuration = Clamp ( 0, uiServerDuration + 1, 0xfff ); // Get path to mta dir SString strPathCode; { std::vector < SString > parts; PathConform ( CalcMTASAPath ( "" ) ).Split ( PATH_SEPERATOR, parts ); for ( uint i = 0 ; i < parts.size () ; i++ ) { if ( parts[i].CompareI ( "Program Files" ) ) strPathCode += "Pr"; else if ( parts[i].CompareI ( "Program Files (x86)" ) ) strPathCode += "Px"; else if ( parts[i].CompareI ( "MTA San Andreas" ) ) strPathCode += "Mt"; else if ( parts[i].BeginsWithI ( "MTA San Andreas" ) ) strPathCode += "Mb"; else strPathCode += parts[i].Left ( 1 ).ToUpper (); } } // Ensure filename parts match up with EDumpFileNameParts SString strFilename ( "mta\\dumps\\private\\client_%s_%s_%08x_%x_%s_%08X_%04X_%03X_%s_%04d%02d%02d_%02d%02d.dmp", strMTAVersionFull.c_str (), strModuleName.c_str (), pExceptionInformation->GetAddressModuleOffset (), pExceptionInformation->GetCode () & 0xffff, strPathCode.c_str (), uiServerIP, uiServerPort, uiServerDuration, strSerialPart.c_str (), SystemTime.wYear, SystemTime.wMonth, SystemTime.wDay, SystemTime.wHour, SystemTime.wMinute ); SString strPathFilename = CalcMTASAPath ( strFilename ); // Copy the file CopyFile ( CalcMTASAPath ( "mta\\core.dmp" ), strPathFilename, false ); // For the dump uploader SetApplicationSetting ( "diagnostics", "last-dump-extra", "none" ); SetApplicationSetting ( "diagnostics", "last-dump-save", strPathFilename ); // Try to append pool sizes info to dump file SetApplicationSetting ( "diagnostics", "last-dump-extra", "try-pools" ); CBuffer poolInfo; GetPoolInfo ( poolInfo ); AppendToDumpFile ( strPathFilename, poolInfo, 'POLs', 'POLe' ); SetApplicationSetting ( "diagnostics", "last-dump-extra", "added-pools" ); // Try to append d3d state info to dump file SetApplicationSetting ( "diagnostics", "last-dump-extra", "try-d3d" ); CBuffer d3dInfo; GetD3DInfo ( d3dInfo ); AppendToDumpFile ( strPathFilename, d3dInfo, 'D3Ds', 'D3De' ); SetApplicationSetting ( "diagnostics", "last-dump-extra", "added-d3d" ); // Try to append crash averted stats to dump file SetApplicationSetting ( "diagnostics", "last-dump-extra", "try-crash-averted" ); CBuffer crashAvertedStats; GetCrashAvertedStats ( crashAvertedStats ); AppendToDumpFile ( strPathFilename, crashAvertedStats, 'CASs', 'CASe' ); SetApplicationSetting ( "diagnostics", "last-dump-extra", "added-crash-averted" ); // Try to append log info to dump file SetApplicationSetting ( "diagnostics", "last-dump-extra", "try-log" ); CBuffer logInfo; GetLogInfo ( logInfo ); AppendToDumpFile ( strPathFilename, logInfo, 'LOGs', 'LOGe' ); SetApplicationSetting ( "diagnostics", "last-dump-extra", "added-log" ); // Try to append dx info to dump file SetApplicationSetting ( "diagnostics", "last-dump-extra", "try-misc" ); CBuffer dxInfo; GetDxInfo ( dxInfo ); AppendToDumpFile ( strPathFilename, dxInfo, 'DXIs', 'DXIe' ); SetApplicationSetting ( "diagnostics", "last-dump-extra", "added-misc" ); // Try to append misc info to dump file SetApplicationSetting ( "diagnostics", "last-dump-extra", "try-misc" ); CBuffer miscInfo; GetMiscInfo ( miscInfo ); AppendToDumpFile ( strPathFilename, miscInfo, 'MSCs', 'MSCe' ); SetApplicationSetting ( "diagnostics", "last-dump-extra", "added-misc" ); // Try to append memory info to dump file SetApplicationSetting ( "diagnostics", "last-dump-extra", "try-mem" ); CBuffer memInfo; GetMemoryInfo ( memInfo ); AppendToDumpFile ( strPathFilename, memInfo, 'MEMs', 'MEMe' ); SetApplicationSetting ( "diagnostics", "last-dump-extra", "added-mem" ); // Try to logfile.txt to dump file SetApplicationSetting ( "diagnostics", "last-dump-extra", "try-logfile" ); CBuffer logfileContent; logfileContent.LoadFromFile( CalcMTASAPath( PathJoin( "mta", "logs", "logfile.txt" ) ) ); AppendToDumpFile ( strPathFilename, logfileContent, 'LOGs', 'LOGe' ); SetApplicationSetting ( "diagnostics", "last-dump-extra", "added-logfile" ); // Try to report.log to dump file SetApplicationSetting ( "diagnostics", "last-dump-extra", "try-report" ); CBuffer reportLogContent; reportLogContent.LoadFromFile( PathJoin( GetMTADataPath(), "report.log" ) ); AppendToDumpFile ( strPathFilename, reportLogContent, 'REPs', 'REPe' ); SetApplicationSetting ( "diagnostics", "last-dump-extra", "added-report" ); } } // Free the DLL again FreeLibrary ( hDll ); } // Auto-fixes // Check if crash was in volumetric shadow code if ( ms_uiInCrashZone == 1 || ms_uiInCrashZone == 2 ) { CVARS_SET( "volumetric_shadows", false ); CCore::GetSingleton().SaveConfig(); AddReportLog( 9205, "Disabled volumetric shadows" ); } CNet* pNet = CCore::GetSingleton().GetNetwork(); if ( pNet ) pNet->PostCrash(); }
//////////////////////////////////////////////////// // // CNewsBrowser::InitNewsItemList // // // //////////////////////////////////////////////////// void CNewsBrowser::InitNewsItemList(void) { m_NewsitemList.clear(); // Find all sub-directories in 'news' directory SString strAllNewsDir = PathJoin(GetMTADataPath(), "news"); std::vector<SString> directoryList = FindFiles(strAllNewsDir + "\\*", false, true); std::sort(directoryList.begin(), directoryList.end()); // Get news settings SString strOldestPost; uint uiMaxHistoryLength; GetVersionUpdater()->GetNewsSettings(strOldestPost, uiMaxHistoryLength); // Process each sub-directory for (uint i = 0; i < directoryList.size(); i++) { SString strItemDir = directoryList[directoryList.size() - 1 - i]; if (strItemDir < strOldestPost) continue; // Post too old if (m_NewsitemList.size() >= uiMaxHistoryLength) continue; // Post count too high SNewsItem newsItem; newsItem.strContentFullDir = PathJoin(strAllNewsDir, strItemDir); // Get filenames from XML file CXMLFile* pFile = g_pCore->GetXML()->CreateXML(PathJoin(newsItem.strContentFullDir, "files.xml")); if (pFile) { pFile->Parse(); CXMLNode* pRoot = pFile->GetRootNode(); if (pRoot) { // Headline text CXMLNode* pHeadline = pRoot->FindSubNode("headline", 0); if (pHeadline) newsItem.strHeadline = pHeadline->GetTagContent(); // Date text CXMLNode* pDate = pRoot->FindSubNode("date", 0); if (pDate) newsItem.strDate = pDate->GetTagContent(); else newsItem.strHeadline.Split(" - ", &newsItem.strHeadline, &newsItem.strDate, true); // Layout filename CXMLNode* pLayout = pRoot->FindSubNode("layout", 0); if (pLayout) newsItem.strLayoutFilename = pLayout->GetTagContent(); // Imageset filenames CXMLNode* pImages = pRoot->FindSubNode("imagesetlist", 0); if (pImages) for (uint i = 0; i < pImages->GetSubNodeCount(); i++) newsItem.imagesetFilenameList.push_back(pImages->GetSubNode(i)->GetTagContent()); } delete pFile; } // Add to news item list if valid if (!newsItem.strHeadline.empty() && !newsItem.strLayoutFilename.empty()) m_NewsitemList.push_back(newsItem); } }
////////////////////////////////////////////////////////// // // CInstallManager::_ProcessLayoutChecks // // Make sure new reg/dir structure is ok // ////////////////////////////////////////////////////////// SString CInstallManager::_ProcessLayoutChecks ( void ) { // // Validation // // Check data dir exists { if ( !DirectoryExists ( GetMTADataPath () ) ) ShowLayoutError ( "[Data directory not present]" ); // Can't find directory } // Check reg key exists //{ // if ( GetRegistryValue ( "", "Last Install Location" ).empty () ) // ShowLayoutError ( "[Registry key not present]" ); // Can't find reg key //} // Check data dir writable { SString strTestFilePath = PathJoin ( GetMTADataPath (), "testdir", "testfile.txt" ); FileDelete ( strTestFilePath ); RemoveDirectory ( ExtractPath ( strTestFilePath ) ); SString strContent = "test"; if ( !FileSave ( strTestFilePath, strContent ) ) ShowLayoutError ( "[Data directory not writable]" ); // Can't save file FileDelete ( strTestFilePath ); RemoveDirectory ( ExtractPath ( strTestFilePath ) ); } // Check reg key writable { RemoveRegistryKey ( "testkeypath" ); SString strValue = GetTimeString( true, true ); SetRegistryValue ( "testkeypath", "testname", strValue ); SString strValueCheck = GetRegistryValue ( "testkeypath", "testname" ); if ( strValueCheck != strValue ) ShowLayoutError ( "[Registry key not writable]" ); // Can't write reg key RemoveRegistryKey ( "testkeypath" ); } // Check install dir writable { SString strTestFilePath = CalcMTASAPath ( PathJoin ( "mta", "writetest.txt" ) ); FileDelete ( strTestFilePath ); SString strContent = "test"; if ( !FileSave ( strTestFilePath, strContent ) ) ShowLayoutError ( "[Install directory not writable]" ); // Can't save file FileDelete ( strTestFilePath ); } // // Migration // // If news/temp/upcache folder doesn't exist in new, but does in old place, move it { const char* folders[] = { "news", "temp", "upcache" }; for ( uint i = 0 ; i < NUMELMS( folders ) ; i++ ) { SString strSrc = PathJoin ( GetSystemLocalAppDataPath (), "MTA San Andreas " + GetMajorVersionString (), folders[i] ); SString strDest = PathJoin ( GetMTADataPath (), folders[i] ); if ( !DirectoryExists ( strDest ) && DirectoryExists ( strSrc ) ) MoveFile ( strSrc, strDest ); } } // If aero option reg entry doesn't exist in new, but does in old place, move it { if ( GetApplicationSetting ( "aero-enabled" ).empty () ) { SString strLegacyValue = GetVersionRegistryValueLegacy ( GetMajorVersionString (), PathJoin ( "Settings", "general" ), "aero-enabled" ); if ( !strLegacyValue.empty () ) SetApplicationSettingInt ( "aero-enabled", atoi ( strLegacyValue ) ); else SetApplicationSettingInt ( "aero-enabled", 1 ); } } return "ok"; }
void SharedUtil::SetReportLogContents ( const SString& strText ) { SString strPathFilename = PathJoin ( GetMTADataPath (), "report.log" ); MakeSureDirExists ( strPathFilename ); FileSave ( strPathFilename, strText.length () ? &strText.at ( 0 ) : NULL, strText.length () ); }