Skip to content

Commit 672a0ed

Browse files
committed
MD5 checking of all GTA files, HTTPS support for downloading nightly installers, other tweaks
1 parent 7242efa commit 672a0ed

File tree

7 files changed

+550
-490
lines changed

7 files changed

+550
-490
lines changed

MTADiag/Common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <sstream>
2121
#include <fstream>
2222
#include <vector>
23+
#include <shlobj.h>
2324
#include "Log.h"
2425

25-
#define VERSION "2.7.1"
26+
#define VERSION "2.7.3"

MTADiag/Curl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ bool Curl::DownloadFile ( std::string fileURL, std::string filePath )
2929
{
3030
FILE *fp; // file pointer
3131
fopen_s ( &fp, filePath.c_str(), "wb" ); // open the temporary file download location
32+
curl_easy_setopt ( curl, CURLOPT_SSL_VERIFYPEER, FALSE ); // used for https
3233
curl_easy_setopt ( curl, CURLOPT_URL, fileURL.c_str() ); // set the URL
3334
curl_easy_setopt ( curl, CURLOPT_WRITEFUNCTION, fwrite ); // set the write function
3435
curl_easy_setopt ( curl, CURLOPT_WRITEDATA, fp ); // set the file path
@@ -75,7 +76,7 @@ std::string Curl::CreatePasteBin ( std::string filePath, std::string pasteName )
7576
<< curl_easy_escape ( curl, pasteName.c_str(), pasteName.length() ) // urlencode MTADiag log filename
7677
<< "&"
7778
<< "api_paste_expire_date=1M&" // paste will expire in one month
78-
<< "api_dev_key=use_your_own&" // Pastebin API dev key
79+
<< "api_dev_key=provide_your_own&" // Pastebin API dev key
7980
<< "api_paste_code="
8081
<< curl_easy_escape ( curl, logText.c_str(), logText.length() ); // urlencode log file contents
8182
post = ss.str();

MTADiag/Diag.cpp

Lines changed: 52 additions & 477 deletions
Large diffs are not rendered by default.

MTADiag/Diag.h

Lines changed: 422 additions & 8 deletions
Large diffs are not rendered by default.

MTADiag/libcurl.dll

416 KB
Binary file not shown.

MTADiag/util.cpp

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ bool CopyToClipboard ( std::string contents )
164164
return false; // failure
165165
}
166166

167-
// slightly modified version of http://msdn.microsoft.com/en-us/library/ms724451%28VS.85%29.aspx
167+
// slightly modified version of https://msdn.microsoft.com/en-us/library/ms724451%28VS.85%29.aspx
168168
bool IsVistaOrNewer ( void )
169169
{
170170
OSVERSIONINFO osvi;
@@ -181,7 +181,7 @@ bool IsVistaOrNewer ( void )
181181
return false;
182182
}
183183

184-
// slightly modified version of http://msdn.microsoft.com/en-us/library/ms724451%28VS.85%29.aspx
184+
// slightly modified version of https://msdn.microsoft.com/en-us/library/ms724451%28VS.85%29.aspx
185185
bool IsWin8OrNewer ( void )
186186
{
187187
OSVERSIONINFO osvi;
@@ -240,6 +240,51 @@ std::string GetFileMD5 ( std::string filename )
240240
return md5sum;
241241
}
242242

243+
bool CompareFileMD5 ( std::string MD5sum, std::string filename )
244+
{
245+
FILE *fp; // file pointer
246+
247+
fopen_s ( &fp, filename.c_str(), "rb" ); // try to open the file
248+
249+
if ( fp == NULL ) // we can't open it
250+
{
251+
return ( false );
252+
}
253+
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
286+
}
287+
243288
bool FindInFile ( std::string filename, std::string value )
244289
{
245290
std::ifstream file;
@@ -258,4 +303,26 @@ bool FindInFile ( std::string filename, std::string value )
258303
file.close(); // close the file
259304

260305
return false; // we didn't find it, return false
306+
}
307+
308+
void ProgressBar ( int percent )
309+
{
310+
std::string bar;
311+
312+
for ( int i = 0; i < 50; i++ )
313+
{
314+
if ( i < ( percent / 2 ) )
315+
{
316+
bar.replace ( i, 1, "=" );
317+
}
318+
else if ( i == ( percent / 2 ) )
319+
{
320+
bar.replace ( i, 1, ">" );
321+
}
322+
else
323+
{
324+
bar.replace ( i, 1, " " );
325+
}
326+
}
327+
std::cout << "\r" "[" << bar << "] "; std::cout.width ( 3 ); std::cout << percent << "% " << std::flush;
261328
}

MTADiag/util.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ bool CopyToClipboard ( std::string contents );
2828
bool IsVistaOrNewer ( void );
2929
bool IsWin8OrNewer ( void );
3030
std::string GetFileMD5 ( std::string filename );
31-
bool FindInFile ( std::string filename, std::string value );
31+
bool CompareFileMD5 ( std::string MD5sum, std::string filename );
32+
bool FindInFile ( std::string filename, std::string value );
33+
void ProgressBar ( int percent );

0 commit comments

Comments
 (0)