-
Notifications
You must be signed in to change notification settings - Fork 1
/
renamer.ps1
160 lines (108 loc) · 5.01 KB
/
renamer.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
$s2madir = "./s2ma"
$tempdir = "./_temp_"
$mapdir = "./maps"
$moddir = "./mods"
$mpqesitor = "./MPQEditor.exe"
New-Item -ItemType Directory -Force -Path $s2madir | Out-Null
New-Item -ItemType Directory -Force -Path $tempdir | Out-Null
New-Item -ItemType Directory -Force -Path $mapdir | Out-Null
New-Item -ItemType Directory -Force -Path $moddir | Out-Null
Get-ChildItem -Path $tempdir -Include * -File -Recurse | ForEach-Object { $_.Delete() }
Get-ChildItem -Path $mapdir -Include * -File -Recurse | ForEach-Object { $_.Delete() }
Get-ChildItem -Path $moddir -Include * -File -Recurse | ForEach-Object { $_.Delete() }
$mpqesitor = Resolve-Path $mpqesitor
$s2madir = Resolve-Path $s2madir
$tempdir = Resolve-Path $tempdir
$markdown = @"
# ``*.s2ma`` Tables
The tables are generated by [``renamer.ps1``](https://github.com/jamiephan/HeroesOfTheStorm_S2MA/blob/main/renamer.ps1).
- [Full Table](#table-full)
- [Maps only Table](#table-maps)
- [Mods only Table](#table-mods)
- [Null only Table](#table-null)
<a name="table-full" />
## Full Table
| s2ma | type | path |
|-|-|-|
"@
$markdownMapsTable = @"
---
<a name="table-maps" />
## Maps only Table
This table only contains the Map files:
| Map Name | s2ma |
|-|-|
"@
$markdownModsTable = @"
---
<a name="table-mods" />
## Mods only Table
This table only contains the Mod files:
| Mod Name | s2ma |
|-|-|
"@
$markdownNullTable = @"
---
<a name="table-null" />
## Null only Table
This table only contains the Null files (Undecided Files):
| s2ma |
|-|
"@
function getModName ($file) {
# Full path of the s2ma file
$filePath = $file.FullName
# Basename (without extension) of the s2ma file
$basename = $file.BaseName
$temppath = ($tempdir.Path + "\" + "$basename")
# Extract the GameStrings.txt
Start-Process $mpqesitor -ArgumentList "extract", "$filepath", "enus.stormdata/localizeddata/gamestrings.txt", "$temppath" -NoNewWindow -PassThru | Wait-Process
# Read the extracted file
if (Test-Path -Path ($temppath + "\" + "gamestrings.txt")) {
$DocInfoName = Get-Content -Path ($temppath + "\" + "gamestrings.txt") | Select-String -Pattern "^DocInfo/Name="
# $DocInfoName = $DocInfoName.Replace("DocInfo/Name=", "")
$DocInfoName = $DocInfoName.ToString().Replace("DocInfo/Name=", "").Replace(":", "")
return $DocInfoName
}
else {
return $false
}
}
function isMapFile($file) {
# Full path of the s2ma file
$filePath = $file.FullName
# Basename (without extension) of the s2ma file
$basename = $file.BaseName
$temppath = ($tempdir.Path + "\" + "$basename")
Start-Process $mpqesitor -ArgumentList "extract", "$filepath", "mapscript.galaxy", "$temppath" -NoNewWindow -PassThru | Wait-Process
return Test-Path -Path ($temppath + "\" + "mapscript.galaxy")
}
# Loop each file
Get-ChildItem -File -Path $s2madir -Filter "*.s2ma" | Sort-Object | ForEach-Object -Process {
$isS2MAMapFile = isMapFile($_)
$ModName = getModName($_)
if ($ModName) {
if ($isS2MAMapFile) {
# Its a stormmap file, copy to ./maps and rename it
Copy-Item $_.FullName -Destination "$mapdir/$ModName.stormmap" -Force
$markdown = $markdown + "`n| [``$_``]($([uri]::EscapeUriString("https://github.com/jamiephan/HeroesOfTheStorm_S2MA/blob/main/s2ma/$_"))) | ``Map`` | [``./maps/$ModName.stormmap``]($([uri]::EscapeUriString("https://github.com/jamiephan/HeroesOfTheStorm_S2MA/tree/main/maps/$ModName.stormmap"))) |"
$markdownMapsTable = $markdownMapsTable + "`n| [``$ModName``]($([uri]::EscapeUriString("https://github.com/jamiephan/HeroesOfTheStorm_S2MA/tree/main/maps/$ModName.stormmap"))) | [``$_``]($([uri]::EscapeUriString("https://github.com/jamiephan/HeroesOfTheStorm_S2MA/blob/main/s2ma/$_")))|"
}
else {
# Its a stormmod file, copy to ./mods and rename it
Copy-Item $_.FullName -Destination "$moddir/$ModName.stormmod" -Force
$markdown = $markdown + "`n| [``$_``]($([uri]::EscapeUriString("https://github.com/jamiephan/HeroesOfTheStorm_S2MA/blob/main/s2ma/$_"))) | ``Mod`` | [``./mods/$ModName.stormmod``]($([uri]::EscapeUriString("https://github.com/jamiephan/HeroesOfTheStorm_S2MA/tree/main/mods/$ModName.stormmod"))) |"
$markdownModsTable = $markdownModsTable + "`n| [``$ModName``]($([uri]::EscapeUriString("https://github.com/jamiephan/HeroesOfTheStorm_S2MA/tree/main/mods/$ModName.stormmod"))) | [``$_``]($([uri]::EscapeUriString("https://github.com/jamiephan/HeroesOfTheStorm_S2MA/blob/main/s2ma/$_"))) |"
}
} else {
$markdown = $markdown + "`n| [``$_``]($([uri]::EscapeUriString("https://github.com/jamiephan/HeroesOfTheStorm_S2MA/blob/main/s2ma/$_"))) | ``Null`` | ``Null`` |"
$markdownNullTable = $markdownNullTable + "`n| [``$_``]($([uri]::EscapeUriString("https://github.com/jamiephan/HeroesOfTheStorm_S2MA/blob/main/s2ma/$_"))) |"
}
}
# Clean up Temp dir
Remove-Item -Recurse $tempdir
# Copy maps from extra_maps to maps
Copy-Item -Path "./extra_maps/*.stormmap" -Destination $mapdir -Recurse
# Save the markdown file
$markdown = $markdown + "`n" + $markdownMapsTable + "`n" + $markdownModsTable + "`n" + $markdownNullTable
Out-File -FilePath "./TABLE.md" -InputObject $markdown