Add central function for creating backup

This commit is contained in:
Manuel Thalmann 2023-06-07 01:32:14 +02:00
parent a0bb4320d0
commit f6d0f9d594
4 changed files with 20 additions and 35 deletions

View file

@ -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;
}
}

View file

@ -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]);
}
}

View file

@ -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`""));
}

View file

@ -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`""));
}