Skip to content

Commit 6cfbbdc

Browse files
committed
Add alternate temp dir.
Disabled MTA update because status page is not updated correctly.
1 parent 0a728ed commit 6cfbbdc

File tree

5 files changed

+71
-8
lines changed

5 files changed

+71
-8
lines changed

MTADiag/Common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
#include <shlobj.h>
2626
#include "Log.h"
2727

28-
#define VERSION "2.7.15"
28+
#define VERSION "2.7.16"

MTADiag/Diag.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
//#define SKIPDXDIAG
2121
//#define SKIPFILECHECK
2222
//#define DEBUGOUTPUT // output contents of files vector
23+
#define SKIP_MTA_UPDATE // Disabled until status page is fixed
2324

2425
std::vector<std::string> Diag::files;
2526

@@ -32,6 +33,7 @@ void Diag::Begin ( void )
3233

3334
Log::WriteStringToLog ( "MTADiag version", VERSION, false );
3435
Log::WriteStringToLog ( " by Towncivilian" );
36+
std::cout << "MTADiag version " VERSION << std::endl;
3537

3638
// poll all currently installed MTA versions; if there is more than one installed, ask the user to pick one
3739
if ( !PollMTAVersions() ) // PollMTAVersions will return true if there is only one version of MTA installed
@@ -78,6 +80,7 @@ void Diag::Begin ( void )
7880
exit ( EXIT_FAILURE ); // exit
7981
};
8082
#endif
83+
#ifndef SKIP_MTA_UPDATE
8184
// check if MTA version matches the latest auto-update nightly
8285
if ( Curl::DownloadFile ( MTAVerURL, files[FILE_TEMP].c_str() ) ) // download the version appropriation HTML
8386
{
@@ -92,6 +95,7 @@ void Diag::Begin ( void )
9295
UpdateMTA(); // update MTA to latest nightly / unstable build, depending on MTA's major version
9396
}
9497
}
98+
#endif
9599

96100
// write some information to the log file
97101
Log::WriteStringToLog ( "MTA path: ", MTAPath );
@@ -284,6 +288,22 @@ void Diag::GeneratePaths ( void )
284288
bQuit = false; // initialize quit bool, used in GTA files checking
285289
MTAUpdated = false; // initialize MTAUpdated bool
286290

291+
// Try to use 'MTA San Andreas All\MTADiag' as a temp dir first, so non admin can peek at it
292+
{
293+
std::string altTempDir = programData + "\\MTA San Andreas All\\MTADiag";
294+
SHCreateDirectoryEx( NULL, altTempDir.c_str(), NULL );
295+
// Check can write there
296+
std::string altTempDirTest = altTempDir + "\\test.txt";
297+
std::ofstream file;
298+
file.open ( altTempDirTest.c_str(), std::ios::out );
299+
if ( file )
300+
{
301+
tempDir = altTempDir;
302+
file.close();
303+
remove( altTempDirTest.c_str() );
304+
}
305+
}
306+
287307
// generate MTADiag log file path
288308
std::stringstream ss;
289309

@@ -479,7 +499,7 @@ void Diag::UpdateMTA ( void )
479499
{
480500
std::cout << std::endl << "Launching the installer..." << std::endl;
481501
std::cout << "Run MTA once the installer has finished to see if it works now." << std::endl;
482-
system ( files[FILE_NIGHTLY_INSTALLER].c_str() );
502+
system ( QuoteFilename( files[FILE_NIGHTLY_INSTALLER] ).c_str() );
483503
}
484504
else // if the download failed, open a browser window to start the download of the nightly
485505
{
@@ -521,7 +541,7 @@ void Diag::UpdateDirectX ( void )
521541
if ( Curl::DownloadFile ( DXWebSetupURL.c_str(), DXWebSetupPath.c_str() ) ) // success! open the file
522542
{
523543
std::cout << std::endl << "Follow the instructions to update DirectX." << std::endl << std::endl;
524-
system ( DXWebSetupPath.c_str() );
544+
system ( QuoteFilename( DXWebSetupPath ).c_str() );
525545
}
526546
else // failure; open a browser window to start the download of DXWebSetup
527547
{
@@ -613,7 +633,14 @@ void Diag::DoSystemCommandWithOutput ( std::string command, int outputType, DWOR
613633
else
614634
{
615635
// Apply time limit for command to complete
616-
DWORD status = WaitForSingleObject ( pi.hProcess, maxTimeMs );
636+
DWORD status = 1;
637+
for( unsigned int i = 0 ; i < maxTimeMs ; i += 100 )
638+
{
639+
status = WaitForSingleObject ( pi.hProcess, 100 );
640+
if ( status != WAIT_TIMEOUT )
641+
break;
642+
ProgressBarInc();
643+
}
617644
if ( status == WAIT_TIMEOUT )
618645
{
619646
TerminateProcess ( pi.hProcess, 1 );

MTADiag/Log.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ bool Log::WriteFileToLog ( std::string filePath, std::string itemName )
3131

3232
if ( !file ) // if we can't create the file
3333
{
34-
WriteStringToLog ( "Can't access ", filePath );
35-
WriteStringToLog ( "" );
34+
logfile << itemName
35+
<< ":"
36+
<< std::endl
37+
<< "Can't access "
38+
<< filePath
39+
<< std::endl << std::endl
40+
<< std::flush;
3641
return false; // failure!
3742
}
3843

@@ -73,6 +78,8 @@ void Log::WriteStringToLog ( std::string string, std::string string2, bool endli
7378

7479
if ( endline ) // add an endline if specified
7580
logfile << std::endl;
81+
82+
logfile << std::flush;
7683
}
7784

7885
void Log::WriteDividerToLog ( void )

MTADiag/util.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void ConvertUnicodeToASCII ( std::string file1, std::string file2 )
128128
std::stringstream ss; // create a stringstream
129129
std::string convert;
130130

131-
ss << "TYPE " << file1 << " > " << file2; // TYPE <file1> > <file2>
131+
ss << "TYPE " << QuoteFilename( file1 ) << " > " << QuoteFilename( file2 ); // TYPE <file1> > <file2>
132132
convert = ss.str ();
133133

134134
// clear the stringstream
@@ -313,10 +313,23 @@ bool HasDigits ( std::string s )
313313
return false;
314314
}
315315

316+
int lastPercent = 0;
317+
int fraction = 0;
316318
void ProgressBar ( int percent )
317319
{
318320
std::string bar;
319321

322+
if ( percent >= 0 )
323+
{
324+
lastPercent = percent;
325+
fraction = 0;
326+
}
327+
else
328+
{
329+
percent = lastPercent;
330+
fraction++;
331+
}
332+
320333
for ( int i = 0; i < 50; i++ )
321334
{
322335
if ( i < ( percent / 2 ) )
@@ -332,7 +345,21 @@ void ProgressBar ( int percent )
332345
bar.replace ( i, 1, " " );
333346
}
334347
}
335-
std::cout << "\r" "[" << bar << "] "; std::cout.width ( 3 ); std::cout << percent << "% " << std::flush;
348+
std::cout << "\r" "[" << bar << "] "; std::cout.width ( 3 ); std::cout << percent << "% ";
349+
if ( percent < 100 )
350+
std::cout << "" << fraction << " " << std::flush;
351+
else
352+
std::cout << " " << std::flush;
353+
}
354+
355+
void ProgressBarInc ( void )
356+
{
357+
ProgressBar( -1 );
358+
}
359+
360+
std::string QuoteFilename( const std::string& filename )
361+
{
362+
return "\"" + filename + "\"";
336363
}
337364

338365
// slightly modified version of https://msdn.microsoft.com/en-us/library/ms175774(v=vs.80).aspx

MTADiag/util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ bool CompareFileMD5 ( std::string MD5sum, std
3232
bool FindInFile ( std::string filename, std::string value );
3333
bool HasDigits ( std::string s );
3434
void ProgressBar ( int percent );
35+
void ProgressBarInc ( void );
36+
std::string QuoteFilename ( const std::string& filename );
3537
std::string GetEnv ( std::string variable );

0 commit comments

Comments
 (0)