-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump.ps1
84 lines (82 loc) · 2.37 KB
/
dump.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
param(
# Dump mode: ecl, msg, msg_ending, std
[Parameter(
Mandatory = $true,
Position = 0,
HelpMessage = "Dump mode: ecl, msg, msg_ending, std")]
[ValidateNotNullOrEmpty()]
[string]
$DumpMode,
# Path to Touhou data file
[Parameter(
Mandatory = $true,
Position = 0,
HelpMessage = "Path to 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 = "Output file. Empty = {Input file}.txt")]
[AllowEmptyString()]
[string]
$OutputFile
)
function dump {
param (
[Parameter(Position = 0)]
[string] $DumpMode,
[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
}
$Env:Path += ";$thtk_dir"
$DumpCommand = @{
"ecl" = "thecl.exe -d {0} `"{1}`" `"{2}`" -m `"{3}`""
"msg" = "thmsg.exe -d {0} `"{1}`" `"{2}`""
"msg_ending" = "thmsg.exe -e -d {0} `"{1}`" `"{2}`""
"std" = "thstd.exe -d {0} `"{1}`" `"{2}`""
}
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
if ("" -eq $OutputFile) {
$OutputFile = $File + ".txt"
}
$file_name = Split-Path $File -Leaf
$output_file_name = Split-Path $OutputFile -Leaf
$expression = $DumpCommand[$DumpMode] -f $Version, $File, $OutputFile, $eclmap_file_path
Write-Host -NoNewLine "Dumping: $file_name --> $output_file_name "
if ("ecl" -eq $DumpMode) {
Write-Host -NoNewline ("using ecl map " + $eclmap_name)
}
Write-Host ""
Invoke-Expression $expression
$Env:Path = $prev_path
}
dump `
-DumpMode $DumpMode `
-File $File `
-Version $Version `
-OutputFile $OutputFile