Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $SyncPath = "$env:USERPROFILE\Saved Games\FromSoftware"     # The path your save files will be copied to, preferably Google Drive or something like that
  2. $CheckGameState = $true                                     # Check if game is running before performing a backup?
  3. $IntervalInSeconds = 300                                    # How often to attempt a backup
  4. $NumberToKeep = 20                                          # Number of backups to keep
  5.  
  6. function New-SaveFile([String]$Game, [String]$Version, [System.Array]$Process, [String]$Directory, [String]$File) {
  7.     [PSCustomObject]@{
  8.         Game = $Game
  9.         Version = $Version
  10.         Process = $Process
  11.         Directory = $Directory
  12.         File = $File
  13.     }
  14. }
  15.  
  16. # Custom objects representing each save file
  17. $SaveFiles = @(New-SaveFile `
  18.                 -Game "Dark Souls" `
  19.                 -Version "1" `
  20.                 -Process "DarkSouls","DarkSoulsRemastered" `
  21.                 -File "DRAKS0005.sl2" `
  22.                 -Directory "$env:USERPROFILE\Documents\NBGI\DARK SOULS REMASTERED\17627925")
  23. $SaveFiles += (New-SaveFile `
  24.                 -Game "Dark Souls" `
  25.                 -Version "2" `
  26.                 -Process "DarkSoulsII" `
  27.                 -File "DS2SOFS0000.sl2" `
  28.                 -Directory "$env:APPDATA\DarkSoulsII\01100001010cfb15")
  29. $SaveFiles += (New-SaveFile `
  30.                 -Game "Dark Souls" `
  31.                 -Version "3" `
  32.                 -Process "DarkSoulsIII" `
  33.                 -File "DS30000.sl2" `
  34.                 -Directory "$env:APPDATA\DarkSoulsIII\01100001010cfb15")
  35.  
  36. If ($CheckGameState -eq $false) {$NumberToKeep *= 10}       # If we are doing backups more frequently, allow more backups to be kept
  37.  
  38. While (1) {
  39.  
  40.     ForEach ($SaveFile In $SaveFiles) {
  41.        
  42.         $FileName = $SaveFile.File
  43.         $SourceFile = Get-Item -Path "$($SaveFile.Directory)\$FileName"
  44.        
  45.         If (Test-Path -Path $SourceFile) {
  46.  
  47.             $Game = $SaveFile.Game
  48.             $Version = $SaveFile.Version
  49.             $TargetDir = "$SyncPath\$Game\$Version"
  50.  
  51.             $OKToRun = ($CheckGameState -eq $false) -or ($null -eq (Get-Process -Name $SaveFile.Process -ErrorAction SilentlyContinue))
  52.            
  53.             If (!(Test-Path $TargetDir)) {
  54.                 New-Item -ItemType Directory -Force -Path $TargetDir
  55.             }
  56.  
  57.             If ($OKToRun) {
  58.                 $LastBackup = Get-ChildItem -Path $TargetDir | Sort-Object LastWriteTime | Select-Object -Last 1
  59.                 If ($LastBackup.LastWriteTime -ne $SourceFile.LastWriteTime) {
  60.                     Copy-Item $SourceFile "$SyncPath\$Game\$Version\$FileName.$(Get-Date -f yyyy-MM-dd_HH-mm-ss)" -Force
  61.                 }
  62.            
  63.                 While ((Get-ChildItem -Path $TargetDir).Count -gt $NumberToKeep) {
  64.                     Get-ChildItem -Path $TargetDir | Sort-Object LastWriteTime | Select-Object -First 1 | Remove-Item
  65.                 }  
  66.             }  
  67.         }
  68.     }
  69.  
  70.     Start-Sleep -Seconds $IntervalInSeconds
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement