Skip to content

Commit 311cd3a

Browse files
committed
Add premake build files and fix WinAPI usage
1 parent c96afcb commit 311cd3a

File tree

11 files changed

+112
-20
lines changed

11 files changed

+112
-20
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*.{h,hpp,cpp}]
4+
insert_final_newline = true
5+
indent_style = tab
6+
indent_size = 4
7+
8+
[*.lua]
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
indent_style = tab
12+
indent_size = 4

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.vs/
2+
.vscode/
3+
4+
bin/
5+
build/
6+
tools/vswhere.exe

premake5.lua

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
workspace "MTADiag"
2+
configurations { "Debug", "Release" }
3+
location "build"
4+
targetdir "bin"
5+
startproject "MTADiag"
6+
7+
toolset "v141_xp" -- Enable XP support
8+
flags { "StaticRuntime" }
9+
10+
filter "configurations:Debug"
11+
targetsuffix "_d"
12+
13+
filter "configurations:Release"
14+
optimize "Full"
15+
16+
filter {}
17+
-- Dependencies
18+
include "vendor/curl"
19+
20+
project "MTADiag"
21+
language "C++"
22+
cppdialect "C++14"
23+
kind "ConsoleApp"
24+
25+
defines { "BUILDING_LIBCURL" }
26+
includedirs { "include", "vendor/curl/include" }
27+
links { "curl" }
28+
29+
files {
30+
"premake5.lua",
31+
32+
"include/**.h",
33+
"include/**.hpp",
34+
35+
"src/**.cpp",
36+
37+
"res/**.rc"
38+
}

res/resource.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212

1313
// remains consistent on all systems.
1414

15-
IDI_APPLICATION ICON "res\\MTADiag.ico"
15+
IDI_APPLICATION ICON "MTADiag.ico"

src/Curl.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414

1515
#include "Curl.h"
1616
#include "util.h"
17-
#include "curl/curl.h"
18-
#include "curl/easy.h"
19-
#include "curl/types.h"
17+
#include <curl/curl.h>
18+
#include <curl/easy.h>
2019

2120
void progress_callback ( void* percent, double TotalToDL, double CurrentDL, double TotalToUL, double CurrentUL ); // percentage progress callback
2221
size_t write_data ( void *ptr, size_t size, size_t nmemb, void *stream ); // writes HTTP response to a string
@@ -189,4 +188,4 @@ size_t write_data ( void* ptr, size_t size, size_t nmemb, void* )
189188
std::string temp ( static_cast <const char*> ( ptr ), size* nmemb );
190189
Curl::response.append ( temp );
191190
return size* nmemb;
192-
}
191+
}

src/Diag.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ void Diag::Begin ( void )
294294
std::cout << "Error code: \"" << PasteBinResult << "\"" << std::endl;
295295
std::cout << "Please paste the contents of the opened Wordpad window at https://pastebin.mtasa.com" << std::endl;
296296
std::cout << "Include the MTA Pastebin link in your forum post." << std::endl << std::endl;
297-
ShellExecute ( NULL, "open", "wordpad.exe", QuoteFilename( files[FILE_LOG] ).c_str(), NULL, SW_SHOW );
297+
ShellExecuteA ( NULL, "open", "wordpad.exe", QuoteFilename( files[FILE_LOG] ).c_str(), NULL, SW_SHOW );
298298
}
299299
}
300300

@@ -333,7 +333,7 @@ void Diag::GeneratePaths ( void )
333333
// Try to use 'MTA San Andreas All\MTADiag' as a temp dir first, so non admin can peek at it
334334
{
335335
std::string altTempDir = programData + "\\MTA San Andreas All\\MTADiag";
336-
SHCreateDirectoryEx( NULL, altTempDir.c_str(), NULL );
336+
SHCreateDirectoryExA( NULL, altTempDir.c_str(), NULL );
337337
// Check can write there
338338
std::string altTempDirTest = altTempDir + "\\test.txt";
339339
std::ofstream file;
@@ -547,7 +547,7 @@ void Diag::UpdateMTA ( void )
547547
{
548548
std::cout << "Unable to automatically download MTA patch. Launching download link..." << std::endl;
549549
system ( "pause" ); // wait for user acknowledgement
550-
ShellExecute ( NULL, "open", url.c_str(), NULL, NULL, SW_HIDE );
550+
ShellExecuteA ( NULL, "open", url.c_str(), NULL, NULL, SW_HIDE );
551551
std::cout << std::endl << "Install the patch. ";
552552
}
553553
#endif
@@ -589,7 +589,7 @@ void Diag::UpdateDirectX ( void )
589589
{
590590
std::cout << "Unable to automatically download DirectX updater. Launching download link..." << std::endl;
591591
system ( "pause" ); // wait for user acknowledgement
592-
ShellExecute ( NULL, "open", DXWebSetupURL.c_str(), NULL, NULL, SW_HIDE );
592+
ShellExecuteA ( NULL, "open", DXWebSetupURL.c_str(), NULL, NULL, SW_HIDE );
593593
std::cout << "Continue when DirectX has finished updating." << std::endl;
594594
system ( "pause" ); // wait for user acknowledgement
595595
}
@@ -639,7 +639,7 @@ DWORD Diag::DoSystemCommandWithOutput ( std::string command, int outputType, DWO
639639
if ( outputType != OUTPUT_NONE )
640640
{
641641
// File for output to be redirected to
642-
h = CreateFile( files[FILE_TEMP].c_str(),
642+
h = CreateFileA( files[FILE_TEMP].c_str(),
643643
FILE_APPEND_DATA,
644644
FILE_SHARE_WRITE | FILE_SHARE_READ,
645645
&sa,
@@ -653,7 +653,7 @@ DWORD Diag::DoSystemCommandWithOutput ( std::string command, int outputType, DWO
653653
}
654654

655655
PROCESS_INFORMATION pi;
656-
STARTUPINFO si;
656+
STARTUPINFOA si;
657657
BOOL ret = FALSE;
658658
DWORD flags = CREATE_NO_WINDOW;
659659

@@ -665,7 +665,7 @@ DWORD Diag::DoSystemCommandWithOutput ( std::string command, int outputType, DWO
665665
si.hStdError = h;
666666
si.hStdOutput = h;
667667

668-
ret = CreateProcess( NULL, (LPSTR)command.c_str(), NULL, NULL, TRUE, flags, NULL, NULL, &si, &pi );
668+
ret = CreateProcessA( NULL, (LPSTR)command.c_str(), NULL, NULL, TRUE, flags, NULL, NULL, &si, &pi );
669669

670670
DWORD status = ERROR_INVALID_FUNCTION;
671671
std::stringstream ss;

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern std::vector<std::string> Diag::files;
1818

1919
int main()
2020
{
21-
SetConsoleTitle ( "MTADiag v" VERSION ); // set the console title
21+
SetConsoleTitleA ( "MTADiag v" VERSION ); // set the console title
2222
std::cout << "MTADiag v" << VERSION << " by Towncivilian" << std::endl << std::endl; // tell the user what this program is
2323

2424
Diag::Begin(); // begin diagnostics
@@ -28,4 +28,4 @@ int main()
2828
system ( "pause" ); // wait for user exit
2929

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

src/util.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ bool DeleteCompatibilityEntries ( std::string subkey, HKEY hKeyType )
5858

5959
bool changed = false;
6060

61-
if ( RegOpenKeyEx ( hKeyType, subkey.c_str(), NULL, KEY_READ | KEY_WRITE, &hKey ) == ERROR_SUCCESS ) // if registry key read was successfully
61+
if ( RegOpenKeyExA ( hKeyType, subkey.c_str(), NULL, KEY_READ | KEY_WRITE, &hKey ) == ERROR_SUCCESS ) // if registry key read was successfully
6262
{
6363
while ( result != ERROR_NO_MORE_ITEMS ) // loop until we run out of registry values to read
6464
{
65-
result = RegEnumValue ( hKey, index, buf, &dwBufSize, 0, NULL, NULL, NULL ); // attempt to enumerate values and store result
65+
result = RegEnumValueA ( hKey, index, buf, &dwBufSize, 0, NULL, NULL, NULL ); // attempt to enumerate values and store result
6666
dwBufSize = sizeof ( buf ); // set the buffer size to the read value's size
6767

6868
if ( result == ERROR_SUCCESS ) // if we read something
6969
{
7070
index++; // increment index
7171
if ( strstr ( buf, "gta_sa.exe" ) || strstr ( buf, "Multi Theft Auto.exe" ) ) // check for filename matches
7272
{
73-
if ( RegQueryValueEx ( hKey, buf, NULL, &dwType, ( BYTE* ) buf2, &dwBuf2Size ) == ERROR_SUCCESS ) // read the value's data
73+
if ( RegQueryValueExA ( hKey, buf, NULL, &dwType, ( BYTE* ) buf2, &dwBuf2Size ) == ERROR_SUCCESS ) // read the value's data
7474
{
7575
if ( strcmp ( buf2, "~ RUNASADMIN" ) == 0 || strcmp ( buf2, "RUNASADMIN" ) == 0 ) // is the value's data already just "RUNASADMIN"?
7676
{
@@ -82,15 +82,15 @@ bool DeleteCompatibilityEntries ( std::string subkey, HKEY hKeyType )
8282
if ( IsWin8OrNewer() ) // is the user running Windows 8 or newer?
8383
{
8484
const char Win8Data[13] = "~ RUNASADMIN"; // set the data buffer to the proper string
85-
RegSetValueEx ( hKey, buf, 0, dwType, ( BYTE* ) Win8Data, sizeof (Win8Data) ); // set the value data to RUNASADMIN only
85+
RegSetValueExA ( hKey, buf, 0, dwType, ( BYTE* ) Win8Data, sizeof (Win8Data) ); // set the value data to RUNASADMIN only
8686
changed = true;
8787
index--;
8888
continue;
8989
}
9090
else // 7 or older
9191
{
9292
const char XPData[11] = "RUNASADMIN"; // set the data buffer to the proper string
93-
RegSetValueEx ( hKey, buf, 0, dwType, ( BYTE* ) XPData, sizeof (XPData) ); // set the value data to RUNASADMIN only
93+
RegSetValueExA ( hKey, buf, 0, dwType, ( BYTE* ) XPData, sizeof (XPData) ); // set the value data to RUNASADMIN only
9494
changed = true;
9595
index--;
9696
continue;
@@ -99,7 +99,7 @@ bool DeleteCompatibilityEntries ( std::string subkey, HKEY hKeyType )
9999

100100
else // the user only has other compatibility mode settings enabled
101101
{
102-
RegDeleteValue ( hKey, buf ); // delete the registry value
102+
RegDeleteValueA ( hKey, buf ); // delete the registry value
103103
changed = true;
104104
index--;
105105
continue;

tools/premake5.exe

1.14 MB
Binary file not shown.

win-build.bat

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@echo off
2+
set VSWHERE=tools\vswhere.exe
3+
4+
rem Download vswhere (command line utility to find MSBuild path)
5+
if not exist %VSWHERE% (
6+
echo vswhere utility doesn't exist. Downloading...
7+
powershell -Command "Invoke-WebRequest https://mirror.mtasa.com/bdata/vswhere.exe -OutFile %VSWHERE%"
8+
)
9+
10+
rem Create solution (ignoring pause)
11+
call win-create-projects.bat < nul
12+
echo.
13+
14+
rem Find MSBuild installation path
15+
for /f "usebackq tokens=1* delims=: " %%i in (`%VSWHERE% -latest -requires Microsoft.Component.MSBuild`) do (
16+
if /i "%%i"=="installationPath" set INSTALLDIR=%%j
17+
)
18+
19+
rem Output an error if not exists
20+
set MSBUILDPATH="%InstallDir%\MSBuild\15.0\Bin\MSBuild.exe"
21+
if not exist %MSBUILDPATH% (
22+
echo Could not find MSBuild. Make sure you have Visual Studio 2017 installed
23+
goto end
24+
)
25+
echo Found MSBuild at: %MSBUILDPATH%
26+
27+
rem Start compiling
28+
%MSBUILDPATH% build/MTADiag.sln /property:Configuration=Release /m
29+
30+
:end
31+
pause

0 commit comments

Comments
 (0)