Skip to content

Commit a6ff948

Browse files
committed
Added more error checks.
Added more hopefully meaningful error messages. Made the script more robust against paths with special characters.
1 parent a7c3b35 commit a6ff948

File tree

4 files changed

+196
-64
lines changed

4 files changed

+196
-64
lines changed

rgo-convert-all.bat

Lines changed: 77 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,59 @@ REM In the case of relative paths, they will be relative to the Game installatio
88

99
SETLOCAL EnableExtensions EnableDelayedExpansion
1010

11-
SET CALLER=convert-all
11+
12+
REM Check if the PATH variable is set or the script is run from inside the directory
13+
WHERE /q rgo-variables.bat
14+
15+
IF ERRORLEVEL 1 (
16+
echo=
17+
echo Couldn't find rgo-variables.bat^^!
18+
echo Please make sure it's in the same directory as this file or is available within
19+
echo one of the directories added to the PATH variable^^!
20+
pause
21+
GOTO :EOF
22+
)
23+
24+
25+
REM Check for the existance of the lua.exe
26+
WHERE /q lua.exe
27+
28+
IF ERRORLEVEL 1 (
29+
echo=
30+
echo Couldn't find lua.exe^^!
31+
echo Please make sure the lua.exe is available within one of the directories added
32+
echo to the PATH variable^^!
33+
pause
34+
GOTO :EOF
35+
)
36+
37+
38+
SET "CALLER=convert-all"
1239
CALL rgo-variables.bat
1340

14-
REM Check if a paramter was passe or not
41+
42+
REM Check if a parameter was passed or not
43+
REM The parameter will be the destination directory for the extracted files
44+
REM If none was set, we're using DATA directory inside the original location
1545
IF "%~1"=="" (
16-
SET LOCATION=PAKS\DATA
46+
SET "LOCATION=PAKS\DATA"
1747
) ELSE (
18-
SET LOCATION=%~1
48+
SET "LOCATION=%~1"
1949
)
2050

2151
REM Remove any trailing backslash
2252
IF %LOCATION:~-1%==\ (
23-
SET LOCATION=%LOCATION:~0,-1%
53+
SET "LOCATION=%LOCATION:~0,-1%"
2454
)
2555

2656

2757
REM Check if the LOCATION contains ":\"
2858
REM If it does, treat it as an absolute path
2959
REM Otherwise it's relative to the game dir
3060
IF NOT x"%LOCATION::\=%"==x"%LOCATION%" (
31-
SET EXTRACT_DIR=%LOCATION%
61+
SET "EXTRACT_DIR=%LOCATION%"
3262
) ELSE (
33-
SET EXTRACT_DIR=%GAME_DIR%\%LOCATION%
63+
SET "EXTRACT_DIR=%GAME_DIR%\%LOCATION%"
3464
)
3565

3666

@@ -43,16 +73,33 @@ IF EXIST "%EXTRACT_DIR%\" (
4373
)
4474

4575

46-
IF errorlevel 1 (
76+
IF ERRORLEVEL 1 (
77+
echo=
78+
echo -------------------------------------------------------------------------------------
79+
echo Couldn't create "%EXTRACT_DIR%", aborting^^!
80+
echo -------------------------------------------------------------------------------------
81+
echo=
82+
echo Maybe the directory is write protected or you do not have sufficient permissions to
83+
echo access it.
84+
echo The latter could be the case if you're trying to access a folder inside the
85+
echo "C:\Program Files" directory, there only programs/scripts with administrator rights
86+
echo can create folders.
87+
echo This is very likely if you're running the Steam version of the game.
88+
echo=
89+
echo You could try to run the script in administrator mode ^(not recommended^), or you
90+
echo could could simply provide a destination folder for the extracted files like so:
91+
echo=
92+
echo rgo-convert-all.bat "D:\Modding\RGO\DATA"
93+
echo=
94+
echo The extracted files will then be copied into this directory.
4795
echo=
48-
echo Couldn't create %EXTRACT_DIR%, aborting^^!
4996
pause
5097
GOTO :EOF
5198
)
5299

53100
IF NOT EXIST "%EXTRACT_DIR%\" (
54101
echo=
55-
echo Couldn't create %EXTRACT_DIR%, aborting^^!
102+
echo Couldn't create "%EXTRACT_DIR%", aborting^^!
56103
pause
57104
GOTO :EOF
58105
)
@@ -61,14 +108,14 @@ IF NOT EXIST "%EXTRACT_DIR%\" (
61108

62109
REM Extract all files
63110
echo Extracting all .PAK files...
64-
lua "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%\DATA.PAK" "%EXTRACT_DIR%"
65-
lua "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%\DATA0.PAK" "%EXTRACT_DIR%"
66-
lua "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%\DATA1.PAK" "%EXTRACT_DIR%"
67-
lua "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%\DATA2.PAK" "%EXTRACT_DIR%"
68-
lua "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%\DATA3.PAK" "%EXTRACT_DIR%"
69-
lua "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%\DATA4.PAK" "%EXTRACT_DIR%"
70-
lua "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%\DATA5.PAK" "%EXTRACT_DIR%"
71-
lua "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%\DATA6.PAK" "%EXTRACT_DIR%"
111+
lua.exe "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%DATA.PAK" "%EXTRACT_DIR%"
112+
lua.exe "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%DATA0.PAK" "%EXTRACT_DIR%"
113+
lua.exe "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%DATA1.PAK" "%EXTRACT_DIR%"
114+
lua.exe "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%DATA2.PAK" "%EXTRACT_DIR%"
115+
lua.exe "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%DATA3.PAK" "%EXTRACT_DIR%"
116+
lua.exe "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%DATA4.PAK" "%EXTRACT_DIR%"
117+
lua.exe "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%DATA5.PAK" "%EXTRACT_DIR%"
118+
lua.exe "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%DATA6.PAK" "%EXTRACT_DIR%"
72119

73120

74121
REM Convert all the files to .lua
@@ -81,34 +128,34 @@ pushd "%EXTRACT_DIR%"
81128

82129
REM Convert the original files
83130
FOR /R %%F IN (*.WDAT, *.IMAGESET, *.DAT) DO (
84-
SET LUA_FILE=%%F.lua
131+
SET "LUA_FILE=%%F.lua"
85132

86133
rem echo File: %%F
87-
rem echo LUA_FILE: !LUA_FILE!
134+
rem echo LUA_FILE: "!LUA_FILE!"
88135

89-
lua "%UTILS_DIR%\dat2lua.lua" "%%F" "!LUA_FILE!"
136+
lua.exe "%UTILS_DIR%\dat2lua.lua" "%%F" "!LUA_FILE!"
90137

91-
IF NOT errorlevel 1 (
92-
rem echo Created !LUA_FILE!
138+
IF NOT ERRORLEVEL 1 (
139+
rem echo Created "!LUA_FILE!"
93140
) ELSE (
94-
echo ERROR: Could not create !LUA_FILE!
141+
echo ERROR: Could not create "!LUA_FILE!"
95142
)
96143
)
97144

98145

99146
REM Convert the layout files
100147
FOR /R %%F IN (*.LAYOUT) DO (
101-
set LUA_FILE=%%F.lua
148+
SET "LUA_FILE=%%F.lua"
102149

103150
rem echo File: %%F
104-
rem echo LUA_FILE: !LUA_FILE!
151+
rem echo LUA_FILE: "!LUA_FILE!"
105152

106-
lua "%UTILS_DIR%\layout2lua.lua" "%%F" "!LUA_FILE!"
153+
lua.exe "%UTILS_DIR%\layout2lua.lua" "%%F" "!LUA_FILE!"
107154

108-
IF NOT errorlevel 1 (
109-
rem echo Created !LUA_FILE!
155+
IF NOT ERRORLEVEL 1 (
156+
rem echo Created "!LUA_FILE!"
110157
) ELSE (
111-
echo ERROR: Could not create !LUA_FILE!
158+
echo ERROR: Could not create "!LUA_FILE!"
112159
)
113160
)
114161

rgo-deploy.bat

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,32 @@ REM This calls the "rgo-pack.bat" batch file and then moves the generated file d
55
SETLOCAL EnableDelayedExpansion
66

77
REM This variables defines that the script is run from the deploy file
8-
SET IS_DEPLOY=1
8+
SET "IS_DEPLOY=1"
99

1010

1111
REM *********************************************
1212
REM *** Call the pack batch file
1313
REM *********************************************
14+
15+
REM Check if the PATH variable is set or the script is run from inside the directory
16+
WHERE /q rgo-pack.bat
17+
18+
IF ERRORLEVEL 1 (
19+
echo=
20+
echo Couldn't find rgo-pack.bat^^!
21+
echo Please make sure it's in the same directory as this file or is available within
22+
echo one of the direcotries added to the PATH variable^^!
23+
pause
24+
GOTO :EOF
25+
)
26+
1427
CALL rgo-pack.bat %1
1528

1629

30+
IF ERRORLEVEL 1 (
31+
GOTO :EOF
32+
)
33+
1734

1835
REM *********************************************
1936
REM *** Copy the file to the PAK folder
@@ -23,7 +40,7 @@ echo Moving the generated .pak file to the game's PAK directory...
2340
move /Y "%PAK_FILE_WITH_PATH%" "%GAME_PAK_DIR%"
2441

2542

26-
IF NOT errorlevel 1 (
43+
IF NOT ERRORLEVEL 1 (
2744
echo=
2845
echo=
2946
echo SUCCESS^^!
@@ -32,8 +49,29 @@ IF NOT errorlevel 1 (
3249
) ELSE (
3350
echo=
3451
echo=
52+
echo -------------------------------------------------------------------------------------
3553
echo ERROR^^!
3654
echo Something failed^^!
55+
echo -------------------------------------------------------------------------------------
56+
echo=
57+
echo The .pak file was created, but it couldn't be moved to the game directory.
58+
echo Maybe the directory is write protected or you do not have sufficient permissions to
59+
echo access it.
60+
echo The latter could be the case if you're trying to access a folder inside the
61+
echo "C:\Program Files" directory, there only programs/scripts with administrator rights
62+
echo can create files.
63+
echo This could be the case if you're running the Steam version of the game.
64+
echo=
65+
echo You could try to run the script in administrator mode ^(not recommended^), or you
66+
echo could manually copy the generated file to the game's PAKS folder.
67+
echo=
68+
echo The generated file:
69+
echo "%PAK_FILE_WITH_PATH%"
70+
echo=
71+
echo The game's PAKS directory path:
72+
echo "%GAME_PAK_DIR%"
73+
echo=
74+
3775
echo=
3876
pause
3977
)

0 commit comments

Comments
 (0)