Created
August 14, 2024 22:44
-
-
Save vttc08/f1918f290abc9769ec740bb9e2565cb9 to your computer and use it in GitHub Desktop.
Powershell Script Template for Backing Up Game Saves
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Global Configuration | |
$server=$(cat $HOME/gamesave) | |
# Common places | |
$documents = $([Environment]::GetFolderPath("MyDocuments")) | |
$downloads = $(New-Object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path | |
$desktop = $([Environment]::GetFolderPath("Desktop")) | |
$appdata = $env:appdata # Roaming | |
$localappdata = $env:localappdata # Local | |
# Game Configuration | |
$gamename = "kingdom_rush" | |
$gamepath = "$appdata/kingdom_rush" | |
# Menu | |
function menu { | |
Clear-Host | |
echo "Game save: $gamepath" "Path: $pwd" "Server: $server" | |
Write-Host "1. Backup (Save)" | |
Write-Host "2. Restore (Load)" | |
Write-Host "3. Transfer to server." | |
Write-Host "4. Load from server." | |
} | |
# Confirm function | |
function confirm { | |
$confirm = Read-Host "`nDoes this look right? Press Enter to continue or q to quit" | |
switch ($confirm) { | |
q { return $false } | |
default { return $true } | |
} | |
} | |
# Copy function | |
function cpy { | |
param ( $src, $dest ) | |
Clear-Host | |
echo "Source: $src `nDest: $dest`n" | |
echo "Generating robocopy report..." | |
robocopy $src $dest /MIR /L /NJH /NJS | |
if (confirm) { | |
robocopy $src $dest /MIR | |
} | |
else { | |
Write-Output "Nothing copied. Bye." | |
sleep 1 | |
} | |
} | |
# Save | |
function save { | |
Write-Host "Saving..." | |
cpy $gamepath ./saves | |
Write-Host "Saved!" | |
} | |
# Load | |
function load { | |
Write-Host "Loading..." | |
cpy ./saves $gamepath | |
Write-Host "Loaded!" | |
} | |
function save_server { | |
Write-Host "Saving to server..." | |
echo "Source: ./saves `nDest: $server/$gamename" | |
if (confirm) { | |
scp -r ./saves/* "$server/$gamename" | |
} | |
else { | |
Write-Output "Nothing copied. Bye." | |
sleep 1 | |
} | |
} | |
function load_server { | |
Write-Host "Loading from server..." | |
echo "Source: $server/$gamename `nDest: ./saves" | |
if (confirm) { | |
scp -r "$server/$gamename/*" ./saves | |
} | |
else { | |
Write-Output "Nothing copied. Bye." | |
sleep 1 | |
} | |
} | |
# Main | |
do { | |
menu | |
$option = Read-Host "Choose an option" | |
switch ($option) { | |
1 { save } | |
2 { load } | |
3 { save_server } | |
4 { load_server } | |
q { exit } | |
} | |
} until ( | |
$option -eq 'q' | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment