-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsss.ps1
executable file
·71 lines (60 loc) · 2.08 KB
/
dsss.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
#
# Dark Souls Save Scummer
#
#
# NO WARRANTY WHATSOEVER
#
# https://github.com/Kaurin/DSSS
# Exit on any error
$ErrorActionPreference = "Stop"
$username = "$env:UserName"
$folder = "C:\Users\$username\Documents\NBGI\DarkSouls"
$filter = "*sl2"
#intro
Write-Host "
*****
***** Script detected this as your DarkSouls SAVES path:
***** $folder
*****
***** If this is not the case, try to replace `$env:UserName with
***** `$env:UserDomain or `$env:ComputerName in the script
*****"
function global:makeBackup($filePath)
{
$folder = Split-Path $filePath
$filename = Split-Path $filePath -Leaf
$datetime = $(get-date -f yyyy-MM-dd__HH-mm)
# This prevents file getting created more than 1 min, because our files have a 1-min resolution
if (! (Test-Path $folder\$datetime-$filename.dsbak))
{
Copy-Item $filePath "$folder\$datetime-$filename.dsbak"
Write-Host "$datetime - Backup made: $folder\$datetime-$filename.dsbak"
}
else { Write-Host "$datetime - Backup for this minute already exists. Not backing up" }
}
$watcher = New-Object -TypeName IO.FileSystemWatcher $folder, $filter -Property @{
IncludeSubdirectories = $false
EnableRaisingEvents = $true
}
$changeAction = [scriptblock]::Create('
# This is the code which will be executed every time a file change is detected
$path = $Event.SourceEventArgs.FullPath
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
# Write-Host "The file $name was $changeType at $timeStamp // $path / $name"
makeBackup $path
')
Register-ObjectEvent $Watcher "Changed" -Action $changeAction
# Infinite loop. We can clean up the "event catcher" on ctrl+c
# Notice we don't do any logic here. The background event listener does all the work
Write-Host
Write-Host "To exit, press CTL+C (a few times)"
Try {
While($True) {
Start-Sleep 3
}
} Finally {
Write-Host "goodbye!"
Get-EventSubscriber -Force | Unregister-Event -Force
}