From f6d0f9d5949b02e1683aec8dc9a62571ef856f74 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 7 Jun 2023 01:32:14 +0200 Subject: [PATCH] Add central function for creating backup --- scripts/Windows/Scripts/Context.ps1 | 17 +++++++++++++++++ scripts/Windows/Scripts/PersonalFiles.ps1 | 18 +----------------- .../TrackMania Nations Forever/Manage.ps1 | 10 +--------- .../TrackMania United Forever/Manage.ps1 | 10 +--------- 4 files changed, 20 insertions(+), 35 deletions(-) diff --git a/scripts/Windows/Scripts/Context.ps1 b/scripts/Windows/Scripts/Context.ps1 index f24c346c..6eb27cb2 100644 --- a/scripts/Windows/Scripts/Context.ps1 +++ b/scripts/Windows/Scripts/Context.ps1 @@ -15,4 +15,21 @@ class Context { [string] SoftwareArchive([string]$softwareName) { return $this.ArchivePath($softwareName); } + + [void] Backup([string]$sourcePath, [string]$archivePath, [string[]]$arguments) { + if (Test-Path $archivePath) { + Remove-Item -Recurse $archivePath; + } + + Start-Process -WorkingDirectory "$sourcePath" ` + -FilePath "7z" ` + -ArgumentList ( + @( + "a", + "-xr!desktop.ini", + "-xr!{t,T}humbs.db", + $archivePath) + $arguments) ` + -Wait ` + -NoNewWindow; + } } diff --git a/scripts/Windows/Scripts/PersonalFiles.ps1 b/scripts/Windows/Scripts/PersonalFiles.ps1 index 3dd9d790..8114ebde 100644 --- a/scripts/Windows/Scripts/PersonalFiles.ps1 +++ b/scripts/Windows/Scripts/PersonalFiles.ps1 @@ -13,22 +13,6 @@ function Get-BackupCandidates() { function Invoke-FileBackup([Context] $context) { foreach ($candidate in Get-BackupCandidates) { - $archiveName = $context.FileArchivePath($candidate[0]); - - if (Test-Path $archiveName) { - Remove-Item -Recurse $archiveName; - } - - Start-Process -WorkingDirectory $candidate[1] ` - -ArgumentList ( - @( - "a", - "-xr!desktop.ini", - "-xr!{t,T}humbs.db") + - $candidate[2] + - @($archiveName)) ` - -FilePath "7z" ` - -NoNewWindow ` - -Wait; + $context.Backup($candidate[1], $context.FileArchivePath($candidate[0]), $candidate[2]); } } diff --git a/scripts/Windows/Software/TrackMania Nations Forever/Manage.ps1 b/scripts/Windows/Software/TrackMania Nations Forever/Manage.ps1 index 89b84eab..6f70bc35 100644 --- a/scripts/Windows/Software/TrackMania Nations Forever/Manage.ps1 +++ b/scripts/Windows/Software/TrackMania Nations Forever/Manage.ps1 @@ -3,13 +3,5 @@ $path = "$HOME/Documents/TmForever"; $softwareName = "TmNationsForever"; function Invoke-BackupTmNations([Context] $context) { - Write-Host "$PSScriptRoot"; - Start-Process -WorkingDirectory "$path" ` - -FilePath "7z" ` - -ArgumentList @( - "a", - "-i@`"$PSScriptRoot/include.txt`"", - $context.SoftwareArchive($softwareName)) ` - -Wait ` - -NoNewWindow; + $context.Backup($path, $context.SoftwareArchive($softwareName), @("-i@`"$PSScriptRoot/include.txt`"")); } diff --git a/scripts/Windows/Software/TrackMania United Forever/Manage.ps1 b/scripts/Windows/Software/TrackMania United Forever/Manage.ps1 index 43f75709..c7e98b38 100644 --- a/scripts/Windows/Software/TrackMania United Forever/Manage.ps1 +++ b/scripts/Windows/Software/TrackMania United Forever/Manage.ps1 @@ -3,13 +3,5 @@ $path = "$HOME/Documents/TrackMania"; $softwareName = "TmUnitedForever"; function Invoke-BackupTmNations([Context] $context) { - Write-Host "$PSScriptRoot"; - Start-Process -WorkingDirectory "$path" ` - -FilePath "7z" ` - -ArgumentList @( - "a", - "-i@`"$PSScriptRoot/include.txt`"", - $context.SoftwareArchive($softwareName)) ` - -Wait ` - -NoNewWindow; + $context.Backup($path, $context.SoftwareArchive($softwareName), @("-i@`"$PSScriptRoot/include.txt`"")); }