Skip to content

Commit

Permalink
Added more error checks.
Browse files Browse the repository at this point in the history
Added more hopefully meaningful error messages.
Made the script more robust against paths with special characters.
  • Loading branch information
sp00n committed Oct 24, 2022
1 parent a7c3b35 commit a6ff948
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 64 deletions.
107 changes: 77 additions & 30 deletions rgo-convert-all.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,59 @@ REM In the case of relative paths, they will be relative to the Game installatio

SETLOCAL EnableExtensions EnableDelayedExpansion

SET CALLER=convert-all

REM Check if the PATH variable is set or the script is run from inside the directory
WHERE /q rgo-variables.bat

IF ERRORLEVEL 1 (
echo=
echo Couldn't find rgo-variables.bat^^!
echo Please make sure it's in the same directory as this file or is available within
echo one of the directories added to the PATH variable^^!
pause
GOTO :EOF
)


REM Check for the existance of the lua.exe
WHERE /q lua.exe

IF ERRORLEVEL 1 (
echo=
echo Couldn't find lua.exe^^!
echo Please make sure the lua.exe is available within one of the directories added
echo to the PATH variable^^!
pause
GOTO :EOF
)


SET "CALLER=convert-all"
CALL rgo-variables.bat

REM Check if a paramter was passe or not

REM Check if a parameter was passed or not
REM The parameter will be the destination directory for the extracted files
REM If none was set, we're using DATA directory inside the original location
IF "%~1"=="" (
SET LOCATION=PAKS\DATA
SET "LOCATION=PAKS\DATA"
) ELSE (
SET LOCATION=%~1
SET "LOCATION=%~1"
)

REM Remove any trailing backslash
IF %LOCATION:~-1%==\ (
SET LOCATION=%LOCATION:~0,-1%
SET "LOCATION=%LOCATION:~0,-1%"
)


REM Check if the LOCATION contains ":\"
REM If it does, treat it as an absolute path
REM Otherwise it's relative to the game dir
IF NOT x"%LOCATION::\=%"==x"%LOCATION%" (
SET EXTRACT_DIR=%LOCATION%
SET "EXTRACT_DIR=%LOCATION%"
) ELSE (
SET EXTRACT_DIR=%GAME_DIR%\%LOCATION%
SET "EXTRACT_DIR=%GAME_DIR%\%LOCATION%"
)


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


IF errorlevel 1 (
IF ERRORLEVEL 1 (
echo=
echo -------------------------------------------------------------------------------------
echo Couldn't create "%EXTRACT_DIR%", aborting^^!
echo -------------------------------------------------------------------------------------
echo=
echo Maybe the directory is write protected or you do not have sufficient permissions to
echo access it.
echo The latter could be the case if you're trying to access a folder inside the
echo "C:\Program Files" directory, there only programs/scripts with administrator rights
echo can create folders.
echo This is very likely if you're running the Steam version of the game.
echo=
echo You could try to run the script in administrator mode ^(not recommended^), or you
echo could could simply provide a destination folder for the extracted files like so:
echo=
echo rgo-convert-all.bat "D:\Modding\RGO\DATA"
echo=
echo The extracted files will then be copied into this directory.
echo=
echo Couldn't create %EXTRACT_DIR%, aborting^^!
pause
GOTO :EOF
)

IF NOT EXIST "%EXTRACT_DIR%\" (
echo=
echo Couldn't create %EXTRACT_DIR%, aborting^^!
echo Couldn't create "%EXTRACT_DIR%", aborting^^!
pause
GOTO :EOF
)
Expand All @@ -61,14 +108,14 @@ IF NOT EXIST "%EXTRACT_DIR%\" (

REM Extract all files
echo Extracting all .PAK files...
lua "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%\DATA.PAK" "%EXTRACT_DIR%"
lua "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%\DATA0.PAK" "%EXTRACT_DIR%"
lua "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%\DATA1.PAK" "%EXTRACT_DIR%"
lua "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%\DATA2.PAK" "%EXTRACT_DIR%"
lua "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%\DATA3.PAK" "%EXTRACT_DIR%"
lua "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%\DATA4.PAK" "%EXTRACT_DIR%"
lua "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%\DATA5.PAK" "%EXTRACT_DIR%"
lua "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%\DATA6.PAK" "%EXTRACT_DIR%"
lua.exe "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%DATA.PAK" "%EXTRACT_DIR%"
lua.exe "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%DATA0.PAK" "%EXTRACT_DIR%"
lua.exe "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%DATA1.PAK" "%EXTRACT_DIR%"
lua.exe "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%DATA2.PAK" "%EXTRACT_DIR%"
lua.exe "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%DATA3.PAK" "%EXTRACT_DIR%"
lua.exe "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%DATA4.PAK" "%EXTRACT_DIR%"
lua.exe "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%DATA5.PAK" "%EXTRACT_DIR%"
lua.exe "%UTILS_DIR%\unpack.lua" "%GAME_PAK_DIR%DATA6.PAK" "%EXTRACT_DIR%"


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

REM Convert the original files
FOR /R %%F IN (*.WDAT, *.IMAGESET, *.DAT) DO (
SET LUA_FILE=%%F.lua
SET "LUA_FILE=%%F.lua"

rem echo File: %%F
rem echo LUA_FILE: !LUA_FILE!
rem echo LUA_FILE: "!LUA_FILE!"

lua "%UTILS_DIR%\dat2lua.lua" "%%F" "!LUA_FILE!"
lua.exe "%UTILS_DIR%\dat2lua.lua" "%%F" "!LUA_FILE!"

IF NOT errorlevel 1 (
rem echo Created !LUA_FILE!
IF NOT ERRORLEVEL 1 (
rem echo Created "!LUA_FILE!"
) ELSE (
echo ERROR: Could not create !LUA_FILE!
echo ERROR: Could not create "!LUA_FILE!"
)
)


REM Convert the layout files
FOR /R %%F IN (*.LAYOUT) DO (
set LUA_FILE=%%F.lua
SET "LUA_FILE=%%F.lua"

rem echo File: %%F
rem echo LUA_FILE: !LUA_FILE!
rem echo LUA_FILE: "!LUA_FILE!"

lua "%UTILS_DIR%\layout2lua.lua" "%%F" "!LUA_FILE!"
lua.exe "%UTILS_DIR%\layout2lua.lua" "%%F" "!LUA_FILE!"

IF NOT errorlevel 1 (
rem echo Created !LUA_FILE!
IF NOT ERRORLEVEL 1 (
rem echo Created "!LUA_FILE!"
) ELSE (
echo ERROR: Could not create !LUA_FILE!
echo ERROR: Could not create "!LUA_FILE!"
)
)

Expand Down
42 changes: 40 additions & 2 deletions rgo-deploy.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,32 @@ REM This calls the "rgo-pack.bat" batch file and then moves the generated file d
SETLOCAL EnableDelayedExpansion

REM This variables defines that the script is run from the deploy file
SET IS_DEPLOY=1
SET "IS_DEPLOY=1"


REM *********************************************
REM *** Call the pack batch file
REM *********************************************

REM Check if the PATH variable is set or the script is run from inside the directory
WHERE /q rgo-pack.bat

IF ERRORLEVEL 1 (
echo=
echo Couldn't find rgo-pack.bat^^!
echo Please make sure it's in the same directory as this file or is available within
echo one of the direcotries added to the PATH variable^^!
pause
GOTO :EOF
)

CALL rgo-pack.bat %1


IF ERRORLEVEL 1 (
GOTO :EOF
)


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


IF NOT errorlevel 1 (
IF NOT ERRORLEVEL 1 (
echo=
echo=
echo SUCCESS^^!
Expand All @@ -32,8 +49,29 @@ IF NOT errorlevel 1 (
) ELSE (
echo=
echo=
echo -------------------------------------------------------------------------------------
echo ERROR^^!
echo Something failed^^!
echo -------------------------------------------------------------------------------------
echo=
echo The .pak file was created, but it couldn't be moved to the game directory.
echo Maybe the directory is write protected or you do not have sufficient permissions to
echo access it.
echo The latter could be the case if you're trying to access a folder inside the
echo "C:\Program Files" directory, there only programs/scripts with administrator rights
echo can create files.
echo This could be the case if you're running the Steam version of the game.
echo=
echo You could try to run the script in administrator mode ^(not recommended^), or you
echo could manually copy the generated file to the game's PAKS folder.
echo=
echo The generated file:
echo "%PAK_FILE_WITH_PATH%"
echo=
echo The game's PAKS directory path:
echo "%GAME_PAK_DIR%"
echo=

echo=
pause
)
Loading

0 comments on commit a6ff948

Please sign in to comment.