-
Notifications
You must be signed in to change notification settings - Fork 0
/
unpack-all.ps1
101 lines (98 loc) · 2.81 KB
/
unpack-all.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
param(
# Path to Touhou data file
[Parameter(
Mandatory = $true,
Position = 0,
HelpMessage = "Path to data file")]
[ValidateNotNullOrEmpty()]
[string]
$File,
# Touhou version
[Parameter(
Mandatory = $true,
Position = 0,
HelpMessage = "Touhou version")]
[ValidateNotNullOrEmpty()]
[string]
$Version,
# Destination folder
[Parameter(
Mandatory = $true,
Position = 0,
HelpMessage = "Unpack folder. Empty = create new folder")]
[AllowEmptyString()]
[string]
$UnpackLocation
)
function resolve_conflict_between_anms {
param(
[Parameter(Position = 0)]
[string] $Version,
[Parameter(Position = 0)]
[string] $ConflictingAnm
)
. ("$PSScriptRoot/conflicting-files.ps1")
if ($conflicting_files[$Version].ContainsKey($ConflictingAnm)) {
$conflicting_file = $conflicting_files[$Version][$ConflictingAnm]
Write-Host "Resolving conflict on $conflicting_file"
$new_file_name = $(Split-Path $conflicting_file -LeafBase) `
+ " ($ConflictingAnm)" `
+ $(Split-Path $conflicting_file -Extension)
Remove-Item $($(Split-Path $conflicting_file -Parent) + "/" + $new_file_name)
Rename-Item $conflicting_file $new_file_name
}
}
if (".dat" -ne (Split-Path $File -Extension)) {
Write-Error "unpack-all can only be used with .dat files"
}
if ("" -eq $UnpackLocation) {
$UnpackLocation = (Split-Path $File -Parent) `
+ '\' `
+ (Split-Path $File -LeafBase)
$UnpackLocation = $UnpackLocation.Trim('\')
}
$previous_location = (Get-Location).Path
New-Item $UnpackLocation -ItemType Directory -Force | Out-Null
& "$PSScriptRoot/unpack.ps1" `
-UnpackMode "dat" `
-File $File `
-Version $Version `
-UnpackLocation $UnpackLocation
Set-Location $UnpackLocation
$file_filter_pattern = @{
"ecl" = "*.ecl"
"msg" = "st*.msg"
"msg_ending" = "e*.msg"
"std" = "*.std"
}
$anms = Get-ChildItem `
-File `
-Filter "*.anm" `
-Name
foreach ($anm in $anms) {
& "$PSScriptRoot/unpack.ps1" `
-UnpackMode "anm" `
-File $anm `
-Version $Version `
-UnpackLocation "." `
-ListUnpacked "anm spec file/$anm.txt"
resolve_conflict_between_anms `
-Version $Version `
-ConflictingAnm $anm
Remove-Item $anm
}
foreach ($file_type in "ecl", "msg", "msg_ending") {
$files = Get-ChildItem `
-File `
-Filter $file_filter_pattern[$file_type] `
-Exclude "staff*.msg" `
-Name
foreach ($file in $files) {
& "$PSScriptRoot\dump.ps1" `
-DumpMode $file_type `
-File $file `
-Version $Version `
-OutputFile ""
}
}
Set-Location $previous_location