Skip to content

Commit a7eede1

Browse files
committed
Added enums for files array
1 parent f0d5053 commit a7eede1

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

MTADiag/Diag.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void Diag::Begin ( void )
2828
// obtain necessary environment variables and generate filepaths used for temporary files
2929
GeneratePaths();
3030

31-
Log::Open ( files[0] ); // create the log file and open it
31+
Log::Open ( files[FILE_LOG] ); // create the log file and open it
3232

3333
Log::WriteStringToLog ( "MTADiag version", VERSION, false );
3434
Log::WriteStringToLog ( " by Towncivilian" );
@@ -43,7 +43,7 @@ void Diag::Begin ( void )
4343
std::cout << std::endl;
4444

4545
// check whether DirectX is up to date (actually whether D3DX9_43.dll is present in %systemroot%\system32)
46-
if ( CheckForFile ( files[4].c_str() ) ) { std::cout << "DirectX is up-to-date." << std::endl << std::endl; }
46+
if ( CheckForFile ( files[FILE_D3DX9_DLL].c_str() ) ) { std::cout << "DirectX is up-to-date." << std::endl << std::endl; }
4747
else { UpdateDirectX(); DXUpdated = 1; }
4848

4949
// remove any compatibility mode settings on gta_sa.exe and/or Multi Theft Auto.exe
@@ -79,12 +79,12 @@ void Diag::Begin ( void )
7979
};
8080
#endif
8181
// check if MTA version matches the latest auto-update nightly
82-
if ( Curl::DownloadFile ( MTAVerURL, files[1].c_str() ) ) // download the version appropriation HTML
82+
if ( Curl::DownloadFile ( MTAVerURL, files[FILE_TEMP].c_str() ) ) // download the version appropriation HTML
8383
{
8484
std::string MTAVersionTrim = MTAVersion; // copy the MTAVersion string
8585
MTAVersionTrim.resize ( 15 ); // trim the MTAVersion string stored in registry to 15 characters
8686
// the version appropriation HTML has a 15 char string lacking two trailing zeros
87-
if ( FindInFile ( files[1].c_str(), ( MTAVersionTrim ) ) ) // look for the current MTA version string in it
87+
if ( FindInFile ( files[FILE_TEMP].c_str(), ( MTAVersionTrim ) ) ) // look for the current MTA version string in it
8888
std::cout << "MTA is up-to-date." << std::endl << std::endl; // we've found it, hooray, we don't need to update MTA
8989
else
9090
{
@@ -113,7 +113,7 @@ void Diag::Begin ( void )
113113
Log::WriteStringToLog ( "D3D9.dll present: ", D3D9Present );
114114

115115
// is DirectX up-to-date? (D3DX9_43.dll present)
116-
std::string DirectXState = ( CheckForFile ( files[4] ) ) ? "Yes" : "No";
116+
std::string DirectXState = ( CheckForFile ( files[FILE_D3DX9_DLL] ) ) ? "Yes" : "No";
117117
Log::WriteStringToLog ( "DirectX up-to-date: ", DirectXState );
118118
if ( DXUpdated == 1 )
119119
Log::WriteStringToLog ( "DirectX was updated: Yes");
@@ -207,7 +207,7 @@ void Diag::Begin ( void )
207207
// upload to PasteBin
208208
std::cout << "Log file generated. Uploading to Pastebin..." << std::endl;
209209

210-
PasteBinResult = Curl::CreateMTAPasteBin ( files[0], logFileName ); // store the HTTP POST result into PasteBinResult
210+
PasteBinResult = Curl::CreateMTAPasteBin ( files[FILE_LOG], logFileName ); // store the HTTP POST result into PasteBinResult
211211

212212
// upload successful; copy URL to clipboard
213213
if ( HasDigits ( PasteBinResult ) && !( strstr ( PasteBinResult.c_str(), "DOCTYPE" ) ) && !( strstr ( PasteBinResult.c_str(), "error" ) ) )
@@ -229,7 +229,7 @@ void Diag::Begin ( void )
229229
std::cout << "Error code: \"" << PasteBinResult << "\"" << std::endl;
230230
std::cout << "Please paste the contents of the opened Wordpad window at https://pastebin.mtasa.com" << std::endl;
231231
std::cout << "Include the MTA Pastebin link in your forum post." << std::endl << std::endl;
232-
ShellExecute ( NULL, "open", "wordpad.exe", files[0].c_str(), NULL, SW_SHOW );
232+
ShellExecute ( NULL, "open", "wordpad.exe", files[FILE_LOG].c_str(), NULL, SW_SHOW );
233233
}
234234
}
235235

@@ -243,7 +243,7 @@ void Diag::Cleanup ( bool deleteLog )
243243
if ( deleteLog ) // do we need to delete our log? (if MTADiag quit prior to completing diagnostics)
244244
{
245245
Log::Close(); // close the log file for writing
246-
remove ( files[0].c_str() ); // remove the MTADiag log
246+
remove ( files[FILE_LOG].c_str() ); // remove the MTADiag log
247247
}
248248
}
249249

@@ -449,11 +449,11 @@ void Diag::UpdateMTA ( void )
449449
}
450450

451451
#ifndef SKIPUPDATE
452-
if ( Curl::DownloadFile ( url, files[2].c_str() ) ) // if the download was successful, open the installer
452+
if ( Curl::DownloadFile ( url, files[FILE_NIGHTLY_INSTALLER].c_str() ) ) // if the download was successful, open the installer
453453
{
454454
std::cout << std::endl << "Launching the installer..." << std::endl;
455455
std::cout << "Run MTA once the installer has finished to see if it works now." << std::endl;
456-
system ( files[2].c_str() );
456+
system ( files[FILE_NIGHTLY_INSTALLER].c_str() );
457457
}
458458
else // if the download failed, open a browser window to start the download of the nightly
459459
{
@@ -511,20 +511,20 @@ void Diag::UpdateDirectX ( void )
511511
void Diag::DoSystemCommandWithOutput ( std::string command )
512512
{
513513
Log::WriteStringToLog ( "----------------------------------------------------------------------------------" );
514-
int iCommandReturn = system ( ( command + files[1] ).c_str() ); // do the command
514+
int iCommandReturn = system ( ( command + files[FILE_TEMP] ).c_str() ); // do the command
515515

516516
std::stringstream ss;
517517
ss << command << " (returned " << iCommandReturn << ")";
518518

519-
Log::WriteFileToLog ( files[1], ss.str() ); // write the result to the log file with the passed command argument as a description
519+
Log::WriteFileToLog ( files[FILE_TEMP], ss.str() ); // write the result to the log file with the passed command argument as a description
520520
}
521521

522522
void Diag::QueryWMIC ( std::string arg1, std::string arg2, std::string arg3, std::string arg4 )
523523
{
524524
std::string WMIC;
525525
std::stringstream ss; // create a stringstream
526526

527-
ss << "wmic " << arg1 << " " << arg2 << " " << arg3 << " " << arg4 << " >" << files[3].c_str(); // wmic <arg1> <arg2> <arg3> <arg4>
527+
ss << "wmic " << arg1 << " " << arg2 << " " << arg3 << " " << arg4 << " >" << files[FILE_WMIC_UNI].c_str(); // wmic <arg1> <arg2> <arg3> <arg4>
528528
WMIC = ss.str ();
529529

530530
// clear the stringstream
@@ -533,19 +533,19 @@ void Diag::QueryWMIC ( std::string arg1, std::string arg2, std::string arg3, std
533533

534534
system ( WMIC.c_str() ); // do it
535535

536-
ConvertUnicodeToASCII ( files[3], files[1] ); // convert the Unicode-encoded result to ASCII for proper display in the log file
536+
ConvertUnicodeToASCII ( files[FILE_WMIC_UNI], files[FILE_TEMP] ); // convert the Unicode-encoded result to ASCII for proper display in the log file
537537

538-
remove ( files[3].c_str() ); // delete the Unicode-encoded log file
538+
remove ( files[FILE_WMIC_UNI].c_str() ); // delete the Unicode-encoded log file
539539

540-
Log::WriteFileToLog ( files[1], ( "WMIC " + arg1 + " " + arg2 + " " + arg3 + " " + arg4 ) ); // write the result to the log file with a description
540+
Log::WriteFileToLog ( files[FILE_TEMP], ( "WMIC " + arg1 + " " + arg2 + " " + arg3 + " " + arg4 ) ); // write the result to the log file with a description
541541
}
542542

543543
void Diag::GetDir ( std::string directory )
544544
{
545545
std::string dirPath;
546546
std::stringstream ss; // create a stringstream
547547

548-
ss << "dir \"" << directory << "\" >\"" << files[1].c_str() << "\""; // dir "<filepath>"
548+
ss << "dir \"" << directory << "\" >\"" << files[FILE_TEMP].c_str() << "\""; // dir "<filepath>"
549549
dirPath = ss.str();
550550

551551
// clear the stringstream
@@ -554,5 +554,5 @@ void Diag::GetDir ( std::string directory )
554554

555555
system ( dirPath.c_str() ); // do it
556556

557-
Log::WriteFileToLog ( files[1].c_str(), ( directory + " directory listing" ) ); // write the result to the log file with a description
557+
Log::WriteFileToLog ( files[FILE_TEMP].c_str(), ( directory + " directory listing" ) ); // write the result to the log file with a description
558558
}

MTADiag/Diag.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@
4747

4848
#define MTAVerURL "https://nightly.mtasa.com/ver/"
4949

50+
enum
51+
{
52+
FILE_LOG,
53+
FILE_TEMP,
54+
FILE_NIGHTLY_INSTALLER,
55+
FILE_WMIC_UNI,
56+
FILE_D3DX9_DLL,
57+
};
58+
5059
namespace Diag {
5160

5261
void Begin ( void );

MTADiag/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ int main()
2727

2828
system ( "pause" ); // wait for user exit
2929

30-
remove ( Diag::files[0].c_str() ); // remove the generated MTADiag log
30+
remove ( Diag::files[FILE_LOG].c_str() ); // remove the generated MTADiag log
3131
};

0 commit comments

Comments
 (0)