Jump to content

rotate saves every 10 minutes


Recommended Posts

hi everyone

I think that might be of any help for anyone experiencing constant crashes like i do.

I created a quick batch to be launched BEFORE launching KSP, and it saves your game every 10 minutes, rolling on 6 files. So at any point, you have 1 hour back with 6 save points.

In the past, I used to date the savegames, but honestly, when in life have you reloaded a 3 weeks old savegame?

PRE-REQUISITES:

0) this is for Windows. Linux users are smart enough, in general, to code that by themselves.

1) 7zip http://www.7-zip.org/

2) GNU sleep.exe http://gnuwin32.sourceforge.net/downlinks/coreutils-bin-zip.php

3) optional: pslist.exe https://technet.microsoft.com/en-us/sysinternals/bb896682.aspx

a) Install 7zip if you don't have it yet

B) then get sleep.exe from the link above and put it in the same directory that contains your savegames

c) optionally, get pslist.exe from the link above and put it in the same directory that contains your savegames

d) finally, adapt the paths inside the batch file bellow (call it looSave.cmd or whatever), that you will save in the same directory that contains your savegames

- get the savegames ordered by TIME

- after a crash, just get the N-1, or 2 or whatever number you need to get back before the launch that crashed your game.

hope that can help someone :wink:

:: loop saving system every 10 minutes for KSP by ScavengeR(c)
@echo off

rem put your 7z.exe full path bellow if it is not in your %PATH% variable:
set SEVENzip=7z.exe
rem adapt the full path to your save dir:
set SAVEDIR=G:\GAMES\KSP_win_1.0.2\saves
rem adapt the name of your zip files if you want too:
set KSPLoopSave=KSPLoopSave
::-----------------

pushd %~dp0
goto :loop
goto :END

:loop
set CURRENTMIN=%TIME:~3,1%
echo %TIME% saving %~dp0%KSPLoopSave%_%CURRENTMIN%.zip ...
%SEVENzip% a -bd -y %~dp0%KSPLoopSave%_%CURRENTMIN%.zip %SAVEDIR% >NUL
echo %TIME% saving %~dp0%KSPLoopSave%_%CURRENTMIN%.zip ...OK
sleep 600

rem if you want, comment the line bellow, that test if KSP is still running.
rem You then will have to close the DOS window manually:
pslist KSP
::---------
if %ERRORLEVEL% EQU 0 goto :loop
goto :EOF

:END
exit

edit: About Linux, hum, please Windows users do not misinterpret my words. And for anyone under Linux asking for, I will write the same shell with bash if u want ;)

Edited by scavenger
wrong title
Link to comment
Share on other sites

thank you, and as I said if that can be of any use to anyone, I am happy to share.

bellow is another version that uses current hours too, that makes 24 * 6 = 144 possible rotating saves. I had to do that because of a mission that lasted 3 hours. Going one hour back was not enough.

:: loop saving system every 10 minutes every hours for KSP by ScavengeR(c)
:: it generates at most 24 * 6 = 144 rotating savegames
:: This batch to be placed in the directory that holds the generated save zip files.
@echo off

rem put your 7z.exe full path bellow if it is not in your %PATH% variable:
set SEVENzip=7z.exe
rem adapt the full path to your installed game main saves directory:
set SAVEDIR=G:\GAMES\KSP_win_1.0.2\saves
rem adapt the name of your zip files if you want too:
set KSPLoopSave=KSPLoopSave
::-----------------

pushd %~dp0
goto :loop
goto :END

:loop
set CURRENTH=%TIME:~0,2%
set CURRENTMIN=%TIME:~3,1%
set LastShip=
:: get the last modified player name:
for /f "delims=" %%L in ('dir /b /od %SAVEDIR%') do set LastPlayer=%%L
:: get the last modified ship, with underscore in front.
for /f "delims=" %%L in ('dir /b /od %SAVEDIR%\%LastPlayer%\Ships\VAB ^| findstr /p /v Auto-Saved') do set LastShip=_%%L

:: delete same time savegame since the name can be different each time:
if EXIST "%~dp0%KSPLoopSave%_%CURRENTH%%CURRENTMIN%0_*.zip" del /q "%~dp0%KSPLoopSave%_%CURRENTH%%CURRENTMIN%0_*.zip"

echo %TIME% saving "%~dp0%KSPLoopSave%_%CURRENTH%%CURRENTMIN%0%LastShip%.zip" ...
%SEVENzip% a -bd -y "%~dp0%KSPLoopSave%_%CURRENTH%%CURRENTMIN%0%LastShip%.zip" %SAVEDIR% >NUL
echo %TIME% saving "%~dp0%KSPLoopSave%_%CURRENTH%%CURRENTMIN%0%LastShip%.zip" ...OK
sleep 600

rem if you want, comment the line bellow, that test if KSP is still running.
rem You then will have to close the DOS window manually:
pslist KSP >NUL 2>&1
::---------
if %ERRORLEVEL% EQU 0 goto :loop
goto :EOF

:END
exit

edit: i added the last modified ship name to the zip files so you can recognize easily what you were doing at that time ;)

Edited by scavenger
Link to comment
Share on other sites

  • 4 weeks later...

Here is the latest version. It still uses the timely fashion to order the saves but there is no relationship with the time anymore.

This version does 24 * 6 = 144 rotate saves or more, as you can customize the sleep between savegames.

This version also name the saves according to the last player used, and last ship name edited.

P4Z6Bi4.png

:: loop saving system every 10 minutes every hours for KSP by ScavengeR(c)
:: it generates at most 24 * 6 = 144 rotating savegames
:: This batch to be placed in the directory that holds the generated save zip files.
@echo off
MODE 120,30

rem put your 7z.exe full path bellow if it is not in your %PATH% variable:
set SEVENzip=7z.exe
rem set extention: 7z compress KSP saves usually like 5 times more than zip
set ext=7z
rem adapt the full path to your installed game main saves directory:
set SAVEDIR=G:\GAMES\KSP_win_1.0.2\saves
rem adapt the name of your zip files if you want too:
set KSPLoopSave=KSPLoopSave
rem set the time in minutes between saves:
set minutes=10
::-----------------
set /A seconds=minutes*60
set /A maxMin=60-minutes

pushd %~dp0
call :getLastSaveNum %KSPLoopSave%
goto :loopsave
goto :END

:getLastSaveNum
for /f "tokens=2 delims=_" %%a in ('dir /b /o-d %1_*.%ext%') do if not defined lastSaveNum set lastSaveNum=%%a
goto :EOF

:getLastNames
set LastPlaceName=
set LastShipName=
:: get the last modified player name:
for /f "delims=" %%L in ('dir /b /od %SAVEDIR%') do set LastPlayer=%%L
:: get the last place whre are modified ships
for /f "delims=" %%L in ('dir /b /od %SAVEDIR%\%LastPlayer%\Ships') do set LastPlaceName=%%L
:: get the last modified ship name
for /f "delims=" %%L in ('dir /b /od %SAVEDIR%\%LastPlayer%\Ships\%LastPlaceName% ^| findstr /p /v Auto-Saved') do set LastShipName=%%L
goto :EOF

:getSaveNum
set lastSaveNum=%1
set H=%lastSaveNum:~0,2%
rem INFO: To get hours that are less than 10. MSDOS treat numbers that begin by 0 as just 0
rem INFO: We could use "if %H% LSS 10 echo ok" but we don't know if later one day Microsoft will change the "if" behavior
if %H:~0,1% == 0 set H=%H:~1,1%

set M=%lastSaveNum:~2,2%
if %M% GEQ %maxMin% (
set M=00
set /A H+=1
) ELSE (
set /A M+=minutes
)
if %H% GTR 23 set H=0
if %H% LSS 10 set H=0%H%
set saveNum=%H%%M%
goto :EOF

:loopsave
call :getLastNames
call :getSaveNum %lastSaveNum%
echo LastShipName=%LastShipName%
echo lastSaveNum=%lastSaveNum%
echo saveNum=%saveNum%

:: delete same time savegame since the name can be different each time:
if EXIST "%~dp0%KSPLoopSave%_%saveNum%_*.%ext%" del /q "%~dp0%KSPLoopSave%_%saveNum%_*.%ext%"

echo %TIME% saving "%~dp0%KSPLoopSave%_%saveNum%_%LastPlayer%-%LastPlaceName%-%LastShipName%.%ext%" ...
%SEVENzip% a -bd -y "%~dp0%KSPLoopSave%_%saveNum%_%LastPlayer%-%LastPlaceName%-%LastShipName%.%ext%" %SAVEDIR% >NUL
echo %TIME% saving "%~dp0%KSPLoopSave%_%saveNum%_%LastPlayer%-%LastPlaceName%-%LastShipName%.%ext%" ...OK
set lastSaveNum=%saveNum%
sleep %seconds%

rem if you want, comment the line bellow, that test if KSP is still running.
rem You then will have to close the DOS window manually:
pslist KSP >NUL 2>&1
::---------
if %ERRORLEVEL% EQU 0 goto :loopsave
goto :EOF

:END
exit

Link to comment
Share on other sites

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...