1. This forum is obsolete and read-only. Feel free to contact us at support.keenswh.com

How to easily switch between steam branches for modding

Discussion in 'Modding Guides and Tools' started by Gwindalmir, Jul 2, 2016.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Gwindalmir

    Gwindalmir Senior Engineer

    Messages:
    1,006
    Currently if you want to support multiple branches for your mods on Steam, you typically have to either constantly switch branches and redownload, backup/restore, or manage multiple steam installs.

    Here's, IMO, an easier way to do this:
    1. Start with a branch initially, we'll use Stable (default) as an example.
    2. Make sure stable branch is up to date.
    3. Go into Steam\SteamApps\common, and copy the SpaceEngineers directory.
    4. Rename the copy to SpaceEngineers.stable
    5. Go up a level to SteamApps
    6. Create a copy of appmanifest_244850.acf
    7. Rename that copy to appmanifest_244850.acf.stable
    8. In Steam, go back and switch to the other branch (development)
    9. Once updated, EXIT STEAM
    10. Rename the SpaceEngineers directory to SpaceEngineers.dev (do not copy)
    11. Rename the appmanifest_244850.acf to appmanifest_244850.acf.dev (do not copy)
    12. Now you have both branches ready. Continue below to see how to switch
    To switch between the two branches at this point, I have two batch scripts I use.
    Steam must not be running. I recommend exiting steam completely (don't just close the window).
    My scripts will kill steam if it's still running, but I recommend exiting safely.
    1. Exit Steam, or let script kill it
    2. If you are on Stable, and want to switch to development, run switchtodev.bat
    3. If you are on development, and want to switch to Stable, run switchtostable.bat
    4. Relaunch steam (if the batch script doesn't for you).
    Both versions of the game will continue to stay up to date automatically as you switch back and forth. So no need to worry about that.
    There's a lot more this could do (like automatic branch detection), but for simplicity, I didn't go down that route. You are welcome to do that.

    Place both of the following files in Steam\SteamApps\common

    switchtostable.bat:
    Code:
    @echo off
    setlocal
    set BRANCH=stable
    taskkill /t /f /im steam.exe 2>NUL
    taskkill /t /f /im SpaceEngineers.exe 2>NUL
    taskkill /t /f /im SpaceEngineersDedicated.exe 2>NUL
    rmdir SpaceEngineers
    mklink /j SpaceEngineers SpaceEngineers.%BRANCH%
    :: Swap the steam manifest
    del ..\appmanifest_244850.acf
    mklink /h ..\appmanifest_244850.acf ..\appmanifest_244850.acf.%BRANCH%
    :: Uncomment/comment the following line to toggle autostart steam
    start "" "%ProgramFiles(x86)%\Steam\Steam.exe"
    
    switchtodev.bat:
    Code:
    @echo off
    setlocal
    set BRANCH=dev
    taskkill /t /f /im steam.exe 2>NUL
    taskkill /t /f /im SpaceEngineers.exe 2>NUL
    taskkill /t /f /im SpaceEngineersDedicated.exe 2>NUL
    rmdir SpaceEngineers
    mklink /j SpaceEngineers SpaceEngineers.%BRANCH%
    :: Swap the steam manifest
    del ..\appmanifest_244850.acf
    mklink /h ..\appmanifest_244850.acf ..\appmanifest_244850.acf.%BRANCH%
    :: Uncomment/comment the following line to toggle autostart steam
    start "" "%ProgramFiles(x86)%\Steam\Steam.exe"
    
    A keen eye will notice the two scripts are identical, except for the set BRANCH= on line 3. Just change the part after the equals sign to match the extension you chose above.

    To keep this system flexible, this uses junctions and hardlinks in Windows. The technical details don't matter, all you need to do is create more directories, appmanifest and batch scripts if you want to enable more branches (eg. dx9), following this same pattern.

    EDIT: 30 Aug 2016, Changed batch scripts to use mklink.
     
    Last edited: Nov 2, 2016
    • Like Like x 4
    • Informative Informative x 2
  2. nukeguard

    nukeguard Trainee Engineer

    Messages:
    93
    I like this, very helpful!
     
    • Like Like x 1
  3. Digi

    Digi Senior Engineer

    Messages:
    2,393
    Here's my version that can be customized for any number of branches, there might be issues as I don't have too much experience with batch, so have some version indicators inside the folders in case something gets renamed wrong and backup your ACF files.

    Similar setup, just suffix the folders and .acf files with an underline and the branch names in the array (example: _STABLE, _DEV, etc), then place the script in the common folder under a .bat name.
    It's configured with STABLE, DEV and DX9 as an example, you can add, remove and rename any branch you want by editing the script at the top, there are comments where you need to do that.
    The script will save an empty file with the branch name and the .branch extension, the file doesn't do anything but indicate to the script which branch was last selected so it can rename the SE folder and ACF file back to their suffix.

    EDIT 24 july 2016:
    Updated the below code, it now properly blocks the execution if the folder is in use.

    Code:
    @echo off
    setlocal enabledelayedexpansion
    
    :: the branch names used in the suffixes
    set BRANCHES=(STABLE DEVELOPMENT DX9)
    
    :: the numbers used in the choices, should match the branches
    set CHOICES="123"
    
    :: 1 or 0 to start or not to start Steam
    set STARTSTEAM=1
    
    pause
    
    taskkill /f /im SpaceEngineers.exe
    taskkill /f /im Steam.exe
    cls
    
    
    for %%i in %BRANCHES% do (
      if EXIST %%i.branch (
        echo Found "%%i.branch", renaming things back...
        ren SpaceEngineers SpaceEngineers_%%i && (
          rem Command succesful.
        ) || (
          echo ERROR: Renaming "SpaceEngineers" to "SpaceEngineers_%%i" failed!
          pause
          goto:eof
        )
        cd ..
        ren appmanifest_244850.acf appmanifest_244850.acf_%%i && (
          rem Command succesful.
        ) || (
          echo ERROR: Renaming "appmanifest_244850.acf" to "appmanifest_244850.acf_%%i" failed!
          pause
          goto:eof
        )
        cd common
        del %%i.branch && (
          echo Done, "%%i.branch" file deleted.
        ) || (
          echo ERROR: Deleting "%%i.branch" failed!
          pause
          goto:eof
        )
      )
    )
    goto Menu
    
    
    :Menu
    echo.
    set /A COUNT=0
    for %%i in %BRANCHES% do (
      set /A COUNT+=1
      echo !COUNT! %%i
    )
    echo.
    choice /C %CHOICES% /N /M "Choose branch: "
    echo.
    set BRANCH=""
    set /A COUNT=0
    for %%i in %BRANCHES% do (
      set /A COUNT+=1
      if ERRORLEVEL !COUNT! set BRANCH=%%i
    )
    if not %BRANCH%=="" (
      echo Picked %BRANCH% branch, renaming things...
      ren SpaceEngineers_%BRANCH% SpaceEngineers && (
        rem Command succesful.
      ) || (
        echo ERROR: Renaming "SpaceEngineers_%BRANCH%" to "SpaceEngineers" failed!
        pause
        goto:eof
      )
      cd ..
      ren appmanifest_244850.acf_%BRANCH% appmanifest_244850.acf && (
        rem Command succesful.
      ) || (
        echo ERROR: Renaming "appmanifest_244850.acf_%BRANCH%" to "appmanifest_244850.acf" failed!
        pause
        goto:eof
      )
      cd common
      echo "" >> %BRANCH%.branch && (
        echo Created "%BRANCH%.branch" file.
      ) || (
        echo ERROR: Failed to create "%BRANCH%.branch" file!
        pause
        goto:eof
      )
      if %STARTSTEAM%==1 (
        echo Starting Steam...
        start ..\..\Steam.exe
      )
      echo All done.
    ) else (
      echo No branch selected!
      pause
    )
    
     
    Last edited: Jul 24, 2016
  4. Gwindalmir

    Gwindalmir Senior Engineer

    Messages:
    1,006
    Just FYI, you can use goto :EOF to exit the current scope.
    For the main batch script, this exits.
    For a batch 'sub' (label section), it exits the label and returns context to where you previously were.

    https://ss64.com/nt/goto.html

    Also, if you don't copy the active .acf to the backup regularly, the steam update will be out of sync. This will cause steam to continuously redownload the update when you switch.
     
    Last edited: Jul 3, 2016
  5. Hexxus

    Hexxus Trainee Engineer

    Messages:
    1
    This isn't working for me, assist?
     
  6. lilbigmouth

    lilbigmouth Trainee Engineer

    Messages:
    29
    Thanks so much Phoenix, this is going to make my SE playing life a whole lot easier!
     
  7. Gwindalmir

    Gwindalmir Senior Engineer

    Messages:
    1,006
    I just updated the steps yesterday. Try again.
     
  8. theimmersion

    theimmersion Trainee Engineer

    Messages:
    11
    Genius! I used copy paste techniques a lot but i never came to the idea to make a simple bat script to switch rather than go and rename folders every time. :woot:DDD
    This will come in handy for any game or program for that matter. THANKS!
     
  9. gordon861

    gordon861 Apprentice Engineer

    Messages:
    131
    Found this thanks to a post in Xocliw Twitch stream, very useful, thanks.
     
Thread Status:
This last post in this thread was made more than 31 days old.