Advertisement
kerbo_

LocoSO-backup.ps1

Oct 3rd, 2022 (edited)
1,348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # A simple PowerShell script to backup Loco Shortline Operations single player save files
  2. # Twitter: @Kerbo_
  3.  
  4. # No changes needed below here
  5. $ErrorActionPreference = 'SilentlyContinue'
  6. $locoDir = $env:APPDATA + "\..\LocalLow\TSRS\Loco"
  7. $dateString = $(get-date -f yyy-MM-dd_HH-mm)
  8. Push-Location $locoDir
  9.  
  10. for ($i = 1; $i -le 6; $i++) {
  11.     $slotsav = Get-Item labstw$i.lab
  12.     $found = ""
  13.     try {
  14.         if(Test-Path -Path $slotsav -PathType Leaf) {
  15.             $found = "True"
  16.         }
  17.     } catch {
  18.         # do nothing
  19.     }
  20.    
  21.     if($found) {
  22.         $slotsav_hash = Get-FileHash $slotsav
  23.         $backup = gci labstw$i-* | select -last 1
  24.         $backup_hash = Get-FileHash $backup -EV Err -EA SilentlyContinue
  25.         if ( $backup_hash.Hash -eq $slotsav_hash.Hash ) {
  26.             Write-Host "labstw$i.lab matches latest backup, no backup needed" -ForegroundColor green
  27.         } else {
  28.             cp labstw$i.lab labstw$i-$dateString.lab
  29.             $RET=$?
  30.             if ($RET) {
  31.                 Write-Host "Copied labstw$i.lab to labstw$i-$dateString.lab" -ForegroundColor yellow
  32.             } else {
  33.                 Write-Host "Error! cp returned $RET for labstw$i.lab" -ForegroundColor red
  34.             }
  35.         }
  36.     }
  37. }
  38. Pop-Location
  39. Start-Sleep -Seconds 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement