Skip to content

Commit be74f6e

Browse files
committed
Windows 8 support, automatic removal of useless compatibility mode flags, other minor tweaks
1 parent a5fa748 commit be74f6e

File tree

6 files changed

+131
-89
lines changed

6 files changed

+131
-89
lines changed

MTADiag/Common.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
*
1313
*****************************************************************************/
1414

15-
#ifndef COMMON_H
16-
#define COMMON_H
15+
#pragma once
16+
1717
#include <iostream>
1818
#include <windows.h>
1919
#include <string>
@@ -22,6 +22,4 @@
2222
#include <vector>
2323
#include "Log.h"
2424

25-
#define VERSION "2.3.5"
26-
27-
#endif
25+
#define VERSION "2.4"

MTADiag/Diag.cpp

Lines changed: 23 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,29 @@ void Diag::Begin ( void )
4747
if ( CheckForFile( files[4].c_str() ) ) { std::cout << "DirectX is up-to-date." << std::endl << std::endl; }
4848
else { UpdateDirectX(); DXUpdated = 1; }
4949

50+
// remove any compatibility mode settings on gta_sa.exe and/or Multi Theft Auto.exe
51+
CompatRemoved1 = DeleteCompatibilityEntries ( CompatModeRegKey, HKEY_CURRENT_USER );
52+
CompatRemoved2 = DeleteCompatibilityEntries ( CompatModeRegKey, HKEY_LOCAL_MACHINE );
53+
5054
// update MTA to latest nightly/unstable build, depending on the version
5155
UpdateMTA();
5256

5357
// write a bunch of information to the log file since we just collected it
54-
Log::WriteStringToLog ( "MTA path: ", MTAPath );
55-
Log::WriteStringToLog ( "Old MTA version: ", OriginalMTAVersion );
56-
Log::WriteStringToLog ( "New MTA version: ", MTAVersion );
57-
Log::WriteStringToLog ( "GTA path: ", GTAPath );
58+
Log::WriteStringToLog ( "MTA path: ", MTAPath );
59+
Log::WriteStringToLog ( "Old MTA version: ", OriginalMTAVersion );
60+
Log::WriteStringToLog ( "New MTA version: ", MTAVersion );
61+
Log::WriteStringToLog ( "GTA path: ", GTAPath );
62+
5863
std::string D3D9Present = ( CheckForFile ( GTAPath + "\\D3D9.dll" ) ) ? "Yes" : "No";
59-
Log::WriteStringToLog ( "D3D9.dll present: ", D3D9Present );
64+
Log::WriteStringToLog ( "D3D9.dll present: ", D3D9Present );
6065

6166
std::string DirectXState = ( CheckForFile ( files[4] ) ) ? "Yes" : "No";
62-
Log::WriteStringToLog ( "DirectX up-to-date: ", DirectXState );
63-
if ( DXUpdated == 1 )
64-
Log::WriteStringToLog ( "DirectX was updated: Yes");
67+
Log::WriteStringToLog ( "DirectX up-to-date: ", DirectXState );
68+
if ( DXUpdated == 0 )
69+
Log::WriteStringToLog ( "DirectX was updated: Yes");
70+
71+
if ( CompatRemoved1 == true || CompatRemoved2 == true )
72+
Log::WriteStringToLog ( "Compat. mode deleted: Yes");
6573
Log::WriteStringToLog ( "" );
6674

6775
// collect more information and output to log file
@@ -72,8 +80,6 @@ void Diag::Begin ( void )
7280
DoSystemCommandWithOutput ( "dxdiag /t " );
7381
#endif
7482
DoSystemCommandWithOutput ( "tasklist >" );
75-
DoSystemCommandWithOutput ( "ipconfig /all >" );
76-
DoSystemCommandWithOutput ( "wevtutil qe Application /q:\"Event [System [(Level=2)] ] [EventData [(Data='Multi Theft Auto.exe')] ]\" /c:1 /f:text /rd:true >" );
7783

7884
// write some of MTA's logs to our log
7985
Log::WriteFileToLog ( MTAPath + "\\MTA\\core.log", "core.log" );
@@ -82,14 +88,9 @@ void Diag::Begin ( void )
8288
Log::WriteFileToLog ( MTAPath + "\\MTA\\timings.log", "timings.log" );
8389
if ( IsVistaOrNewer() ) { Log::WriteFileToLog ( programData + "\\MTA San Andreas All\\" + MTAShortVersion + "\\report.log", "report.log" ); }
8490

85-
// get some video controller information
86-
QueryWMIC ( "Path", "Win32_VideoController", "Get" );
87-
88-
// export compatibility mode registry keys and export to log only if a match for MTA or GTA is found
89-
ExportRegKeyToFile ( CompatModeRegKey1 );
90-
TrimCompatabilityExport();
91-
ExportRegKeyToFile ( CompatModeRegKey2 );
92-
TrimCompatabilityExport();
91+
DoSystemCommandWithOutput ( "ipconfig /all >" ); // get network configuration
92+
DoSystemCommandWithOutput ( "wevtutil qe Application /q:\"Event [System [(Level=2)] ] [EventData [(Data='Multi Theft Auto.exe')] ]\" /c:1 /f:text /rd:true >" ); // might help resolve Visual C++ runtime issues
93+
QueryWMIC ( "Path", "Win32_VideoController", "Get" ); // get some video controller information
9394

9495
// get directory listing of some folders
9596
GetDir ( ( MTAPath + "\\MTA" ) );
@@ -102,7 +103,7 @@ void Diag::Begin ( void )
102103
// upload to PasteBin
103104
std::cout << "Log file generated. Uploading to Pastebin..." << std::endl;
104105

105-
PasteBinResult = Curl::CreatePasteBin ( files[0], logFileName ); // store the POST result into PasteBinResult
106+
PasteBinResult = Curl::CreatePasteBin ( files[0], logFileName ); // store the HTTP POST result into PasteBinResult
106107

107108
// deal with a couple of errors in case there are any
108109
if ( strstr ( PasteBinResult.c_str(), "Bad API request" ) || strstr ( PasteBinResult.c_str(), "Post limit" ) )
@@ -116,15 +117,15 @@ void Diag::Begin ( void )
116117
else // upload successful; open the pasted log file in a browser window
117118
{
118119
std::cout << "Log file uploaded to Pastebin. Please include the Pastebin link in your forum post." << std::endl;
119-
ShellExecute ( NULL, "open", PasteBinResult.c_str(), NULL, NULL, SW_SHOW );
120+
ShellExecute ( NULL, "open", "rundll32.exe", ( "url.dll,FileProtocolHandler " + PasteBinResult ).c_str(), NULL, SW_SHOW );
120121
}
121122
}
122123

123124
void Diag::Cleanup ( void )
124125
{
125126
// clean up after ourselves
126127
// start at 1 since 0 is the generated log's path; we still need that
127-
for (int i = 1; i < ( signed ) files.size() - 1; i++) // don't delete D3DX9_43.dll
128+
for ( unsigned int i = 1; i < files.size() - 1; i++) // don't delete D3DX9_43.dll
128129
remove ( files[i].c_str() );
129130
}
130131

@@ -154,7 +155,7 @@ void Diag::GeneratePaths ( void )
154155

155156
// output contents of files vector
156157
#ifdef DEBUGOUTPUT
157-
for ( int i = 0; i < ( signed ) files.size(); i++ )
158+
for ( unsigned int i = 0; i < files.size(); i++ )
158159
std::cout << i << " " << files[i] << std::endl;
159160
#endif
160161
}
@@ -418,44 +419,4 @@ void Diag::GetDir ( std::string directory )
418419
system ( dirPath.c_str() ); // do it
419420

420421
Log::WriteFileToLog ( files[1].c_str(), ( directory + " directory listing" ) ); // write the result to the log file with a description
421-
}
422-
423-
void Diag::ExportRegKeyToFile ( std::string subkey )
424-
{
425-
std::string ExportReg;
426-
std::stringstream ss; // create a stringstream
427-
428-
ss << "regedit /e /a " << files[1] << " \"" << subkey << "\""; // regedit EXPORT ASCII <filename> <subkey>
429-
ExportReg = ss.str();
430-
431-
// clear the stringstream
432-
ss.str ("");
433-
ss.clear();
434-
435-
system ( ExportReg.c_str() ); // do it
436-
}
437-
438-
void Diag::TrimCompatabilityExport ( void )
439-
{
440-
std::ifstream file;
441-
std::string line;
442-
443-
file.open ( files[1].c_str(), std::ios::in ); // open the file with the exported registry key
444-
445-
if ( file ) // if file exists
446-
{
447-
while ( !file.eof() ) // while we haven't hit the end of the file
448-
{
449-
getline ( file, line ); // read one line
450-
451-
if ( strstr ( line.c_str(), "gta_sa.exe" ) || strstr ( line.c_str(), "Multi Theft Auto.exe" ) ) // if we get a filename match, output it to the log file
452-
{
453-
Log::WriteStringToLog ( "Compatibility registry entry match:", line );
454-
Log::WriteStringToLog ( "" );
455-
}
456-
}
457-
}
458-
Log::WriteStringToLog ( "" );
459-
460-
file.close(); // close the file for writing
461422
}

MTADiag/Diag.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
*
1313
*****************************************************************************/
1414

15-
#ifndef DIAG_H
16-
#define DIAG_H
15+
#pragma once
1716

1817
#include "Common.h"
1918

@@ -46,9 +45,8 @@
4645
#define MTA14NightlyURL "http://nightly.mtasa.com/?mtasa-1.4-unstable-latest"
4746
#define MTA15NightlyURL "http://nightly.mtasa.com/?mtasa-1.5-unstable-latest"
4847

49-
// Compatability mode registry keys
50-
#define CompatModeRegKey1 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"
51-
#define CompatModeRegKey2 "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"
48+
// Compatability mode registry key
49+
#define CompatModeRegKey "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"
5250

5351
namespace Diag {
5452

@@ -73,8 +71,6 @@ namespace Diag {
7371
// information gathering functions
7472
void DoSystemCommandWithOutput ( std::string command );
7573
void GetDir ( std::string directory );
76-
void ExportRegKeyToFile ( std::string subkey );
77-
void TrimCompatabilityExport ( void );
7874
void QueryWMIC ( std::string, std::string = "", std::string = "", std::string = "" );
7975

8076
// used for storing environment variables, current system time, files, and some paths
@@ -99,7 +95,7 @@ namespace Diag {
9995

10096
static std::string PasteBinResult; // HTTP response
10197

98+
static bool CompatRemoved1; // were any compatibility mode registry settings removed?
99+
static bool CompatRemoved2; // were any compatibility mode registry settings removed?
102100
static bool DXUpdated; // was DirectX updated by MTADiag?
103-
}
104-
105-
#endif
101+
}

MTADiag/Log.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ bool Log::WriteFileToLog ( std::string filePath, std::string itemName )
3131

3232
if ( !file ) // if we can't create the file
3333
{
34-
WriteStringToLog ( "Can't create", filePath );
34+
WriteStringToLog ( "Can't access ", filePath );
3535
WriteStringToLog ( "" );
3636
return false; // failure!
3737
}

MTADiag/util.cpp

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ std::string ReadRegKey ( std::string value, std::string subkey )
2121
DWORD dwType = 1; // REG_SZ
2222
DWORD dwBufSize = sizeof ( buf ); // buffer size
2323

24-
if ( RegOpenKey ( HKEY_LOCAL_MACHINE, subkey.c_str(), &hKey ) == ERROR_SUCCESS ) // registry key read was successful
24+
if ( RegOpenKeyEx ( HKEY_LOCAL_MACHINE, subkey.c_str(), NULL, KEY_READ, &hKey ) == ERROR_SUCCESS ) // if registry key read was successfully
2525
{
26-
if ( RegQueryValueEx ( hKey, value.c_str(), NULL, &dwType, ( BYTE* ) buf, &dwBufSize ) == ERROR_SUCCESS ) // registry value read was successful
26+
if ( RegQueryValueEx ( hKey, value.c_str(), NULL, &dwType, ( BYTE* ) buf, &dwBufSize ) == ERROR_SUCCESS ) // if registry value read was successfully
2727
{
2828
std::string value ( buf ); // store the value
2929
RegCloseKey ( hKey ); // close the registry key
@@ -41,6 +41,77 @@ std::string ReadRegKey ( std::string value, std::string subkey )
4141
}
4242
}
4343

44+
bool DeleteCompatibilityEntries ( std::string subkey, HKEY hKeyType )
45+
{
46+
HKEY hKey = 0; // handle to registry key
47+
char buf[255] = {0}; // buffer for reading registry value
48+
char buf2[255] = {0}; // buffer for reading value data
49+
DWORD dwType = 1; // REG_SZ
50+
DWORD dwBufSize = sizeof ( buf ); // registry value buffer size
51+
DWORD dwBuf2Size = sizeof ( buf2 ); // value data buffer size
52+
53+
DWORD index = 0; // index for RegEnumKeyEx
54+
long result = 0; // result of RegEnumKeyEx
55+
56+
bool changed = false;
57+
58+
if ( RegOpenKeyEx ( hKeyType, subkey.c_str(), NULL, KEY_ALL_ACCESS, &hKey ) == ERROR_SUCCESS ) // if registry key read was successfully
59+
{
60+
while ( result != ERROR_NO_MORE_ITEMS ) // loop until we run out of registry values to read
61+
{
62+
result = RegEnumValue ( hKey, index, buf, &dwBufSize, 0, NULL, NULL, NULL ); // attempt to enumerate values and store result
63+
dwBufSize = sizeof ( buf ); // set the buffer size to the read value's size
64+
65+
if ( result == ERROR_SUCCESS ) // if we read something
66+
{
67+
index++; // increment index
68+
if ( strstr ( buf, "gta_sa.exe" ) || strstr ( buf, "Multi Theft Auto.exe" ) ) // check for filename matches
69+
{
70+
if ( RegQueryValueEx ( hKey, buf, NULL, &dwType, ( BYTE* ) buf2, &dwBuf2Size ) == ERROR_SUCCESS ) // read the value's data
71+
{
72+
73+
if ( strcmp ( buf2, "~ RUNASADMIN" ) == 0 || strcmp ( buf2, "RUNASADMIN" ) == 0 ) // is the value's data already just "RUNASADMIN"?
74+
{
75+
continue; // break since we don't need to do anything
76+
}
77+
78+
if ( strstr ( buf2, "RUNASADMIN" ) ) // does it contain "RUNASADMIN" along with something else?
79+
{
80+
if ( IsWin8OrNewer() ) // is the user running Windows 8 or newer?
81+
{
82+
char Win8Data[13] = "~ RUNASADMIN"; // set the data buffer to the proper string
83+
RegSetValueEx ( hKey, buf, 0, dwType, ( BYTE* ) Win8Data, sizeof (Win8Data) ); // set the value data to RUNASADMIN only
84+
changed = true;
85+
continue;
86+
}
87+
else // 7 or older
88+
{
89+
char XPData[11] = "RUNASADMIN"; // set the data buffer to the proper string
90+
RegSetValueEx ( hKey, buf, 0, dwType, ( BYTE* ) XPData, sizeof (XPData) ); // set the value data to RUNASADMIN only
91+
changed = true;
92+
continue;
93+
}
94+
}
95+
96+
else // the user only has other compatibility mode settings enabled
97+
{
98+
RegDeleteValue ( hKey, buf ); // delete the registry value
99+
changed = true;
100+
continue;
101+
}
102+
}
103+
}
104+
}
105+
}
106+
return changed;
107+
RegCloseKey ( hKey ); // close the registry key
108+
}
109+
else
110+
{
111+
return false; // unable to read registry key
112+
}
113+
}
114+
44115
bool CheckForFile ( std::string FilePath )
45116
{
46117
std::ifstream ifile ( FilePath.c_str() );
@@ -80,4 +151,21 @@ bool IsVistaOrNewer ( void )
80151
return true;
81152
else
82153
return false;
154+
}
155+
156+
// slightly modified version of http://msdn.microsoft.com/en-us/library/ms724451%28VS.85%29.aspx
157+
bool IsWin8OrNewer ( void )
158+
{
159+
OSVERSIONINFO osvi;
160+
bool bIsWin8OrNewer;
161+
162+
ZeroMemory ( &osvi, sizeof ( OSVERSIONINFO ) );
163+
osvi.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO );
164+
165+
GetVersionEx ( &osvi );
166+
167+
if ( bIsWin8OrNewer = ( osvi.dwMajorVersion >= 6 && osvi.dwMinorVersion >= 2 ) )
168+
return true;
169+
else
170+
return false;
83171
}

MTADiag/util.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
*
1313
*****************************************************************************/
1414

15-
#ifndef UTIL_H
16-
#define UTIL_H
17-
#include "Common.h"
18-
#include <windows.h>
15+
#pragma once
1916

20-
std::string ReadRegKey ( std::string value, std::string subkey );
21-
bool CheckForFile ( std::string FilePath );
22-
void ConvertUnicodeToASCII ( std::string file1, std::string file2 );
23-
bool IsVistaOrNewer ( void );
17+
#include "Common.h"
2418

25-
#endif
19+
std::string ReadRegKey ( std::string value, std::string subkey );
20+
bool DeleteCompatibilityEntries ( std::string subkey, HKEY hKeyType );
21+
bool CheckForFile ( std::string FilePath );
22+
void ConvertUnicodeToASCII ( std::string file1, std::string file2 );
23+
bool IsVistaOrNewer ( void );
24+
bool IsWin8OrNewer ( void );

0 commit comments

Comments
 (0)