-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_igame_menu.ps1
310 lines (225 loc) · 7.69 KB
/
build_igame_menu.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# Build iGame Menu
# ----------------
#
# Author: Henrik Nørfjand Stengaard
# Date: 2016-04-21
#
# A PowerShell script to build iGame gamelist and screenshots.
Param(
[Parameter(Mandatory=$true)]
[string]$whdloadGamesPath,
[Parameter(Mandatory=$true)]
[string]$outputPath,
[Parameter(Mandatory=$true)]
[string]$mode
)
# check id mode is aga or ocs
if ($mode -notmatch '^(aga|ocs)')
{
Write-Error "Unsupported mode '$mode'"
exit 1
}
# root
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
# input and output paths
$whdownloadGamesSlaveIndexPath = [System.IO.Path]::Combine($scriptPath, "whdownload_games_slave_index")
# screenshot paths
$screenshotPath = [System.IO.Path]::Combine($scriptPath, "screenshots")
$whdloadScreenshotPath = [System.IO.Path]::Combine($screenshotPath, "whdload")
# get game index name from first character in game name
function GetGameIndexName($gameName)
{
$gameName = $gameName -replace '^[^a-z0-9]+', ''
if ($gameName -match '^[0-9]')
{
$gameIndexName = "0"
}
else
{
$gameIndexName = $gameName.Substring(0,1)
}
return $gameIndexName
}
# read index
function ReadIndex($indexFile)
{
$index = @{}
ForEach($line in (Get-Content $indexFile | Select-Object -Skip 1))
{
$columns = $line -split ";"
$index.Set_Item($columns[0], $columns)
}
return $index
}
# read whdload game slave index
function ReadWhdloadGameSlaveIndex($indexFile)
{
$index = @{}
ForEach($line in (Get-Content $indexFile | Select-Object -Skip 1))
{
$columns = $line -split ";"
$whdloadGameFileName = $columns[0]
$whdloadSlaves = $index.Get_Item($whdloadGameFileName)
if (!$whdloadSlaves)
{
$whdloadSlaves = @()
}
$whdloadSlaves += , $columns
$index.Set_Item($whdloadGameFileName, $whdloadSlaves)
}
return $index
}
# Get whdload game files
Write-Output "Reading whdload games from '$whdloadGamesPath'..."
$whdloadGameFiles = Get-ChildItem -recurse -Path $whdloadGamesPath -exclude *.html,*.csv -File
Write-Output "$($whdloadGameFiles.Count) entries"
Write-Output ""
# Read whdload games index
$whdloadGameIndexFile = [System.IO.Path]::Combine($whdloadGamesPath, "whdload_games_index.csv")
Write-Output "Reading whdload games index file '$whdloadGameIndexFile'..."
$whdloadGameIndex = ReadIndex $whdloadGameIndexFile
$whdloadGameIndex.Count
# Read whdload extract index
$whdloadExtractIndexFile = [System.IO.Path]::Combine($whdloadGamesPath, "whdload_extract_index.csv")
Write-Output "Reading whdload extract index file '$whdloadExtractIndexFile'..."
$whdloadExtractIndexIndex = ReadIndex $whdloadExtractIndexFile
$whdloadExtractIndexIndex.Count
# Read whdload games index
$whdloadGameSlaveIndexFile = [System.IO.Path]::Combine($whdownloadGamesSlaveIndexPath, "whdload_slave_index.csv")
Write-Output "Reading whdload game slave index file '$whdloadGameSlaveIndexFile'..."
$whdloadGameSlaveIndex = ReadWhdloadGameSlaveIndex $whdloadGameSlaveIndexFile
$whdloadGameSlaveIndex.Count
# Read whdload screenshot index
$whdloadScreenshotIndexFile = [System.IO.Path]::Combine($whdloadScreenshotPath, "whdload_screenshots.csv")
Write-Output "Reading whdload screenshot index file '$whdloadScreenshotIndexFile'..."
$whdloadScreenshotIndex = ReadIndex $whdloadScreenshotIndexFile
$whdloadScreenshotIndex.Count
# Create output path, if it doesn't exist
if(!(test-path -path $outputPath))
{
md $outputPath | Out-Null
}
#
$whdloadGameCountindex = @{}
ForEach ($whdloadGameFile in $whdloadGameFiles)
{
# get whdload game from index
$whdloadGame = $whdloadGameIndex.Get_Item($whdloadGameFile.Name)
if (!$whdloadGame)
{
continue
}
$whdloadGameName = $whdloadGame[1]
if ($whdloadGameCountindex.ContainsKey($whdloadGameName))
{
$count = $whdloadGameCountindex.Get_Item($whdloadGameName)
}
else
{
$count = 0
}
$count++
$whdloadGameCountindex.Set_Item($whdloadGameName, $count)
}
$iGameCompleteGamesListFile = [System.IO.Path]::Combine($outputPath, "gameslist.")
$iGameCompleteGamesListLines = @()
# Process whdload game files
ForEach ($whdloadGameFile in $whdloadGameFiles)
{
# get whdload game from index
$whdloadGame = $whdloadGameIndex.Get_Item($whdloadGameFile.Name)
if (!$whdloadGame)
{
continue
}
$hardware = ""
if ($whdloadGameFile.Name -match '_cd32')
{
$hardware = "cd32"
}
if ($whdloadGameFile.Name -match '_aga')
{
$hardware = "aga"
}
if ($whdloadGameFile.Name -match '_cdtv')
{
$hardware = "cdtv"
}
$whdloadGameName = $whdloadGame[1]
$whdloadGameBaseName = [System.IO.Path]::GetFileNameWithoutExtension($whdloadGameFile.FullName) -split "_" | Select-Object -first 1
$whdloadGameSlaves = $whdloadGameSlaveIndex.Get_Item($whdloadGameFile.Name)
if (!$whdloadGameSlaves)
{
Write-Error "No slave '$whdloadGameBaseName'"
exit 1
}
ForEach($whdloadGameSlave in $whdloadGameSlaves)
{
# get whdload game slave file name and copy columns
$whdloadGameSlaveFile = $whdloadGameSlave[1]
$whdloadGameSlaveName = $whdloadGameSlave[3].Replace("CD??", "CD32")
$whdloadGameSlaveCopy = $whdloadGameSlave[4]
# get whdload game slave directory from whdload game slave file
$whdloadGameSlaveDirectory = [System.IO.Path]::GetDirectoryName($whdloadGameSlaveFile)
$whdloadGameSlaveFileName = [System.IO.Path]::GetFileName($whdloadGameSlaveFile)
# get whdload extract
$whdloadExtract = $whdloadExtractIndexIndex.Get_Item($whdloadGameFile.Name)
# check if whdload extract path exists
if (!$whdloadExtract)
{
Write-Error "Missing extract path"
exit 1
}
$whdloadExtractPath = $whdloadExtract[1]
$whdloadGamePath = "$($whdloadExtractPath)/$($whdloadGameSlaveDirectory)"
#
$iGameWhdloadPath = [System.IO.Path]::Combine($outputPath, ($whdloadGamePath -replace ":", "\" -replace "/", "\"))
if(!(Test-Path -Path $iGameWhdloadPath))
{
md $iGameWhdloadPath | Out-Null
}
# igame files
$iGameGameIffFile = [System.IO.Path]::Combine($iGameWhdloadPath, "igame.iff")
# get whdload screenshot
$whdloadScreenshotGamePath = [System.IO.Path]::Combine($whdloadScreenshotPath, $whdloadGameBaseName + ".$hardware" )
if (test-path -path $whdloadScreenshotGamePath)
{
$whdloadScreenshotFile = [System.IO.Path]::Combine($whdloadScreenshotGamePath, "igame.iff")
# copy if screenshot exists
if (test-path -path $whdloadScreenshotFile)
{
Copy-Item $whdloadScreenshotFile $iGameGameIffFile -force
}
}
$iGameTitle = "$($whdloadGameName)"
# append slave name to igame title in parantheses, if game has multiple slaves
if ($whdloadGameSlaves.Count -gt 1)
{
$slaveName = [System.IO.Path]::GetFileNameWithoutExtension($whdloadGameSlaveFile)
if ($iGameTitle -match '\s+\([^\(\)]+\)')
{
$iGameTitle = $iGameTitle -replace '(\s+\([^\(\)]+)\)', '$1'
$iGameTitle += ", $($slaveName))"
}
else
{
$iGameTitle += " ($($slaveName))"
}
}
# build igame game gameslist lines
$iGameGameGamesListLines = @(
"index=0",
"title=$($iGameTitle)",
"genre=Unknown",
"path=$($whdloadGamePath)/$($whdloadGameSlaveFileName)",
"favorite=0",
"timesplayed=0",
"lastplayed=0",
"hidden=0",
"" )
# add igame gameslist lines
$iGameCompleteGamesListLines += $iGameGameGamesListLines
}
}
# write complete igame gameslist file in ascii encoding
[System.IO.File]::WriteAllText($iGameCompleteGamesListFile, [System.Text.Encoding]::ASCII.GetString([System.Text.Encoding]::UTF8.GetBytes($iGameCompleteGamesListLines -join "`n")), [System.Text.Encoding]::ASCII)