Code: Select all
Rem Max Payne 2
Set GamePath=
Set D2Test=
for /F "Usebackq Tokens=1* delims=," %%a in ("%SrcPath%\folders.txt") do IF /I "%%a"=="Max payne 2" set GamePath=%%b
Echo %time% Path: "%GamePath%" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF NOT "%GamePath%"=="" IF EXIST "%GamePath%\" IF EXIST "%SrcPath%\MaxPayne2\" IF EXIST "%RegPath%\MaxPayn2.Reg" (
Echo %time% Checking for Max Payne 2 Save games >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
REG IMPORT "%RegPath%\MaxPayne2.Reg" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
FOR /f "tokens=5*" %%a in ('REG QUERY "HKEY_CURRENT_USER\Software\Remedy Entertainment\Max Payne 2\Save Game" /v "Last Saved Game Filename"') do set D2Test=%%~dpb
set D2Test=%D2Test:\\=\%
IF NOT "%D2Test%"=="" IF NOT EXIST "%D2Test%\" xcopy "%SrcPath%\MaxPayne2" "%D2Test%" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
So, Max Payne 2 now looks like...
Code: Select all
Rem Max Payne 2
Set GamePath=
Set D2Test=
for /F "Usebackq Tokens=1* delims=," %%a in ("%SrcPath%\folders.txt") do IF /I "%%a"=="Max payne 2" set GamePath=%%b
Echo %time% Path: "%GamePath%" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF NOT "%GamePath%"=="" IF EXIST "%GamePath%\" IF EXIST "%RegPath%\MaxPayn2.Reg" REG IMPORT "%RegPath%\MaxPayne2.Reg" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
FOR /f "tokens=5*" %%a in ('REG QUERY "HKEY_CURRENT_USER\Software\Remedy Entertainment\Max Payne 2\Save Game" /v "Last Saved Game Filename"') do set D2Test=%%~dpb
IF NOT "%D2Test%"=="" (
set D2Test=%D2Test:\\=\%
xcopy "%SrcPath%\MaxPayne2" "%D2Test%" /e/q/y/c/k/i/h/x >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
I clearly have a massive gap in my knowledge as this delayedexpansion stuff just doesn't gel.
For example, after coding 184 games, not a single one of these works within the script, and I've removed the surrounding IF /I "%DoGame:~0,1%"=="Y" (...). The backup script which is now identical (except the reg commands are export vs import), does work, but these don't. They ALL return null values. This doesn't work (restore/import)...
Code: Select all
Rem Mass Effect.
Set GamePath=
Echo %time% Checking for Mass Effect >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
for /F "Usebackq Tokens=1* delims=," %%a in ("%SrcPath%\folders.txt") do IF /I "%%a"=="Mass Effect" set GamePath=%%b
Echo %time% Path: "%Gamepath%" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF EXIST "%GamePath%\" IF NOT "%GamePath%"=="" (
Echo %time% Restore Mass Effect >>C:\%USERDOMAIN%.Backup.Log 2>&1
IF NOT EXIST "%RegPath%\MassEffect.Reg" IF EXIST "%RegPath%\MassEffect11.Reg" REG IMPORT "%RegPath%\MassEffect11.Reg" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF NOT EXIST "%RegPath%\MassEffect.Reg" IF EXIST "%RegPath%\MassEffect12.Reg" REG IMPORT "%RegPath%\MassEffect12.Reg" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
IF NOT EXIST "%RegPath%\MassEffect.Reg" IF EXIST "%RegPath%\MassEffect13.Reg" REG IMPORT "%RegPath%\MassEffect13.Reg" >>C:\%USERDOMAIN%.PostInstall.Log 2>&1
)
Code: Select all
Rem Mass Effect
Set GamePath=
Echo %time% Checking for Mass Effect >>C:\%USERDOMAIN%.Backup.Log 2>&1
for /F "Usebackq Tokens=1* delims=," %%a in ("%SrcPath%\folders.txt") do IF /I "%%a"=="Mass Effect" set GamePath=%%b
Echo %time% Path: "%GamePath%" >>C:\%USERDOMAIN%.Backup.Log 2>&1
IF EXIST "%GamePath%\" IF NOT "%GamePath%"=="" (
Echo %time% Backup Mass Effect >>C:\%USERDOMAIN%.Backup.Log 2>&1
REG EXPORT "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\BioWare\Mass Effect" "%RegPath%\MassEffect11.reg" /y >>C:\%USERDOMAIN%.Backup.Log 2>&1
REG EXPORT "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Electronic Arts\Electronic Arts\Mass Effect (tm)" "%RegPath%\MassEffect12.reg" /y >>C:\%USERDOMAIN%.Backup.Log 2>&1
REG EXPORT "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{1B0FBB9A-995D-47cd-87CD-13E68B676E4F}" "%RegPath%\MassEffect13.reg" /y >>C:\%USERDOMAIN%.Backup.Log 2>&1
)
I figured the folders.txt file is ok given that the back up works, and the for /f command works from a command line, but I manually typed the entire file from scratch anyway.
...while all that do (for example use GamePath) shouldn't work correct
All games are preceded with Set GamePath=
But in trying to understand variable expansion, is my take away, "Never create a variable within an IF ( ... ) block"?