-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathundump.ps1
77 lines (75 loc) · 2.17 KB
/
undump.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
param(
[Parameter(
Mandatory = $true,
Position = 0,
HelpMessage = "File format: ecl, msg, msg_ending, std")]
[ValidateNotNullOrEmpty()]
[string]
$FileType,
[Parameter(
Mandatory = $true,
Position = 0,
HelpMessage = "Input file")]
[ValidateNotNullOrEmpty()]
[string]
$File,
[Parameter(
Mandatory = $true,
Position = 0,
HelpMessage = "Touhou version")]
[ValidateNotNullOrEmpty()]
[string]
$Version,
[Parameter(
Mandatory = $true,
Position = 0,
HelpMessage = "Output file")]
[ValidateNotNullOrEmpty()]
[string]
$OutputFile
)
function undump {
param (
[Parameter(Position = 0)]
[string] $FileType,
[Parameter(Position = 0)]
[string] $File,
[Parameter(Position = 0)]
[string] $Version,
[Parameter(Position = 0)]
[string] $OutputFile
)
. ("$PSScriptRoot/maplist.ps1")
$prev_path = $Env:Path
$thtk_dir = "$PSScriptRoot\thtk\bin"
if (-not (Test-Path $thtk_dir)) {
Write-Error "Cannot find thtk!" -ErrorAction Stop
}
$UndumpCommand = @{
"ecl" = "thecl.exe -c {0} `"{1}`" `"{2}`" -m `"{3}`""
"msg" = "thmsg.exe -c {0} `"{1}`" `"{2}`""
"msg_ending" = "thmsg.exe -e -c {0} `"{1}`" `"{2}`""
"std" = "thstd.exe -c {0} `"{1}`" `"{2}`""
}
$Env:Path += ";$thtk_dir"
if (-not (Test-Path $File)) {
Write-Error "Cannot find $File!" -ErrorAction Stop
}
$eclmap_file_path = $eclmaps[$Version]
$eclmap_name = Split-Path -LeafBase $eclmap_file_path
$file_name = Split-Path $File -Leaf
$output_file_name = Split-Path $OutputFile -Leaf
$expression = $UndumpCommand[$FileType] -f $Version, $File, $OutputFile, $eclmap_file_path
Write-Host -NoNewLine "Creating: $file_name --> $output_file_name "
if ("ecl" -eq $FileType) {
Write-Host -NoNewline ("using ecl map " + $eclmap_name)
}
Write-Host ""
Invoke-Expression $expression
$Env:Path = $prev_path
}
undump `
-FileType $FileType `
-File $File `
-Version $Version `
-OutputFile $OutputFile