-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup_memorycards.ps1
89 lines (76 loc) · 2.4 KB
/
backup_memorycards.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
[CmdletBinding()]
param (
[Parameter()]
[switch]
$scheduled
)
# load function file
. "$PSScriptRoot\functions.ps1"
#Path to configuration file
$pathtocfg = Join-Path -Path $PSScriptRoot -ChildPath "config/configuration.cfg"
# Check if the configuration file exists if not create it in the correct format
if (Test-Path $pathtocfg -PathType Leaf) {
# Load the XML file
$emulatorxml = New-Object System.Xml.XmlDocument
$emulatorxml.Load($pathtocfg)
} else {
# Ask for backup location
try {
Add-Type -AssemblyName System.Windows.Forms
$backuplocation = New-Object -Typename System.Windows.Forms.FolderBrowserDialog
$null = $backuplocation.ShowDialog() # Suppress output by redirecting to $null
$backuplocation = $backuplocation.SelectedPath
}
catch {
<#Do this if a terminating exception happens#>
$backuplocation = read-host -prompt "Enter a location to save the emulator"
}
# Create basic configuration file
$emulatorxml = new-scriptcfg -pathtocfg $pathtocfg -pathtobackup ($backuplocation)
$emulatorxml = New-Object System.Xml.XmlDocument
$emulatorxml.Load($pathtocfg)
}
if (!($PSBoundParameters.ContainsKey('scheduled'))) {
# Loop until the user exits
while ($true) {
# Display the menu
#Clear-Host
Write-Host -ForegroundColor Yellow "
Please select option:
1. Backup saves
2. Restore saves
3. Add Emulator
4. Remove Emulator
5. Show Emulators
6. Update Backup path
7. Exit
"
switch ([System.Console]::ReadKey($true).KeyChar) {
1 {
Backup-EmulatorSaves -xmlDoc $emulatorxml -backup
}
2 {
Backup-EmulatorSaves -xmlDoc $emulatorxml -restore
}
3 {
add-emulator -xmlDoc $emulatorxml
}
4 {
remove-emulator -xmlDoc $emulatorxml
}
5 {
show-emulators -xmlDoc $emulatorxml
}
6 {
Update-scriptcfg -xmlDoc $emulatorxml
}
7 {
exit
}
}
# Save the changes to the XML file
$emulatorxml.Save($pathtocfg)
}
} else {
Backup-EmulatorSaves -xmlDoc $emulatorxml -backup -force
}