forked from EntranceJew/gmod-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremorse.ps1
75 lines (63 loc) · 1.77 KB
/
remorse.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
param ([string] $input_name)
$input_dest = ".\$input_name\"
$remorse_file = ".\remorse.$input_name.txt"
$remorse_dest = ".\ttt2_remorseful_repacks"
$remorse_ignore = ".\remorse_ignore.txt"
$remorse_ignore_data = Get-Content "$remorse_ignore"
function Make-PathThatMayNotExist {
param (
[string] $Path
)
$dir = Split-Path "$Path" -Parent
if(-Not (Test-Path -Path "$dir")) {
New-Item -Path "$dir" -ItemType Directory | Out-Null
}
}
function Remove-EmptyDirectories {
param (
[string] $Path
)
do {
$dirs = gci "$Path" -directory -recurse | Where { (gci $_.fullName -Force).count -eq 0 } | select -expandproperty FullName
$dirs | Foreach-Object { Remove-Item $_ | Out-Null }
} while ($dirs.count -gt 0)
}
function Check-IsRemorseIgnored {
param (
[string] $Path
)
$go = $True
foreach( $_ in $remorse_ignore_data ) {
# Write-Host "$line vs $_"
if ( "$line" -match "$_" ) {
$go = $False;
break;
}
}
return $go;
}
if (Test-Path "$remorse_file" -PathType Leaf) {
# if there is a remorse file, iterate it
Get-Content "$remorse_file" | % {
$line = "$_"
if ( Check-IsRemorseIgnored -Path "$line" ) {
Write-Host "removing hardlink: $line"
(Get-Item "$remorse_dest\$line").Delete()
}
}
# eradicate empty folders
Remove-EmptyDirectories -Path "$remorse_dest"
# remove the remorse file
(Get-Item "$remorse_file").Delete()
} else {
# if there is no remorse file for this name,
dir ".\$input_name\" -Recurse -Name -File | % {
$line = "$_"
if ( Check-IsRemorseIgnored -Path "$line" ) {
Write-Host "creating hardlink: $line"
Add-Content -Path "$remorse_file" -Value "$line" | Out-Null
Make-PathThatMayNotExist -Path "$remorse_dest\$line"
New-Item -Path "$remorse_dest\$line" -ItemType HardLink -Value ".\$input_name\$line" | Out-Null
}
}
}