Advertisement
kerbo_

RUN8-backup.ps1

Feb 8th, 2022
633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # A simple PowerShell script to backup RUN 8 configs
  2. # Twitter: @Kerbo_
  3. #
  4.  
  5. # Change to your Run 8 path if not default
  6. $run8Dir = "C:\Run8Studios\Run8 Train Simulator V3"
  7.  
  8. #
  9. # No changes below here
  10. #
  11.  
  12. $ErrorActionPreference = 'SilentlyContinue'
  13. $dateString = $(get-date -f yyy-MM-dd_HH-mm)
  14. Push-Location $run8Dir
  15.  
  16. $configs = @(
  17.     "Content\RailDriverCalibration.r8"
  18.     "Content\Run8KeySettings.r8"
  19.     "Content\Run8Settings.r8"
  20.     "Content\V3RailVehicles\HornBellConfiguration.r8"
  21.     "Content\V3RailVehicles\UnitNumberDatabase.xml"
  22. )
  23.  
  24. $regionFiles = @(
  25.     "TrainSymbolRoutings.xml"
  26.     "Config.ind"
  27.     "Hump.r8"
  28.     "Traffic.r8"
  29.     "WX_Stations.txt"
  30. )
  31.  
  32. foreach ($config in $configs) {
  33.     $found = ""
  34.     try {
  35.         if(Test-Path -Path $config -PathType Leaf) {
  36.             $found = "True"
  37.         }
  38.     } catch {
  39.         # do nothing
  40.     }
  41.    
  42.     if($found) {
  43.         $config_hash = Get-FileHash $config
  44.         $backup = gci $config-* | select -last 1
  45.         $backup_hash = Get-FileHash $backup -EV Err -EA SilentlyContinue
  46.         if ( $backup_hash.Hash -eq $config_hash.Hash ) {
  47.             Write-Host "$config matches latest backup, no backup needed"
  48.         } else {
  49.             cp $config $config-$dateString
  50.             $RET=$?
  51.             if ($RET) {
  52.                 Write-Host "Copied $config to $config-$dateString"
  53.             } else {
  54.                 Write-Host "Error! cp returned $RET for $config"
  55.             }
  56.         }
  57.     }
  58. }
  59.  
  60. foreach ($regionFile in $regionFiles) {
  61.     $regionFilesFound = gci -Recurse $regionFile
  62.     if ( $regionFilesFound ) {
  63.         foreach ($config in $regionFilesFound) {
  64.             $config_hash = Get-FileHash $config
  65.             $backup = gci $config-* | select -last 1
  66.             $backup_hash = Get-FileHash $backup -EV Err -EA SilentlyContinue
  67.             if ( $backup_hash.Hash -eq $config_hash.Hash ) {
  68.                 Write-Host "$config matches latest backup, no backup needed"
  69.             } else {
  70.                 cp $config $config-$dateString
  71.                 $RET=$?
  72.                 if ($RET) {
  73.                     Write-Host "Copied $config to $config-$dateString"
  74.                 } else {
  75.                     Write-Host "Error! cp returned $RET for $config"
  76.                 }
  77.             }
  78.         }
  79.     }
  80. }
  81.  
  82. Pop-Location
  83. # Sleep to show screen output before exiting
  84. Start-Sleep -Seconds 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement