-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.ps1
101 lines (87 loc) · 3.08 KB
/
script.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
90
91
92
93
94
95
96
97
98
99
100
101
# Clear garbage
Clear-Host
# Username crap
$username = $env:USERNAME
$profilePath = (Get-ChildItem "C:\Users\" -Filter $username).FullName
# Paths
$documentsPath = [Environment]::GetFolderPath('MyDocuments')
$savePath = $profilePath + '\AppData\Roaming\DIVA'
$segaPath = $profilePath + '\AppData\Roaming\SEGA'
$backPath = $documentsPath + '\DivaBackups'
$steamPath = "C:\Program Files (x86)\Steam\steam.exe"
# Game properties
$gameId = "1761390"
$gameExe = "DivaMegaMix"
# Filename
$datetime = get-date -Format "dd.MM.yy-HHmm"
$filename = "DIVA_" + $datetime + ".7z"
# For script shenanigans
$trackingMessageDisplayed = 0
$sevenZipUrl = "https://www.7-zip.org/"
# Message
Write-Output " _____ _ _ ____ _ "
Write-Output " | __ \(_) /\ | | | _ \ | | "
Write-Output " | | | |___ ____ _ / \ _ _| |_ ___ | |_) | __ _ ___| | ___ _ _ __ "
Write-Output " | | | | \ \ / / _\` | / /\ \| | | | __/ _ \ | _ < / _\` |/ __| |/ / | | | '_ \ "
Write-Output " | |__| | |\ V / (_| | / ____ \ |_| | || (_) | | |_) | (_| | (__| <| |_| | |_) |"
Write-Output " |_____/|_| \_/ \__,_| /_/ \_\__,_|\__\___/ |____/ \__,_|\___|_|\_\\__,_| .__/ "
Write-Output " | | "
Write-Output " |_| "
Write-Output " v1.0.1 by rin "
# Launch DIVA
Write-Host "Starting DIVA..."
Start-Process -FilePath $steamPath -ArgumentList "-applaunch $gameId"
# Try to find DIVA process
Write-Host "Looking for DIVA..."
do{
$gameProcess = Get-Process | Where-Object {$_.ProcessName -eq $gameExe}
}until($null -ne $gameProcess)
# Track DIVA every second until it closes
do{
if($trackingMessageDisplayed -eq 0){
Write-Host "Tracking DIVA..."
$trackingMessageDisplayed = 1
}
Start-Sleep -Milliseconds 1000
}until($gameProcess.HasExited)
# Make sure process is null after DIVA closes
$gameProcess = Get-Process | Where-Object {$_.ProcessName -eq $gameExe}
function exitMessage{
Write-Output " "
Write-Output "Thank you for using DivaAutoBackup."
Start-Sleep -Seconds 5
exit
}
function doBackup{
# Anti-dummy
if((Test-Path $segaPath) -and (Test-Path $savePath)){
Write-Host "Creating offline save backup..."
}elseif(Test-Path $segaPath){
$savePath = $segaPath
Write-Host "Offline save not found. Backing up default SEGA folder instead."
}else{
Write-Host "No saves where found. Exiting."
exitMessage
}
# Anti-dummy 2
if(Test-Path "C:\Program Files\7-Zip"){
# Do backup
C:\'Program Files'\7-Zip\7z.exe -bso0 a temp.7z $savePath
Rename-Item temp.7z $filename
Move-Item *.7z $backPath
exitMessage
}else{
Write-Host "You don't have 7-Zip. Install it for divaAutoBackup to work."
Start-Process $sevenZipUrl
exitMessage
}
}
# Backup save
if($null -eq $gameProcess){
if(Test-Path $backPath){
doBackup
}else{
New-Item -ItemType Directory -Path $backPath
doBackup
}
}