Skip to content

Commit

Permalink
Improve path handling in batch scripts (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
xezon authored Oct 13, 2021
1 parent 9d6a9ea commit 8e71858
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 101 deletions.
21 changes: 13 additions & 8 deletions Patch104pZH/MAKE_Install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,26 @@ if '%errorlevel%' NEQ '0' (
:--------------------------------------

echo on
set ThisDir0="%~dp0."

setlocal

set ThisDir0=%~dp0.
set GeneratedReleaseUnpackedFiles=

call %ThisDir0%\Scripts\MAKE_Patch104pZH.bat build
call %ThisDir0%\Scripts\MAKE_Patch104pArtZH.bat build
call %ThisDir0%\SETUP_UserSettings.bat
call "%ThisDir0%\Scripts\MAKE_Patch104pZH.bat" build
call "%ThisDir0%\Scripts\MAKE_Patch104pArtZH.bat" build
call "%ThisDir0%\SETUP_UserSettings.bat"

:: Rename files as per setup in SETUP_UserSettings.bat
for %%f in (%GameFilesToDisable%) do (
if exist %GameRootDir%\%%f (
ren %GameRootDir%\%%f %%f.PATCH104P
)
if exist "%GameRootDir:"=%\%%f" (
ren "%GameRootDir:"=%\%%f" %%f.PATCH104P
)
)

:: Copy release files to game
for %%f in (%GeneratedReleaseUnpackedFiles%) do (
xcopy /y %GeneratedReleaseUnpackedDir%\%%f %GameRootDir%\%%f*
xcopy /y "%GeneratedReleaseUnpackedDir%\%%f" "%GameRootDir:"=%\"
)

endlocal
15 changes: 10 additions & 5 deletions Patch104pZH/MAKE_Install_Run.bat
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ if '%errorlevel%' NEQ '0' (
:--------------------------------------

echo on
set ThisDir0="%~dp0."

setlocal

set ThisDir0=%~dp0.

:: Install
call %ThisDir0%\MAKE_Install.bat
call "%ThisDir0%\MAKE_Install.bat"

:: Run game
set GameExeArgs0=%GameExeArgs:"=%
%GameRootDir%\%GameExeFile% %GameExeArgs0%
call "%ThisDir0%\SETUP_UserSettings.bat"
"%GameRootDir:"=%\%GameExeFile:"=%" %GameExeArgs:"=%

:: Uninstall
call %ThisDir0%\MAKE_Uninstall.bat
call "%ThisDir0%\MAKE_Uninstall.bat"

endlocal
14 changes: 9 additions & 5 deletions Patch104pZH/MAKE_Release.bat
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
set ThisDir0="%~dp0."
call %ThisDir0%\Scripts\MAKE_Patch104pZH.bat build
call %ThisDir0%\Scripts\MAKE_Patch104pArtZH.bat build
setlocal

set ThisDir0=%~dp0.
call "%ThisDir0%\Scripts\MAKE_Patch104pZH.bat" build
call "%ThisDir0%\Scripts\MAKE_Patch104pArtZH.bat" build

:: Copy base release files
xcopy /y /s %ReleaseUnpackedDir%\* %GeneratedReleaseUnpackedDir%\*
xcopy /y /s "%ReleaseUnpackedDir%\*" "%GeneratedReleaseUnpackedDir%\*"

:: Define archive name(s)
set ArchiveName=Patch104pZH

:: Generate Archive(s)
tar.exe -a -c -C %GeneratedReleaseUnpackedDir% -f %ReleaseDir%\%ArchiveName%.zip *.*
tar.exe -a -c -C "%GeneratedReleaseUnpackedDir%" -f "%ReleaseDir%\%ArchiveName%.zip" *.*

endlocal
21 changes: 13 additions & 8 deletions Patch104pZH/MAKE_Uninstall.bat
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,27 @@ if '%errorlevel%' NEQ '0' (
CD /D "%~dp0"
:--------------------------------------

setlocal

echo on
set ThisDir0="%~dp0."

set ThisDir0=%~dp0.
set GeneratedReleaseUnpackedFiles=

call %ThisDir0%\Scripts\MAKE_Patch104pZH.bat
call %ThisDir0%\Scripts\MAKE_Patch104pArtZH.bat
call %ThisDir0%\SETUP_UserSettings.bat
call "%ThisDir0%\Scripts\MAKE_Patch104pZH.bat"
call "%ThisDir0%\Scripts\MAKE_Patch104pArtZH.bat"
call "%ThisDir0%\SETUP_UserSettings.bat"

:: Remove release files from game
for %%f in (%GeneratedReleaseUnpackedFiles%) do (
del /f /q %GameRootDir%\%%f
del /f /q "%GameRootDir:"=%\%%f"
)

:: Restore files as per setup in SETUP_UserSettings.bat
for %%f in (%GameFilesToDisable%) do (
if exist %GameRootDir%\%%f.PATCH104P (
ren %GameRootDir%\%%f.PATCH104P %%f
)
if exist "%GameRootDir:"=%\%%f.PATCH104P" (
ren "%GameRootDir:"=%\%%f.PATCH104P" %%f
)
)

endlocal
44 changes: 22 additions & 22 deletions Patch104pZH/SETUP_UserSettings.bat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ set GameExeArgs="-win -quickstart"

:: Set files that should be voided (renamed) before launching generals.exe
set GameFilesToDisable=
set GameFilesToDisable=%GameFilesToDisable% "200_ControlBarObsEnglishZH.big"
set GameFilesToDisable=%GameFilesToDisable% "250_HideIP_WindowZH.big"
set GameFilesToDisable=%GameFilesToDisable% "251_HideMail_WindowZH.big"
set GameFilesToDisable=%GameFilesToDisable% "339_ControlBarProHideIpZH.big"
set GameFilesToDisable=%GameFilesToDisable% "339_ControlBarProHideMailZH.big"
set GameFilesToDisable=%GameFilesToDisable% "340_ControlBarPro2160ZH.big"
set GameFilesToDisable=%GameFilesToDisable% "340_ControlBarPro1440ZH.big"
set GameFilesToDisable=%GameFilesToDisable% "340_ControlBarPro1080ZH.big"
set GameFilesToDisable=%GameFilesToDisable% "340_ControlBarPro900ZH.big"
set GameFilesToDisable=%GameFilesToDisable% "340_ControlBarPro720ZH.big"
set GameFilesToDisable=%GameFilesToDisable% "340_ControlBarProZH.big"
set GameFilesToDisable=%GameFilesToDisable% "400_ControlBarHDBaseZH.big"
set GameFilesToDisable=%GameFilesToDisable% "400_ControlBarHDBrazilianZH.big"
set GameFilesToDisable=%GameFilesToDisable% "400_ControlBarHDChineseZH.big"
set GameFilesToDisable=%GameFilesToDisable% "400_ControlBarHDEnglishZH.big"
set GameFilesToDisable=%GameFilesToDisable% "400_ControlBarHDFrenchZH.big"
set GameFilesToDisable=%GameFilesToDisable% "400_ControlBarHDGermanZH.big"
set GameFilesToDisable=%GameFilesToDisable% "400_ControlBarHDItalianZH.big"
set GameFilesToDisable=%GameFilesToDisable% "400_ControlBarHDKoreanZH.big"
set GameFilesToDisable=%GameFilesToDisable% "400_ControlBarHDPolishZH.big"
set GameFilesToDisable=%GameFilesToDisable% "400_ControlBarHDSpanishZH.big"
set GameFilesToDisable=%GameFilesToDisable% "800_GermanUncutLiteZH.big"
set GameFilesToDisable=%GameFilesToDisable% 200_ControlBarObsEnglishZH.big
set GameFilesToDisable=%GameFilesToDisable% 250_HideIP_WindowZH.big
set GameFilesToDisable=%GameFilesToDisable% 251_HideMail_WindowZH.big
set GameFilesToDisable=%GameFilesToDisable% 339_ControlBarProHideIpZH.big
set GameFilesToDisable=%GameFilesToDisable% 339_ControlBarProHideMailZH.big
set GameFilesToDisable=%GameFilesToDisable% 340_ControlBarPro2160ZH.big
set GameFilesToDisable=%GameFilesToDisable% 340_ControlBarPro1440ZH.big
set GameFilesToDisable=%GameFilesToDisable% 340_ControlBarPro1080ZH.big
set GameFilesToDisable=%GameFilesToDisable% 340_ControlBarPro900ZH.big
set GameFilesToDisable=%GameFilesToDisable% 340_ControlBarPro720ZH.big
set GameFilesToDisable=%GameFilesToDisable% 340_ControlBarProZH.big
set GameFilesToDisable=%GameFilesToDisable% 400_ControlBarHDBaseZH.big
set GameFilesToDisable=%GameFilesToDisable% 400_ControlBarHDBrazilianZH.big
set GameFilesToDisable=%GameFilesToDisable% 400_ControlBarHDChineseZH.big
set GameFilesToDisable=%GameFilesToDisable% 400_ControlBarHDEnglishZH.big
set GameFilesToDisable=%GameFilesToDisable% 400_ControlBarHDFrenchZH.big
set GameFilesToDisable=%GameFilesToDisable% 400_ControlBarHDGermanZH.big
set GameFilesToDisable=%GameFilesToDisable% 400_ControlBarHDItalianZH.big
set GameFilesToDisable=%GameFilesToDisable% 400_ControlBarHDKoreanZH.big
set GameFilesToDisable=%GameFilesToDisable% 400_ControlBarHDPolishZH.big
set GameFilesToDisable=%GameFilesToDisable% 400_ControlBarHDSpanishZH.big
set GameFilesToDisable=%GameFilesToDisable% 800_GermanUncutLiteZH.big

echo on
40 changes: 20 additions & 20 deletions Patch104pZH/Scripts/MAKE_Patch104pArtZH.bat
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
echo on
set ThisDir1="%~dp0."
set ThisDir1=%~dp0.
set ThisArg1=%~1
call %ThisDir1%\SETUP_Folders.bat
call "%ThisDir1%\SETUP_Folders.bat"

:: Define big file name(s)
set BigName=600_Patch104pArtZH
set GeneratedReleaseUnpackedFiles=%GeneratedReleaseUnpackedFiles% %BigName%.big

if "%ThisArg1%"=="build" (
:: Free folders of big file contents
del /s /f /q %GeneratedBigFilesUnpackedDir%\%BigName%
del /s /f /q %GeneratedBigFilesDir%\%BigName%.big

:: Copy .big contents
:: Add optional non-essential art files here.
xcopy /y %GameFilesDir%\Art\W3D\NBPTower_DNS.W3D %GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\
xcopy /y %GameFilesDir%\Art\W3D\NBPTower_DS.W3D %GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\
xcopy /y %GameFilesDir%\Art\W3D\NBPTower_ENS.W3D %GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\
xcopy /y %GameFilesDir%\Art\W3D\NBPTower_ES.W3D %GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\
xcopy /y %GameFilesDir%\Art\W3D\NBPTower_NS.W3D %GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\
xcopy /y %GameFilesDir%\Art\W3D\NBPTower_S.W3D %GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\

:: Generate .big file(s)
%ToolsDir%\GeneralsBigCreator\GeneralsBigCreator.exe -source %GeneratedBigFilesUnpackedDir%\%BigName% -dest %GeneratedBigFilesDir%\%BigName%.big

:: Generate Release file(s)
xcopy /y %GeneratedBigFilesDir%\%BigName%.big %GeneratedReleaseUnpackedDir%\%BigName%.big*
:: Free folders of big file contents
del /f /q /s "%GeneratedBigFilesUnpackedDir%\%BigName%"
del /f /q "%GeneratedBigFilesDir%\%BigName%.big"
:: Copy .big contents
:: Add optional non-essential art files here.
xcopy /y "%GameFilesDir%\Art\W3D\NBPTower_DNS.W3D" "%GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\"
xcopy /y "%GameFilesDir%\Art\W3D\NBPTower_DS.W3D" "%GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\"
xcopy /y "%GameFilesDir%\Art\W3D\NBPTower_ENS.W3D" "%GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\"
xcopy /y "%GameFilesDir%\Art\W3D\NBPTower_ES.W3D" "%GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\"
xcopy /y "%GameFilesDir%\Art\W3D\NBPTower_NS.W3D" "%GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\"
xcopy /y "%GameFilesDir%\Art\W3D\NBPTower_S.W3D" "%GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\"
:: Generate .big file(s)
"%ToolsDir%\GeneralsBigCreator\GeneralsBigCreator.exe" -source "%GeneratedBigFilesUnpackedDir%\%BigName%" -dest "%GeneratedBigFilesDir%\%BigName%.big"
:: Generate Release file(s)
xcopy /y "%GeneratedBigFilesDir%\%BigName%.big" "%GeneratedReleaseUnpackedDir%\"
)
50 changes: 25 additions & 25 deletions Patch104pZH/Scripts/MAKE_Patch104pZH.bat
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
echo on
set ThisDir1="%~dp0."
set ThisDir1=%~dp0.
set ThisArg1=%~1
call %ThisDir1%\SETUP_Folders.bat
call "%ThisDir1%\SETUP_Folders.bat"

:: Define big file name(s)
set BigName=600_Patch104pZH
set GeneratedReleaseUnpackedFiles=%GeneratedReleaseUnpackedFiles% %BigName%.big

if "%ThisArg1%"=="build" (
:: Free folders of big file contents
del /s /f /q %GeneratedBigFilesUnpackedDir%\%BigName%
del /s /f /q %GeneratedBigFilesDir%\%BigName%.big

:: Copy .big contents
:: All files listed here become part of the core of Patch104p and are meant
:: to be critical for client compatibility and essential for functionality.
:: Optional files should be moved into one of the other scripts.
xcopy /y /s %GameFilesDir%\*.ini %GeneratedBigFilesUnpackedDir%\%BigName%\
xcopy /y /s %GameFilesDir%\*.wnd %GeneratedBigFilesUnpackedDir%\%BigName%\
xcopy /y %GameFilesDir%\Art\Textures\exlaser3.dds %GeneratedBigFilesUnpackedDir%\%BigName%\Art\Textures\
xcopy /y %GameFilesDir%\Art\W3D\ABSWGLink_L.W3D %GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\
xcopy /y %GameFilesDir%\Art\W3D\AVAvnger.W3D %GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\
xcopy /y %GameFilesDir%\Art\W3D\AVAvnger_D.W3D %GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\
xcopy /y %GameFilesDir%\Art\W3D\EXCarptBmb2.W3D %GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\
xcopy /y %GameFilesDir%\Art\W3D\NVLOutpost.W3D %GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\
xcopy /y %GameFilesDir%\Art\W3D\NVLOutpost_D.W3D %GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\

:: Generate .big file(s)
%ToolsDir%\GeneralsBigCreator\GeneralsBigCreator.exe -source %GeneratedBigFilesUnpackedDir%\%BigName% -dest %GeneratedBigFilesDir%\%BigName%.big

:: Generate Release file(s)
xcopy /y %GeneratedBigFilesDir%\%BigName%.big %GeneratedReleaseUnpackedDir%\%BigName%.big*
:: Free folders of big file contents
del /f /q /s "%GeneratedBigFilesUnpackedDir%\%BigName%"
del /f /q "%GeneratedBigFilesDir%\%BigName%.big"
:: Copy .big contents
:: All files listed here become part of the core of Patch104p and are meant
:: to be critical for client compatibility and essential for functionality.
:: Optional files should be moved into one of the other scripts.
xcopy /y /s "%GameFilesDir%\*.ini" "%GeneratedBigFilesUnpackedDir%\%BigName%\"
xcopy /y /s "%GameFilesDir%\*.wnd" "%GeneratedBigFilesUnpackedDir%\%BigName%\"
xcopy /y "%GameFilesDir%\Art\Textures\exlaser3.dds" "%GeneratedBigFilesUnpackedDir%\%BigName%\Art\Textures\"
xcopy /y "%GameFilesDir%\Art\W3D\ABSWGLink_L.W3D" "%GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\"
xcopy /y "%GameFilesDir%\Art\W3D\AVAvnger.W3D" "%GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\"
xcopy /y "%GameFilesDir%\Art\W3D\AVAvnger_D.W3D" "%GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\"
xcopy /y "%GameFilesDir%\Art\W3D\EXCarptBmb2.W3D" "%GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\"
xcopy /y "%GameFilesDir%\Art\W3D\NVLOutpost.W3D" "%GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\"
xcopy /y "%GameFilesDir%\Art\W3D\NVLOutpost_D.W3D" "%GeneratedBigFilesUnpackedDir%\%BigName%\Art\W3D\"
:: Generate .big file(s)
"%ToolsDir%\GeneralsBigCreator\GeneralsBigCreator.exe" -source "%GeneratedBigFilesUnpackedDir%\%BigName%" -dest "%GeneratedBigFilesDir%\%BigName%.big"
:: Generate Release file(s)
xcopy /y "%GeneratedBigFilesDir%\%BigName%.big" "%GeneratedReleaseUnpackedDir%\"
)
13 changes: 5 additions & 8 deletions Patch104pZH/Scripts/SETUP_Folders.bat
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
:: Setup work folders
set ProjectDir="%~dp0.."
set ProjectDir=%~dp0..
set ToolsDir=%ProjectDir%\..\Tools
set GameFilesDir=%ProjectDir%\GameFilesEdited
set ReleaseUnpackedDir=%ProjectDir%\ReleaseUnpacked
set ReleaseDir=%ProjectDir%\.Release

set GeneratedBigFilesUnpackedDir=%ProjectDir%\.Generated\BigFilesUnpacked
set GeneratedBigFilesDir=%ProjectDir%\.Generated\BigFiles

set GeneratedReleaseUnpackedDir=%ProjectDir%\.Generated\ReleaseUnpacked

:: Create folders
if not exist %ReleaseDir% mkdir %ReleaseDir%
if not exist %GeneratedBigFilesUnpackedDir% mkdir %GeneratedBigFilesUnpackedDir%
if not exist %GeneratedBigFilesDir% mkdir %GeneratedBigFilesDir%
if not exist %GeneratedReleaseUnpackedDir% mkdir %GeneratedReleaseUnpackedDir%

setlocal enableextensions enabledelayedexpansion
if not exist "%ReleaseDir%" mkdir "%ReleaseDir%"
if not exist "%GeneratedBigFilesUnpackedDir%" mkdir "%GeneratedBigFilesUnpackedDir%"
if not exist "%GeneratedBigFilesDir%" mkdir "%GeneratedBigFilesDir%"
if not exist "%GeneratedReleaseUnpackedDir%" mkdir "%GeneratedReleaseUnpackedDir%"

0 comments on commit 8e71858

Please sign in to comment.