Skip to content

Commit c65645e

Browse files
committed
Added %ProgramData%\MTA San Andreas All\<version>\report.log to log; MTADiag now prompts for Administrator privileges on Vista and newer if UAC is enabled
1 parent 45d39ca commit c65645e

File tree

6 files changed

+48
-12
lines changed

6 files changed

+48
-12
lines changed

MTADiag/Common.h

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

25-
#define VERSION "2.3.3"
25+
#define VERSION "2.3.4"
2626

2727
#endif

MTADiag/Diag.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void Diag::Begin ( void )
7878
Log::WriteFileToLog ( MTAPath + "\\MTA\\logfile.txt", "logfile.txt" );
7979
Log::WriteFileToLog ( MTAPath + "\\MTA\\CEGUI.log", "CEGUI.log" );
8080
Log::WriteFileToLog ( MTAPath + "\\MTA\\timings.log", "timings.log" );
81+
if ( IsVistaOrNewer() ) { Log::WriteFileToLog ( programData + "\\MTA San Andreas All\\" + MTAShortVersion + "\\report.log", "report.log" ); }
8182

8283
QueryWMIC ( "Path", "Win32_VideoController", "Get" );
8384

@@ -125,6 +126,7 @@ void Diag::GeneratePaths ( void )
125126
// obtain Temp and WINDOWS environment variables, and store system time
126127
tempDir = getenv ( "Temp" ); // get the Temp directory
127128
systemRoot = getenv ( "SystemRoot" ); // get the WINDOWS directory
129+
if ( IsVistaOrNewer() ) { programData = getenv ( "ProgramData" ); } // get the ProgramData directory
128130
GetLocalTime ( &sysTime ); // get the current system time
129131

130132
// generate necessary file paths
@@ -137,11 +139,11 @@ void Diag::GeneratePaths ( void )
137139
ss.str ("");
138140
ss.clear();
139141

140-
files.push_back ( tempDir + "\\" + logFileName + ".txt" ); // files [0] ...
141-
files.push_back ( tempDir + "\\tempoutput.txt" );
142-
files.push_back ( tempDir + "\\MTANightly.exe" );
143-
files.push_back ( tempDir + "\\WMICUni.txt" );
144-
files.push_back ( systemRoot + "\\system32\\D3DX9_43.dll" );
142+
files.push_back ( tempDir + "\\" + logFileName + ".txt" ); // files [0] ... / log file path
143+
files.push_back ( tempDir + "\\tempoutput.txt" ); // general temporary output file for almost everything
144+
files.push_back ( tempDir + "\\MTANightly.exe" ); // filepath for nightly
145+
files.push_back ( tempDir + "\\WMICUni.txt" ); // WMIC command outputs as ASCII; convert to unicode for proper insertion & formatting in the log
146+
files.push_back ( systemRoot + "\\system32\\D3DX9_43.dll" ); // we check for this file to see if DirectX is up to date
145147

146148
#ifdef DEBUGOUTPUT
147149
for ( int i = 0; i < ( signed ) files.size(); i++ )
@@ -158,7 +160,7 @@ bool Diag::PollMTAVersions ( void )
158160
MTAVersionsInstalled[5] = ReadRegKey ( MTAPathValue, MTA15PathSubKey ); // store MTA 1.5 path, if present
159161

160162
// if a version isn't installed, "Failed to get key." is returned by readRegKey; clear that array element
161-
for ( int i = 1; i < CUR_MTA_VERSIONS; i++ )
163+
for ( int i = 1; i <= CUR_MTA_VERSIONS; i++ )
162164
{
163165
if ( !strcmp ( MTAVersionsInstalled[i].c_str(), "Failed to read key." ) )
164166
MTAVersionsInstalled[i].assign( "" );
@@ -167,7 +169,7 @@ bool Diag::PollMTAVersions ( void )
167169
// check how many versions of MTA:SA are installed; if there's only one, we'll narrow it down and set MTAVerChoice to that version
168170
int versionCounter = 0;
169171

170-
for (int i = 1; i < CUR_MTA_VERSIONS; i++)
172+
for (int i = 1; i <= CUR_MTA_VERSIONS; i++)
171173
{
172174
if ( !MTAVersionsInstalled[i].empty() )
173175
{
@@ -183,14 +185,14 @@ bool Diag::PollMTAVersions ( void )
183185
// or is not running this program as Administrator when they should be
184186
else if ( versionCounter == 0 )
185187
{
186-
std::cout << "Can't read MTA path." << std::endl << "You are either not running this program as an Administrator," << std::endl;
187-
std::cout << "or you may be running a version of MTA older than 1.1." << std::endl;
188+
std::cout << "Can't read MTA path." << std::endl;
189+
std::cout << "You may be running a version of MTA older than 1.1." << std::endl;
188190
std::cout << "Update at www.mtasa.com, then run MTADiag again if necessary." << std::endl;
189191
system ( "pause" );
190192
exit ( EXIT_FAILURE );
191193
}
192194
else
193-
return false; // return false signifying that there are multiple versions of MTA:SA installed
195+
return false; // return false, signifying that there are multiple versions of MTA:SA installed
194196
}
195197

196198
void Diag::UserPickVersion ( void )
@@ -249,22 +251,27 @@ std::string Diag::GetMTAVersion ( void )
249251
{
250252
case 1:
251253
MTAVersion = ReadRegKey ( MTAVerValue, MTA11VerSubKey );
254+
MTAShortVersion = "1.1";
252255
return MTAVersion;
253256
break;
254257
case 2:
255258
MTAVersion = ReadRegKey ( MTAVerValue, MTA12VerSubKey );
259+
MTAShortVersion = "1.2";
256260
return MTAVersion;
257261
break;
258262
case 3:
259263
MTAVersion = ReadRegKey ( MTAVerValue, MTA13VerSubKey );
264+
MTAShortVersion = "1.3";
260265
return MTAVersion;
261266
break;
262267
case 4:
263268
MTAVersion = ReadRegKey ( MTAVerValue, MTA14VerSubKey );
269+
MTAShortVersion = "1.4";
264270
return MTAVersion;
265271
break;
266272
case 5:
267273
MTAVersion = ReadRegKey ( MTAVerValue, MTA15VerSubKey );
274+
MTAShortVersion = "1.5";
268275
return MTAVersion;
269276
break;
270277
}

MTADiag/Diag.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include "Common.h"
1919

20-
#define CUR_MTA_VERSIONS 6 // beginning at 1; encompasses 1.1, 1.2, 1.3, 1.4, 1.5
20+
#define CUR_MTA_VERSIONS 5 // beginning at 1; encompasses 1.1, 1.2, 1.3, 1.4, 1.5
2121

2222
#define MTAPathValue "Last Install Location"
2323
#define MTA11PathSubKey "SOFTWARE\\Multi Theft Auto: San Andreas All\\1.1"
@@ -36,6 +36,13 @@
3636
#define MTA14VerSubKey "SOFTWARE\\Multi Theft Auto: San Andreas All\\1.4\\Settings\\general"
3737
#define MTA15VerSubKey "SOFTWARE\\Multi Theft Auto: San Andreas All\\1.5\\Settings\\general"
3838

39+
#define MTAShortVerValue "Last Run Path Version"
40+
#define MTA11ShortVerSubKey "SOFTWARE\\Multi Theft Auto: San Andreas All\\1.1"
41+
#define MTA12ShortVerSubKey "SOFTWARE\\Multi Theft Auto: San Andreas All\\1.2"
42+
#define MTA13ShortVerSubKey "SOFTWARE\\Multi Theft Auto: San Andreas All\\1.3"
43+
#define MTA14ShortVerSubKey "SOFTWARE\\Multi Theft Auto: San Andreas All\\1.4"
44+
#define MTA15ShortVerSubKey "SOFTWARE\\Multi Theft Auto: San Andreas All\\1.5"
45+
3946
#define MTA11NightlyURL "http://nightly.mtasa.com/?mtasa-1.1.1-rc-latest"
4047
#define MTA12NightlyURL "http://nightly.mtasa.com/?mtasa-1.2-rc-latest"
4148
#define MTA13NightlyURL "http://nightly.mtasa.com/?mtasa-1.3-rc-latest"
@@ -75,6 +82,7 @@ namespace Diag {
7582
static std::string logFileName;
7683
static std::string tempDir;
7784
static std::string systemRoot;
85+
static std::string programData;
7886
static SYSTEMTIME sysTime;
7987

8088
extern std::vector<std::string> files;
@@ -84,6 +92,7 @@ namespace Diag {
8492

8593
// store current MTA version when GetMTAVersion() is called, and store the original version to dump in the log file
8694
static std::string MTAVersion;
95+
static std::string MTAShortVersion;
8796
static std::string OriginalMTAVersion;
8897

8998
static std::string MTAVersionsInstalled[CUR_MTA_VERSIONS]; // array to store paths of all MTA versions currently installed

MTADiag/MTADiag.vcproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
Name="VCLinkerTool"
136136
AdditionalDependencies="libcurl.lib"
137137
LinkIncremental="1"
138+
UACExecutionLevel="2"
138139
GenerateDebugInformation="true"
139140
SubSystem="1"
140141
OptimizeReferences="2"

MTADiag/util.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,21 @@ void ConvertUnicodeToASCII ( std::string file1, std::string file2 )
6363
ss.clear();
6464

6565
system ( convert.c_str() );
66+
}
67+
68+
// slightly modified version of http://msdn.microsoft.com/en-us/library/ms724451%28VS.85%29.aspx
69+
bool IsVistaOrNewer ( void )
70+
{
71+
OSVERSIONINFO osvi;
72+
bool bIsVistaOrNewer;
73+
74+
ZeroMemory ( &osvi, sizeof ( OSVERSIONINFO ) );
75+
osvi.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO );
76+
77+
GetVersionEx ( &osvi );
78+
79+
if ( bIsVistaOrNewer = ( osvi.dwMajorVersion >= 6 ) )
80+
return true;
81+
else
82+
return false;
6683
}

MTADiag/util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
#ifndef UTIL_H
1616
#define UTIL_H
1717
#include "Common.h"
18+
#include <windows.h>
1819

1920
std::string ReadRegKey ( std::string value, std::string subkey );
2021
bool CheckForFile ( std::string FilePath );
2122
void ConvertUnicodeToASCII ( std::string file1, std::string file2 );
23+
bool IsVistaOrNewer ( void );
2224

2325
#endif

0 commit comments

Comments
 (0)