Skip to content

Commit 4e5ba1a

Browse files
committed
Now copies Pastebin URL to clipboard; fixed compatibility mode setting deletion; added font diagnostics
1 parent 7df7072 commit 4e5ba1a

File tree

5 files changed

+68
-19
lines changed

5 files changed

+68
-19
lines changed

MTADiag/Common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
#include <vector>
2323
#include "Log.h"
2424

25-
#define VERSION "2.4.1"
25+
#define VERSION "2.5"

MTADiag/Diag.cpp

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ void Diag::Begin ( void )
4848
else { UpdateDirectX(); DXUpdated = 1; }
4949

5050
// remove any compatibility mode settings on gta_sa.exe and/or Multi Theft Auto.exe
51+
52+
// check HKCU first
5153
CompatRemoved1 = DeleteCompatibilityEntries ( CompatModeRegKey, HKEY_CURRENT_USER );
52-
CompatRemoved2 = DeleteCompatibilityEntries ( CompatModeRegKey, HKEY_LOCAL_MACHINE );
54+
// check HKLM for compat. mode settings set for all users
55+
// only check 32-bit OSes due to compat. mode settings *NOT* being written to Wow6432Node on 64-bit OSes, and I can't seem to query non-Wow6432Node keys
56+
if ( !bIsWOW64 ) { CompatRemoved2 = DeleteCompatibilityEntries ( CompatModeRegKey, HKEY_LOCAL_MACHINE ); }
5357

5458
// update MTA to latest nightly/unstable build, depending on the version
5559
UpdateMTA();
@@ -86,7 +90,7 @@ void Diag::Begin ( void )
8690
Log::WriteFileToLog ( MTAPath + "\\MTA\\logfile.txt", "logfile.txt" );
8791
Log::WriteFileToLog ( MTAPath + "\\MTA\\CEGUI.log", "CEGUI.log" );
8892
Log::WriteFileToLog ( MTAPath + "\\MTA\\timings.log", "timings.log" );
89-
if ( IsVistaOrNewer() ) { Log::WriteFileToLog ( programData + "\\MTA San Andreas All\\" + MTAShortVersion + "\\report.log", "report.log" ); }
93+
if ( bIsVistaOrNewer ) { Log::WriteFileToLog ( programData + "\\MTA San Andreas All\\" + MTAShortVersion + "\\report.log", "report.log" ); }
9094

9195
DoSystemCommandWithOutput ( "ipconfig /all >" ); // get network configuration
9296
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
@@ -97,6 +101,11 @@ void Diag::Begin ( void )
97101
GetDir ( GTAPath );
98102
GetDir ( ( GTAPath + "\\models" ) );
99103

104+
// font diagnostics
105+
Log::WriteStringToLog ( "Verdana (TrueType) registry value:", ReadRegKey ( "Verdana (TrueType)", "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\" ) );
106+
Log::WriteStringToLog ( "" );
107+
GetDir ( systemRoot + "\\fonts\\verd*" );
108+
100109
// close the log file for writing
101110
Log::Close();
102111

@@ -105,20 +114,27 @@ void Diag::Begin ( void )
105114

106115
PasteBinResult = Curl::CreatePasteBin ( files[0], logFileName ); // store the HTTP POST result into PasteBinResult
107116

108-
// deal with a couple of errors in case there are any
109-
if ( strstr ( PasteBinResult.c_str(), "Bad API request" ) || strstr ( PasteBinResult.c_str(), "Post limit" ) )
117+
// upload successful; copy URL to clipboard
118+
if ( strstr ( PasteBinResult.c_str(), "http://pastebin.com/" ) )
119+
{
120+
if ( CopyToClipboard ( PasteBinResult ) ) // was copying to clipboard successful?
121+
{
122+
std::cout << "Pastebin link copied to your clipboard." << std::endl << "Please include the Pastebin link in your forum post." << std::endl;
123+
}
124+
else // just in case that didn't work
125+
{
126+
std::cout << "Log file uploaded to Pastebin. Please include the Pastebin link in your forum post:" << std::endl;
127+
std::cout << PasteBinResult << std::endl;
128+
}
129+
}
130+
else // upload failure
110131
{
111132
std::cout << std::endl << std::endl << "Failed to upload log file to Pastebin." << std::endl;
112133
std::cout << "Error code: \"" << PasteBinResult << "\"" << std::endl;
113134
std::cout << "Please paste the contents of the opened Wordpad window at www.pastebin.com." << std::endl;
114-
std::cout << "Include the Pastebin link in your forum post." << std::endl << std::endl;
135+
std::cout << "Include the Pastebin link in your forum post." << std::endl << std::endl;
115136
ShellExecute ( NULL, "open", "wordpad.exe", files[0].c_str(), NULL, SW_SHOW );
116137
}
117-
else // upload successful; open the pasted log file in a browser window
118-
{
119-
std::cout << "Log file uploaded to Pastebin. Please include the Pastebin link in your forum post." << std::endl;
120-
ShellExecute ( NULL, "open", "rundll32.exe", ( "url.dll,FileProtocolHandler " + PasteBinResult ).c_str(), NULL, SW_SHOW );
121-
}
122138
}
123139

124140
void Diag::Cleanup ( void )
@@ -132,9 +148,11 @@ void Diag::Cleanup ( void )
132148
void Diag::GeneratePaths ( void )
133149
{
134150
// obtain Temp and WINDOWS environment variables, and store system time
151+
bIsVistaOrNewer = IsVistaOrNewer(); // is the user running Vista or newer?
135152
tempDir = getenv ( "Temp" ); // get the Temp directory
136153
systemRoot = getenv ( "SystemRoot" ); // get the WINDOWS directory
137-
if ( IsVistaOrNewer() ) { programData = getenv ( "ProgramData" ); } // get the ProgramData directory
154+
if ( bIsVistaOrNewer ) { programData = getenv ( "ProgramData" ); } // get the ProgramData directory
155+
IsWow64Process ( GetCurrentProcess(), &bIsWOW64 ); // is MTADiag running under WOW64?
138156
GetLocalTime ( &sysTime ); // get the current system time
139157

140158
// generate necessary file paths

MTADiag/Diag.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,10 @@
4141
// Nightly download URLs
4242
#define MTA11NightlyURL "http://nightly.mtasa.com/?mtasa-1.1.1-rc-latest"
4343
#define MTA12NightlyURL "http://nightly.mtasa.com/?mtasa-1.2-rc-latest"
44-
#define MTA13NightlyURL "http://nightly.mtasa.com/?mtasa-1.3-rc-latest"
44+
#define MTA13NightlyURL "http://nightly.mtasa.com/?mtasa-1.3.1-rc-latest"
4545
#define MTA14NightlyURL "http://nightly.mtasa.com/?mtasa-1.4-unstable-latest"
4646
#define MTA15NightlyURL "http://nightly.mtasa.com/?mtasa-1.5-unstable-latest"
4747

48-
// Compatability mode registry key
49-
#define CompatModeRegKey "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"
50-
5148
namespace Diag {
5249

5350
void Begin ( void );
@@ -79,6 +76,8 @@ namespace Diag {
7976
static std::string systemRoot;
8077
static std::string programData;
8178
static SYSTEMTIME sysTime;
79+
static bool bIsVistaOrNewer;
80+
static BOOL bIsWOW64;
8281

8382
extern std::vector<std::string> files;
8483

MTADiag/util.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ bool DeleteCompatibilityEntries ( std::string subkey, HKEY hKeyType )
5555

5656
bool changed = false;
5757

58-
if ( RegOpenKeyEx ( hKeyType, subkey.c_str(), NULL, KEY_ALL_ACCESS, &hKey ) == ERROR_SUCCESS ) // if registry key read was successfully
58+
if ( RegOpenKeyEx ( hKeyType, subkey.c_str(), NULL, KEY_READ | KEY_WRITE, &hKey ) == ERROR_SUCCESS ) // if registry key read was successfully
5959
{
6060
while ( result != ERROR_NO_MORE_ITEMS ) // loop until we run out of registry values to read
6161
{
@@ -69,10 +69,9 @@ bool DeleteCompatibilityEntries ( std::string subkey, HKEY hKeyType )
6969
{
7070
if ( RegQueryValueEx ( hKey, buf, NULL, &dwType, ( BYTE* ) buf2, &dwBuf2Size ) == ERROR_SUCCESS ) // read the value's data
7171
{
72-
7372
if ( strcmp ( buf2, "~ RUNASADMIN" ) == 0 || strcmp ( buf2, "RUNASADMIN" ) == 0 ) // is the value's data already just "RUNASADMIN"?
7473
{
75-
continue; // break since we don't need to do anything
74+
continue; // continue since we don't need to do anything
7675
}
7776

7877
if ( strstr ( buf2, "RUNASADMIN" ) ) // does it contain "RUNASADMIN" along with something else?
@@ -82,13 +81,15 @@ bool DeleteCompatibilityEntries ( std::string subkey, HKEY hKeyType )
8281
char Win8Data[13] = "~ RUNASADMIN"; // set the data buffer to the proper string
8382
RegSetValueEx ( hKey, buf, 0, dwType, ( BYTE* ) Win8Data, sizeof (Win8Data) ); // set the value data to RUNASADMIN only
8483
changed = true;
84+
index--;
8585
continue;
8686
}
8787
else // 7 or older
8888
{
8989
char XPData[11] = "RUNASADMIN"; // set the data buffer to the proper string
9090
RegSetValueEx ( hKey, buf, 0, dwType, ( BYTE* ) XPData, sizeof (XPData) ); // set the value data to RUNASADMIN only
9191
changed = true;
92+
index--;
9293
continue;
9394
}
9495
}
@@ -97,6 +98,7 @@ bool DeleteCompatibilityEntries ( std::string subkey, HKEY hKeyType )
9798
{
9899
RegDeleteValue ( hKey, buf ); // delete the registry value
99100
changed = true;
101+
index--;
100102
continue;
101103
}
102104
}
@@ -136,6 +138,32 @@ void ConvertUnicodeToASCII ( std::string file1, std::string file2 )
136138
system ( convert.c_str() ); // do it
137139
}
138140

141+
bool CopyToClipboard ( std::string contents )
142+
{
143+
HGLOBAL hGlobal = GlobalAlloc ( GMEM_MOVEABLE, contents.length() + 1 ); // get a handle to store our data in the clipboard
144+
145+
if ( hGlobal ) // if handle was allocated successfully
146+
{
147+
char *szData = ( char * ) GlobalLock ( hGlobal ); // allocate a handle for the data
148+
149+
strcpy_s ( szData, contents.length() + 1, contents.c_str() ); // copy data to clipboard
150+
151+
GlobalUnlock ( hGlobal ); // free the handle
152+
153+
OpenClipboard ( NULL ); // open the clipboard
154+
155+
EmptyClipboard(); // empty any previous contents
156+
157+
SetClipboardData ( CF_TEXT, hGlobal ); // set the clipboard data to the Pastebin URL
158+
159+
CloseClipboard(); // close the clipboard
160+
161+
return true; // success
162+
}
163+
else
164+
return false; // failure
165+
}
166+
139167
// slightly modified version of http://msdn.microsoft.com/en-us/library/ms724451%28VS.85%29.aspx
140168
bool IsVistaOrNewer ( void )
141169
{

MTADiag/util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616

1717
#include "Common.h"
1818

19+
// Compatability mode registry key
20+
#define CompatModeRegKey "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"
21+
1922
std::string ReadRegKey ( std::string value, std::string subkey );
2023
bool DeleteCompatibilityEntries ( std::string subkey, HKEY hKeyType );
2124
bool CheckForFile ( std::string FilePath );
2225
void ConvertUnicodeToASCII ( std::string file1, std::string file2 );
26+
bool CopyToClipboard ( std::string contents );
2327
bool IsVistaOrNewer ( void );
2428
bool IsWin8OrNewer ( void );

0 commit comments

Comments
 (0)