View Single Post
Old 05-23-16, 12:48 AM   #9
baka
Swabbie
 
Join Date: Aug 2009
Posts: 6
Downloads: 147
Uploads: 0
Default

This is an old thread but taking the comments above, I have written a batch file that swaps out the active SH5 copy and the settings and saves in your Documents directory for another copy and saves just by renaming folders. No registry changes. Just drag and drop the folder of the inactive SH5 copy you want to activate on the batch file.

Works for me to run mod tests on one copy, keep another for the stock version and a third for The Wolves of Steel.

You need to know how to edit the batch file below to work in your set up. If you know about Windows batch file programming, it should be easy.

Copy the code below and save it in a text file but change the extension to .bat instead of .txt.

To be safe, the actual renaming lines have been commented out so you can test it to see if it works after editing the path names pointing to your Documents directory and the Silent Hunter 5 install directory. Once you are happy the simulation works, edit out the REM part in front of RENAME in the 4 relevant lines.

You can create as many copy of the default install folder as you like. Give each a unique name and make that as part of the name of an empty folder WITHIN each copy. The batch file looks for a folder with "unique_name_" as the first part of its name to correctly swap out the active copy. E.g. unique_name_SH5_1.2.Wolves_of_Steel. Note that you have to do this for EVERY copy.

See details within the batch file.

Hope it is not too complicated and of use to someone.

Code:
@ECHO off
REM =============== Intro ===================
REM This batch file swaps the current game with another copy in a dropped folder
REM It will also rename the settings file usually located in the Documents folder
REM of the current user
REM Requires an unique name for each copy stored in a folder name within 
REM the directory of that copy

REM Create an empty folder
REM name it in this format: unique_name_[choose_a_name_for_the_copy_without_these_brackets_or_spaces]
REM MUST start with "unique_name_"

REM Spaces in file names or path may cause problems
REM If possible, initial game installation should avoid using 
REM the C:\Program Files or C:\Program Files(x86) folders as they need 
REM special write privileges to change content which may be a problem
REM ==================================

REM ============ Modifications to make this work ===============
REM 1. Duplicate clean copies of your game
REM 2. Create a subfolder in each giving each copy a unique name as mentioned above
REM 3. Change the default path variables in the User Defined Variables section below
REM 4. Place this batch file in the same folder containing your game copies (optional)
REM 5. Try dropping an inactive copy to swap out the active copy
REM 6. Look at the DOS Console window output and make sure the file name changes are right
REM 7. If everything looks right, uncomment the 4 lines in this batch file that 
REM    renames files (remove the REM before RENAME) and save. 
REM The batch file is now ready to do its thing.
REM ==================================

REM User Defined Variables - change according to your set up =========================

REM Change this to the path to your documents folder if necessary
SET settings_file_path=%HOMEDRIVE%%HOMEPATH%\Documents

REM No need to change the next item
REM This is the default folder where Silent Hunter 5 settings are saved
SET settings_file_name=SH5

REM change this to where Silent Hunter 5 had been installed
SET full_installed_path=C:\Ubisoft\Silent Hunter5


REM Parse variables ================================
For %%A in ("%full_installed_path%") do (
    Set installed_path=%%~dpA
    Set installed_folder=%%~nxA
)
IF "%installed_path:~-1%"=="\" SET installed_path=%installed_path:~0,-1%

IF [%1]==[] GOTO NoTargetProvided

ECHO.Copy to activate is: %~1

IF NOT EXIST "%~1" GOTO NoTargetFolder

for %%F in ("%~1") do SET TargetFolder=%%~nxF

REM Check current default folder

ECHO.Default Installed Path is: %installed_path%\%installed_folder%

IF NOT EXIST "%installed_path%" GOTO NoInstallPath

IF NOT EXIST %installed_path%\%installed_folder% GOTO NoInstallFolder

REM Make sure the installation folder is not the same as the target folder

IF [%~1]==[%installed_path%\%installed_folder%] GOTO InstallFolderDropped

REM Look for name of the current active copy

IF NOT EXIST "%installed_path%\%installed_folder%\unique_name_*" GOTO NameNotFound

for /f "delims=" %%a in ('dir "%installed_path%\%installed_folder%\unique_name_*" /ad /b') do @set current_copy_name=%%a
SET current_copy_name=%current_copy_name:~12%
echo.Current active copy is: %current_copy_name%

REM Main swapping routine ===============================

REM Now change the installed folder to its real name

ECHO RENAME "%installed_path%\%installed_folder%" "%current_copy_name%"
REM RENAME "%installed_path%\%installed_folder%" "%current_copy_name%"

REM Now change the target folder to the default install folder name

ECHO RENAME "%~1" "%installed_folder%"
REM RENAME "%~1" "%installed_folder%"

REM rename the settings files in User/Documents

IF EXIST "%settings_file_path%\%settings_file_name%" (
	ECHO RENAME "%settings_file_path%\%settings_file_name%" "%current_copy_name%"
REM	RENAME "%settings_file_path%\%settings_file_name%" "%current_copy_name%"
)

IF EXIST "%settings_file_path%\%TargetFolder%" (
	ECHO RENAME "%settings_file_path%\%TargetFolder%" "%settings_file_name%"
REM	RENAME "%settings_file_path%\%TargetFolder%" "%settings_file_name%"
)

Set ErrorMsg=Switched to %TargetFolder%!
GOTO printMsg

REM Error processing =================================

:NoInstallPath
Set ErrorMsg=Installation Path not found!
GOTO printMsg

:NoInstallFolder
Set ErrorMsg=Installation Folder not found!
GOTO printMsg

:NoTargetProvided
Set ErrorMsg=No Target Folder specified!
GOTO printMsg

:NoTargetFolder
Set ErrorMsg=Target Folder not found!
GOTO printMsg

:InstallFolderDropped
Set ErrorMsg=Aborted as Target Folder is the installation folder!
GOTO printMsg

:NameNotFound
Set ErrorMsg=Real Name not found in installed folder
GOTO printMsg

REM Print messages and exit ==============================

:printMsg
ECHO %ErrorMsg%

pause

exit /b

Last edited by baka; 05-24-16 at 08:12 PM.
baka is offline   Reply With Quote