Skip to content

Commit 8b57fb9

Browse files
committed
Added MTA version checker to see if it matches current auto-update nightly build; updated some comments
1 parent 3cb2494 commit 8b57fb9

File tree

5 files changed

+65
-15
lines changed

5 files changed

+65
-15
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.6.4"
25+
#define VERSION "2.7"

MTADiag/Diag.cpp

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,43 @@ void Diag::Begin ( void )
7272
exit ( EXIT_FAILURE ); // exit
7373
};
7474

75-
// update MTA to latest nightly/unstable build, depending on the major version
76-
UpdateMTA();
75+
// check if MTA version matches the latest auto-update nightly
76+
if ( Curl::DownloadFile ( MTAVerURL, files[5].c_str() ) ) // download the version appropriation HTML
77+
{
78+
std::string MTAVersionTrim = MTAVersion; // copy the MTAVersion string
79+
MTAVersionTrim.resize ( 15 ); // trim the MTAVersion string stored in registry to 15 characters; the version appropriation HTML has a 15 char string lacking two trailing zeros
80+
if ( FindInFile ( files[5].c_str(), ( MTAVersionTrim ) ) ) // look for the current MTA version string in it
81+
std::cout << "MTA is up-to-date." << std::endl << std::endl; // we've found it, hooray, we don't need to update MTA
82+
else
83+
UpdateMTA(); // update MTA to latest nightly / unstable build, depending on MTA's major version
84+
}
7785

78-
// write a bunch of information to the log file since we just collected it
86+
// write some information to the log file
7987
Log::WriteStringToLog ( "MTA path: ", MTAPath );
88+
89+
if ( MTAUpdated ) // was MTA updated? if so, list the old and new versions
90+
{
8091
Log::WriteStringToLog ( "Old MTA version: ", OriginalMTAVersion );
8192
Log::WriteStringToLog ( "New MTA version: ", MTAVersion );
93+
}
94+
else // list the current version of MTA
95+
{
96+
Log::WriteStringToLog ( "MTA version: ", MTAVersion );
97+
}
98+
8299
Log::WriteStringToLog ( "GTA path: ", GTAPath );
83100

101+
// is D3D9 present in GTA:SA directory despite MTA:SA's own warning?
84102
std::string D3D9Present = ( CheckForFile ( GTAPath + "\\D3D9.dll" ) ) ? "Yes" : "No";
85103
Log::WriteStringToLog ( "D3D9.dll present: ", D3D9Present );
86104

105+
// is D3DX9_43.dll present? second check to ensure it was updated
87106
std::string DirectXState = ( CheckForFile ( files[4] ) ) ? "Yes" : "No";
88107
Log::WriteStringToLog ( "DirectX up-to-date: ", DirectXState );
89108
if ( DXUpdated == 1 )
90109
Log::WriteStringToLog ( "DirectX was updated: Yes");
91110

111+
// was an erroneous compatibility mode setting removed?
92112
if ( CompatRemoved1 == true || CompatRemoved2 == true )
93113
Log::WriteStringToLog ( "Compat. mode deleted: Yes");
94114
Log::WriteStringToLog ( "" );
@@ -118,6 +138,7 @@ void Diag::Begin ( void )
118138
GetDir ( GTAPath );
119139
GetDir ( ( GTAPath + "\\models" ) );
120140

141+
// get relevant MD5sums
121142
Log::WriteStringToLog ( GetFileMD5 ( GTAPath + "\\gta_sa.exe" ) );
122143
Log::WriteStringToLog ( "Value should be: 170b3a9108687b26da2d8901c6948a18 (HOODLUM 1.0)" );
123144
Log::WriteStringToLog ( GetFileMD5 ( GTAPath + "\\models\\gta3.img" ) );
@@ -167,7 +188,7 @@ void Diag::Cleanup ( bool deleteLog )
167188
// clean up after ourselves
168189
// start at 1 since 0 is the generated log's path; we still need that
169190
for ( unsigned int i = 1; i < files.size() - 1; i++) // don't delete D3DX9_43.dll
170-
remove ( files[i].c_str() );
191+
remove ( files[i].c_str() ); // delete the file
171192

172193
if ( deleteLog )
173194
{
@@ -179,14 +200,15 @@ void Diag::Cleanup ( bool deleteLog )
179200
void Diag::GeneratePaths ( void )
180201
{
181202
// obtain Temp and WINDOWS environment variables, and store system time
182-
tempDir = getenv ( "Temp" ); // get the Temp directory
183-
systemRoot = getenv ( "SystemRoot" ); // get the WINDOWS directory
184-
programData = getenv ( "AllUsersProfile" ); // get the ProgramData directory
185-
IsWow64Process ( GetCurrentProcess(), &bIsWOW64 ); // is MTADiag running under WOW64?
186-
GetLocalTime ( &sysTime ); // get the current system time
187-
bQuit = false; // initialize quit bool, used in GTA files checking
188-
189-
// generate necessary file paths
203+
tempDir = getenv ( "Temp" ); // get the Temp directory
204+
systemRoot = getenv ( "SystemRoot" ); // get the WINDOWS directory
205+
programData = getenv ( "AllUsersProfile" ); // get the ProgramData directory
206+
IsWow64Process ( GetCurrentProcess(), &bIsWOW64 ); // is MTADiag running under WOW64?
207+
GetLocalTime ( &sysTime ); // get the current system time
208+
bQuit = false; // initialize quit bool, used in GTA files checking
209+
MTAUpdated = false; // initialize MTAUpdated bool
210+
211+
// generate MTADiag log file path
190212
std::stringstream ss;
191213

192214
ss << "MTADiag-Log-" << sysTime.wYear << "-" << sysTime.wMonth << "-" << sysTime.wDay << "_" << sysTime.wHour << "-" << sysTime.wMinute << "-" << sysTime.wSecond;
@@ -201,6 +223,7 @@ void Diag::GeneratePaths ( void )
201223
files.push_back ( tempDir + "\\MTANightly.exe" ); // filepath for nightly
202224
files.push_back ( tempDir + "\\WMICUni.txt" ); // WMIC command outputs as Unicode; we convert this file to ASCII for proper insertion & formatting in the log
203225
files.push_back ( systemRoot + "\\system32\\D3DX9_43.dll" ); // we check for the presence of this file to determine if DirectX is up to date
226+
files.push_back ( tempDir + "\\ver.txt" ); // MTA's auto-update version appropriation
204227

205228
// fill the GTAFiles vector
206229
GTAFiles.push_back ( "\\eax.dll" );
@@ -660,7 +683,7 @@ bool Diag::PollMTAVersions ( void )
660683
MTAVersionsInstalled[4] = ReadRegKey ( MTAPathValue, MTA14PathSubKey ); // store MTA 1.4 path, if present
661684
MTAVersionsInstalled[5] = ReadRegKey ( MTAPathValue, MTA15PathSubKey ); // store MTA 1.5 path, if present
662685

663-
// if a version isn't installed, "Failed to get key." is returned by readRegKey; clear that array element
686+
// if a version isn't installed, "Failed to get key." is returned by ReadRegKey; clear that array element
664687
for ( int i = 1; i <= CUR_MTA_VERSIONS; i++ )
665688
{
666689
if ( !strcmp ( MTAVersionsInstalled[i].c_str(), "Failed to read key." ) )
@@ -838,7 +861,10 @@ void Diag::UpdateMTA ( void )
838861
exit ( EXIT_SUCCESS );
839862
}
840863
else
864+
{
841865
std::cout << "MTA version is now: " << GetMTAVersion() << std::endl << std::endl; // tell the user the updated version string
866+
MTAUpdated = true; // bool to control log file output of old and new MTA versions
867+
}
842868
}
843869

844870
void Diag::UpdateDirectX ( void )

MTADiag/Diag.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
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+
#define MTAVerURL "http://nightly.mtasa.com/ver/"
49+
4850
namespace Diag {
4951

5052
void Begin ( void );
@@ -91,6 +93,7 @@ namespace Diag {
9193
static std::string MTAVersion;
9294
static std::string MTAShortVersion;
9395
static std::string OriginalMTAVersion;
96+
static bool MTAUpdated;
9497

9598
static std::string MTAVersionsInstalled[CUR_MTA_VERSIONS]; // array to store paths of all MTA versions currently installed
9699
static int MTAVerChoice; // stores user's choice of which MTA version to diagnose

MTADiag/util.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,24 @@ std::string GetFileMD5 ( std::string filename )
238238
ss.clear();
239239

240240
return md5sum;
241+
}
242+
243+
bool FindInFile ( std::string filename, std::string value )
244+
{
245+
std::ifstream file;
246+
file.open ( filename.c_str(), std::ios::in );
247+
std::string line;
248+
249+
while ( file.good() ) // is the file good for reading still?
250+
{
251+
getline ( file, line );
252+
size_t found;
253+
254+
found = line.find ( value ); // look for our value on each line
255+
if ( found != std::string::npos ) { return true; } // return true if value found
256+
}
257+
258+
file.close(); // close the file
259+
260+
return false; // we didn't find it, return false
241261
}

MTADiag/util.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ void ConvertUnicodeToASCII ( std::string file1, std:
2727
bool CopyToClipboard ( std::string contents );
2828
bool IsVistaOrNewer ( void );
2929
bool IsWin8OrNewer ( void );
30-
std::string GetFileMD5 ( std::string filename );
30+
std::string GetFileMD5 ( std::string filename );
31+
bool FindInFile ( std::string filename, std::string value );

0 commit comments

Comments
 (0)