-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunpack.ps1
122 lines (117 loc) · 3.1 KB
/
unpack.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
param(
# Extraction mode: anm, dat
[Parameter(
Mandatory = $true,
Position = 0,
HelpMessage = "Unpack mode: anm, dat")]
[ValidateNotNullOrEmpty()]
[string]
$UnpackMode,
# Path to Touhou data file
[Parameter(
Mandatory = $true,
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 location. Empty = current directory")]
[AllowEmptyString()]
[string]
$UnpackLocation,
[AllowEmptyString()]
[string]
$ListUnpacked
)
function unpack_dat {
param(
[Parameter(Position = 0)]
[string] $File,
[Parameter(Position = 0)]
[string] $Version,
[Parameter(Position = 0)]
[string] $ListUnpacked
)
& "thdat" -x $Version $File | Tee-Object $ListUnpacked
}
function unpack_anm {
param(
[Parameter(Position = 0)]
[string] $File,
[Parameter(Position = 0)]
[string] $Version,
[Parameter(Position = 0)]
[string] $ListUnpacked
)
. ("$PSScriptRoot/maplist.ps1")
& "thanm" -l $File -m $anmmaps[$Version] | Out-File $ListUnpacked
& "thanm" -x $File
}
function unpack {
param(
[Parameter(Position = 0)]
[string] $UnpackMode,
[Parameter(Position = 0)]
[string] $File,
[Parameter(Position = 0)]
[string] $Version,
[Parameter(Position = 0)]
[string] $UnpackLocation = "",
[Parameter(Position = 0)]
[string] $ListUnpacked = ""
)
$prev_path = $Env:Path
$thtk_dir = "$PSScriptRoot\thtk\bin"
if (-not (Test-Path $thtk_dir)) {
Write-Error "Cannot find thtk!" -ErrorAction Stop
}
$Env:Path += ";$thtk_dir"
if (-not (Test-Path $File)) {
Write-Error "Cannot find $File!" -ErrorAction Stop
}
$file_absolute = Resolve-Path $File
$previous_location = (Get-Location).Path
if ("" -ne $UnpackLocation) {
New-Item $UnpackLocation -ItemType Directory -Force | Out-Null
Set-Location $UnpackLocation
}
$file_name = Split-Path $File -Leaf
if ("" -eq $ListUnpacked) {
$ListUnpacked = $file_name + ".txt"
}
Write-Host "Unpacking: $file_name"
New-Item $ListUnpacked -Force | Out-Null
Switch ($UnpackMode) {
"dat" {
unpack_dat `
-File $file_absolute `
-Version $Version `
-ListUnpacked $ListUnpacked
}
"anm" {
unpack_anm `
-File $file_absolute `
-Version $Version `
-ListUnpacked $ListUnpacked
}
}
Set-Location $previous_location
$Env:Path = $prev_path
}
unpack `
-UnpackMode $UnpackMode `
-File $File `
-Version $Version `
-UnpackLocation $UnpackLocation `
-ListUnpacked $ListUnpacked