Skip to content

Commit 0e9b440

Browse files
committed
Added file size report for Nonstandard GTA files.
Increased timeout for tasklist command.
1 parent 769b4ca commit 0e9b440

File tree

4 files changed

+37
-62
lines changed

4 files changed

+37
-62
lines changed

MTADiag/Common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <fstream>
2424
#include <vector>
2525
#include <shlobj.h>
26+
#include <time.h>
2627
#include "Log.h"
2728

28-
#define VERSION "2.7.17"
29+
#define VERSION "2.7.18"

MTADiag/Diag.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,15 @@ void Diag::Begin ( void )
139139
if ( GetAsyncKeyState( VK_F1 ) )
140140
break;
141141
#endif
142-
if ( !( CompareFileMD5 ( szMd5, ( GTAPath + szFilename ) ) ) )
142+
std::string strCalcedMd5 = GetFileMD5( GTAPath + szFilename );
143+
long long fileSize = GetFileSize( GTAPath + szFilename );
144+
if ( strCalcedMd5 != szMd5 )
143145
{
144-
std::cout << "Nonstandard GTA file: " << fileList[i].szFilename << std::endl;
146+
std::cout << "Nonstandard GTA file: " << szFilename << std::endl;
145147

146148
Log::WriteStringToLog ( "Nonstandard GTA file: ", szFilename );
147-
Log::WriteStringToLog ( GetFileMD5 ( GTAPath + szFilename ) );
149+
std::stringstream ss; ss << "MD5sum for " << szFilename << ": " << strCalcedMd5 << " Size: " << fileSize;
150+
Log::WriteStringToLog ( ss.str() );
148151
Log::WriteStringToLog ( "Value should be: ", szMd5 );
149152
Log::WriteStringToLog ( "" );
150153
}
@@ -161,7 +164,7 @@ void Diag::Begin ( void )
161164
DoSystemCommandWithOutput ( std::string( "dxdiag /t " ) + files[FILE_TEMP], OUTPUT_NONE );
162165
ProgressBar ( 10 );
163166
#endif
164-
DoSystemCommandWithOutput ( "tasklist" );
167+
DoSystemCommandWithOutput ( "tasklist", OUTPUT_ANSI, 120000 );
165168
ProgressBar ( 20 );
166169

167170
// write some of MTA's logs to our log
@@ -196,12 +199,6 @@ void Diag::Begin ( void )
196199
ProgressBar ( 40 );
197200

198201
DoSystemCommandWithOutput ( "ipconfig /all" ); // get network configuration
199-
ProgressBar ( 45 );
200-
if ( IsVistaOrNewer() )
201-
{
202-
// might help resolve Visual C++ runtime issues
203-
DoSystemCommandWithOutput ( "wevtutil qe Application /q:\"Event [System [(Level=2)] ] [EventData [(Data='Multi Theft Auto.exe')] ]\" /c:1 /f:text /rd:true" );
204-
}
205202
ProgressBar ( 50 );
206203
QueryWMIC ( "Path", "Win32_VideoController", "Get" ); // get some video controller information
207204
ProgressBar ( 55 );
@@ -215,20 +212,29 @@ void Diag::Begin ( void )
215212

216213
// get relevant MD5sum( s)
217214
Log::WriteDividerToLog ();
218-
Log::WriteStringToLog ( GetFileMD5 ( GTAPath + "\\gta_sa.exe" ) );
219-
Log::WriteStringToLog ( "Value should be: 170b3a9108687b26da2d8901c6948a18 (HOODLUM 1.0)" );
215+
Log::WriteStringToLog ( "MD5sum for gta_sa.exe: " + GetFileMD5 ( GTAPath + "\\gta_sa.exe" ) );
216+
//Log::WriteStringToLog ( "Value should be: 170b3a9108687b26da2d8901c6948a18 (HOODLUM 1.0)" );
220217
Log::WriteStringToLog ( "" );
221218

222219
ProgressBar ( 80 );
223220

224221
// font diagnostics
225222
Log::WriteDividerToLog ();
226223
Log::WriteStringToLog ( "Verdana (TrueType) registry value:", ReadRegKey ( "Verdana (TrueType)", "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\" ) );
227-
Log::WriteStringToLog ( GetFileMD5 ( systemRoot + "\\Fonts\\verdana.ttf" ) );
224+
Log::WriteStringToLog ( "MD5sum for verdana.ttf: " + GetFileMD5 ( systemRoot + "\\Fonts\\verdana.ttf" ) );
228225
Log::WriteStringToLog ( "Value should be: ba34b303291e36596759eb46ad9c51f2 (Win 8) / 6eee3713d2330d93183846f2d34f0976 (Win 7)" );
229226
Log::WriteStringToLog ( "" );
230227
GetDir ( systemRoot + "\\Fonts\\verd*" );
231228

229+
ProgressBar ( 90 );
230+
231+
// Do this last in case of problems
232+
if ( IsVistaOrNewer() )
233+
{
234+
// might help resolve Visual C++ runtime issues
235+
DoSystemCommandWithOutput ( "wevtutil qe Application /q:\"Event [System [(Level=2)] ] [EventData [(Data='Multi Theft Auto.exe')] ]\" /c:1 /f:text /rd:true" );
236+
}
237+
232238
ProgressBar ( 100 ); std::cout << std::endl << std::endl;
233239

234240
// close the log file for writing
@@ -586,6 +592,7 @@ void Diag::GetDir ( std::string directory )
586592
void Diag::DoSystemCommandWithOutput ( std::string command, int outputType, DWORD maxTimeMs )
587593
{
588594
Log::WriteDividerToLog();
595+
time_t startTime = time( NULL );
589596

590597
SECURITY_ATTRIBUTES sa;
591598
sa.nLength = sizeof(sa);
@@ -656,7 +663,7 @@ void Diag::DoSystemCommandWithOutput ( std::string command, int outputType, DWOR
656663
{
657664
DWORD dwExitCode = 0xFFFFFFFF;
658665
GetExitCodeProcess( pi.hProcess, &dwExitCode );
659-
ss << command << " (returned " << dwExitCode << ")";
666+
ss << command << " (returned " << dwExitCode << ") [Took " << time( NULL ) - startTime << " seconds]";
660667
}
661668
CloseHandle( pi.hProcess );
662669
CloseHandle( pi.hThread );

MTADiag/util.cpp

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ std::string GetFileMD5 ( std::string filename )
213213

214214
std::string md5sum; // string to store md5sum
215215

216-
unsigned char buffer[4096]; // file buffer
216+
unsigned char buffer[65536]; // file buffer
217217

218218
// read all bytes throughout the file
219219
while ( !feof ( fp ) )
220220
{
221-
unsigned int read = fread ( buffer, 1, 4096, fp );
221+
unsigned int read = fread ( buffer, 1, sizeof( buffer ), fp );
222222

223223
// update the MD5 with what we just read
224224
md5.update ( buffer, read );
@@ -228,61 +228,27 @@ std::string GetFileMD5 ( std::string filename )
228228

229229
fclose ( fp ); // close the file
230230

231-
std::stringstream ss; // create a stringstream
232-
233-
ss << "MD5sum for " << filename << ": " << md5;
234-
md5sum = ss.str();
235-
236-
// clear the stringstream
237-
ss.str ("");
238-
ss.clear();
239-
240-
return md5sum;
231+
return md5.hexdigest();
241232
}
242233

243234
bool CompareFileMD5 ( std::string MD5sum, std::string filename )
244235
{
245-
FILE *fp; // file pointer
236+
return MD5sum == GetFileMD5 ( filename );
237+
}
246238

239+
long long GetFileSize ( const std::string& filename )
240+
{
241+
FILE *fp;
247242
fopen_s ( &fp, filename.c_str(), "rb" ); // try to open the file
248-
249243
if ( fp == NULL ) // we can't open it
250244
{
251-
return false;
245+
return 0;
252246
}
253247

254-
MD5 md5; // initialize MD5
255-
256-
std::string md5sum; // string to store md5sum
257-
258-
unsigned char buffer[4096]; // file buffer
259-
260-
// read all bytes throughout the file
261-
while ( !feof ( fp ) )
262-
{
263-
unsigned int read = fread ( buffer, 1, 4096, fp );
264-
265-
// update the MD5 with what we just read
266-
md5.update ( buffer, read );
267-
}
268-
269-
md5.finalize(); // create a digest from the MD5 result
270-
271-
fclose ( fp ); // close the file
272-
273-
std::stringstream ss; // create a stringstream
274-
275-
ss << md5;
276-
md5sum = ss.str(); // put the md5sum into a string
277-
278-
// clear the stringstream
279-
ss.str ("");
280-
ss.clear();
281-
282-
if ( md5sum == MD5sum ) // compare the file's actual MD5sum to the passed MD5sum
283-
return true; // return true if they're the same
284-
else
285-
return false; // return false if they're different
248+
fseek( fp, 0, SEEK_END );
249+
long long fileSize = _ftelli64 ( fp );
250+
fclose ( fp );
251+
return fileSize;
286252
}
287253

288254
bool FindInFile ( std::string filename, std::string value )

MTADiag/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ bool CopyToClipboard ( std::string contents );
2828
bool IsVistaOrNewer ( void );
2929
bool IsWin8OrNewer ( void );
3030
std::string GetFileMD5 ( std::string filename );
31+
long long GetFileSize ( const std::string& filename );
3132
bool CompareFileMD5 ( std::string MD5sum, std::string filename );
3233
bool FindInFile ( std::string filename, std::string value );
3334
bool HasDigits ( std::string s );

0 commit comments

Comments
 (0)