Posted in Uncategorized

After an unfortunate incident involving a crash and a lost save file, I decided to write a batch script to automatically back up my Subnautica 2 saves every x number of minutes. You’ll need 7-Zip and PowerShell installed.

This script will check if Subnautica 2 is running, and if so, will zip the Subnautica save folder to whatever folder the script is located.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@echo off
 
:loop
 
rem Get HH:MM:SS for log prefix
FOR /F "tokens=* USEBACKQ" %%F IN (`powershell get-date -format ^"{HH:mm:ss}^"`) DO (
	SET logtime=%%F
)
 
rem Determine if subnautica is running
tasklist /fi "ImageName eq SubnauticaZero.exe" /fo csv 2>NUL | find /I "SubnauticaZero.exe">NUL
 
rem If subnautica is running...
if "%ERRORLEVEL%"=="0" (
 
	rem Get current datetime https://stackoverflow.com/a/2854857
	FOR /F "tokens=* USEBACKQ" %%F IN (`powershell get-date -format ^"{yyyy_MM_dd_HH_mm_ss}^"`) DO (
		SET mydatetime=%%F
	)
 
	rem Set up a folder name for our new backup
	SET stamp=slot0000-%mydatetime%.zip
 
	rem Back up with 7zip
	"C:\Program Files\7-Zip\7z.exe" a -tzip "%stamp%" "%USERPROFILE%\AppData\LocalLow\Unknown Worlds\Subnautica Below Zero\SubnauticaZero\SavedGames\slot0000" > NUL
 
	echo [%logtime%] Backed up to %stamp%
) else (
	echo [%logtime%] Not running...
)
 
rem sleep for 30 minutes https://stackoverflow.com/a/16803409
powershell -command "Start-Sleep -s 1800"
 
goto loop

To run the script simply save the above code into a file with a filename like backup.bat and double click it. Run it whenever you’re playing and close it when you’re done.

Read More »

Posted (Updated ) in Linux

Tonight I discovered I had an entire folder of dual audio MKV files with the wrong default language and wrong default subtitle track. I could have used mkvpropedit to manually change each file but that’s such a hassle. Instead, here’s a handy one-liner to do them all at once:

1
find . -name "*.mkv" -exec mkvpropedit {} --edit track:a1 --set flag-default=0 --edit track:a2 --set flag-default=1 --edit track:s1 --set flag-default=0 --edit track:s2 --set flag-default=1 \;

 

Explanation

At first glance they may look a bit complicated, but let’s break it down a bit:

Find all .mkvΒ files and execute an operation on them:

1
find . -name "*.mkv" -exec ... \;

Do an mkvpropeditΒ on the current matched file:

1
mkvpropedit {}

Set the first audio track to not be default, the second audio track to be default, and do the same with the subtitle tracks:

1
2
3
4
--edit track:a1 --set flag-default=0
--edit track:a2 --set flag-default=1
--edit track:s1 --set flag-default=0
--edit track:s2 --set flag-default=1

 

You’ll need mkvtoolnix installed for the mkvpropedit command. To determine what the various tracks contain, do a

1
mkvinfo /path/to/file.mkv

or mkvinfo -g for you GUI users πŸ™‚ This can be a bit tricky to read though so I tend to just open the file in VLC and look at the audio and video tracks that way.

As an added bonus, here’s the Windows equivalent of the above script:

1
2
3
4
5
6
7
8
9
@echo off
FOR /f "tokens=*" %%G IN ('dir /a-d /b') DO (
	mkvpropedit.exe "%%G" --edit track:2 --set flag-default=0
	mkvpropedit.exe "%%G" --edit track:3 --set flag-default=0
	mkvpropedit.exe "%%G" --edit track:4 --set flag-default=1
	mkvpropedit.exe "%%G" --edit track:5 --set flag-default=0
	echo.
)
pause

I’ve been told the Windows version works but haven’t tested personally.

Happy viewing!

Read More »