Jump to content

Multiple KSP Directories Script


Recommended Posts

Hi everybody!

I wrote a simple Windows shell script that makes a new vanilla installation of KSP by making hardlinks to an existing KSP directory. This allows you to have multiple installations without actually having to install it multiple times. I use this to have multiple sets of mods without actually installing KSP multiple times. It works well for me.

It is designed to be run from the command line. Due to its use of mklink, it needs administrator privileges.

Here is the code for it (spoiler-ed because it is kind of long):

Spoiler

@echo off

REM This program is to create a vanilla installation of Kerbal Space Program by 
REM making links to an existing installation. This allows you to save space over
REM installing KSP multiple times.

set me=%~0
set menoext=%~n0
set parent=%~dp0
if [%2]==[] (
    if [%1]==[] (goto usage)
    if "%%1"=="/^?" (goto usage) else (
        echo Invalid Syntax.
        echo.
        goto usage
        )
    ) else (goto program)

:program
set sourcedir=%~1
set destdir=%~2
echo Making new directory.
mkdir "%destdir%"
cd "%sourcedir%"
echo Making hardlinks to files.
for %%G in (.\*) do (mklink /h "%destdir%\%%~nxG" "%%G" >nul)
echo Linking folders.
cd %parent%
cd "%destdir%"
mkdir GameData
mklink /J .\GameData\Squad "%sourcedir%\GameData\Squad" >nul
mklink /J Internals "%sourcedir%\Internals" >nul
mklink /J KSP_Data "%sourcedir%\KSP_Data" >nul
mklink /J KSP_x64_Data "%sourcedir%\KSP_x64_Data" >nul
mklink /J Launcher_Data "%sourcedir%\Launcher_Data" >nul
mkdir Logs
mklink /J Parts "%sourcedir%\Parts" >nul
mklink /J Plugin_Data "%sourcedir%\Plugin_Data" >nul 
mklink /J Plugins "%sourcedir%\Plugins" >nul
mklink /J Resources "%sourcedir%\Resources" >nul
mkdir saves
mklink /J .\saves\scenarios "%sourcedir%\saves\scenarios" >nul 
mklink /J .\saves\training "%sourcedir%\saves\training" >nul
mkdir Screenshots
mklink /J Ships "%sourcedir%\Ships" >nul
mklink /J sounds "%sourcedir%\sounds" >nul
mkdir thumbs
echo Done!
cd %parent%
goto :EOF

:usage
echo    Makes a new vanilla Kerbal Space Program installation using links to
echo    another installation. This allows you to have multiple KSP installations
echo    wihout having to waste the space for multiple installations.
echo.
echo    Command Usage:
echo.
echo        %me% [/^?] Source Destination
echo.
echo.       /^?             Display this help.
echo        Source         Specifies KSP directory to mirror.
echo        Destination    Specifies the new KSP directory.
goto :EOF

 

To use this script:

  1. Copy the code in the spoiler above.
  2. Paste into a text editor, like Notepad.
  3. Save the file with whatever name you want, wherever you want. Select "all file types" and change the part that says ".txt" to ".bat"
  4. Open an administrator command prompt.
  5. Navigate to where you saved the file using "cd"
  6. Type the name of the file. Then, type the location of the KSP installation you are copying (i.e. "C:\Kerbal Space Program"). If this contains spaces, it must be in quotes. Finish the command with the folder of the new KSP installation. Type /? after the name of the file for help.
  7. You should now have a second KSP installation, that has no mods.

 

Feel free to modify and distribute this code as you see fit. I'm not super experienced with batch files (I mostly use Python), so any input is appreciated!

 

Edited by pogrmman
Fixing bug pointed out below
Link to comment
Share on other sites

  • 1 month later...

Saved it as ksplink.cmd (works same as .bat)

Found a bug:

If I use the following command:

ksplink.cmd KSP_1.1.3_dev jbb2
 

it will create the directory "jbb2" inside the source directory

To avoid, I needed to put in the drive letter, or at least a backslash to start a complete path.

I expected it to create the jbb2 directory in my current directory

 

Other than that, worked well

Link to comment
Share on other sites

  • 2 weeks later...
This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...