Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $SyncPath = "$env:USERPROFILE\Saved Games\FromSoftware" # The path your save files will be copied to, preferably Google Drive or something like that
- $CheckGameState = $true # Check if game is running before performing a backup?
- $IntervalInSeconds = 300 # How often to attempt a backup
- $NumberToKeep = 20 # Number of backups to keep
- function New-SaveFile([String]$Game, [String]$Version, [System.Array]$Process, [String]$Directory, [String]$File) {
- [PSCustomObject]@{
- Game = $Game
- Version = $Version
- Process = $Process
- Directory = $Directory
- File = $File
- }
- }
- # Custom objects representing each save file
- $SaveFiles = @(New-SaveFile `
- -Game "Dark Souls" `
- -Version "1" `
- -Process "DarkSouls","DarkSoulsRemastered" `
- -File "DRAKS0005.sl2" `
- -Directory "$env:USERPROFILE\Documents\NBGI\DARK SOULS REMASTERED\17627925")
- $SaveFiles += (New-SaveFile `
- -Game "Dark Souls" `
- -Version "2" `
- -Process "DarkSoulsII" `
- -File "DS2SOFS0000.sl2" `
- -Directory "$env:APPDATA\DarkSoulsII\01100001010cfb15")
- $SaveFiles += (New-SaveFile `
- -Game "Dark Souls" `
- -Version "3" `
- -Process "DarkSoulsIII" `
- -File "DS30000.sl2" `
- -Directory "$env:APPDATA\DarkSoulsIII\01100001010cfb15")
- If ($CheckGameState -eq $false) {$NumberToKeep *= 10} # If we are doing backups more frequently, allow more backups to be kept
- While (1) {
- ForEach ($SaveFile In $SaveFiles) {
- $FileName = $SaveFile.File
- $SourceFile = Get-Item -Path "$($SaveFile.Directory)\$FileName"
- If (Test-Path -Path $SourceFile) {
- $Game = $SaveFile.Game
- $Version = $SaveFile.Version
- $TargetDir = "$SyncPath\$Game\$Version"
- $OKToRun = ($CheckGameState -eq $false) -or ($null -eq (Get-Process -Name $SaveFile.Process -ErrorAction SilentlyContinue))
- If (!(Test-Path $TargetDir)) {
- New-Item -ItemType Directory -Force -Path $TargetDir
- }
- If ($OKToRun) {
- $LastBackup = Get-ChildItem -Path $TargetDir | Sort-Object LastWriteTime | Select-Object -Last 1
- If ($LastBackup.LastWriteTime -ne $SourceFile.LastWriteTime) {
- Copy-Item $SourceFile "$SyncPath\$Game\$Version\$FileName.$(Get-Date -f yyyy-MM-dd_HH-mm-ss)" -Force
- }
- While ((Get-ChildItem -Path $TargetDir).Count -gt $NumberToKeep) {
- Get-ChildItem -Path $TargetDir | Sort-Object LastWriteTime | Select-Object -First 1 | Remove-Item
- }
- }
- }
- }
- Start-Sleep -Seconds $IntervalInSeconds
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement