-
Notifications
You must be signed in to change notification settings - Fork 1
/
filter_eab_whdload_packs.ps1
165 lines (137 loc) · 6.39 KB
/
filter_eab_whdload_packs.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
# Filter English Amiga Board WHDLoad Packs
# ----------------------------------------
#
# Author: Henrik Nørfjand Stengaard
# Date: 2017-12-22
#
# A PowerShell script to filter whdload packs from English Amiga Board.
# The script filters whdload packs by excluding hardware, language versions, calculate rank based on hardware, language, demo, memory and other texts.
# Best ranked versions are picked for each whdload directory.
Param(
[Parameter(Mandatory=$true)]
[string]$entriesFile,
[Parameter(Mandatory=$true)]
[string]$outputEntriesFile,
[Parameter(Mandatory=$false)]
[string]$excludeHardwarePattern,
[Parameter(Mandatory=$false)]
[string]$excludeLanguagePattern,
[Parameter(Mandatory=$false)]
[string]$excludeFlagPattern,
[Parameter(Mandatory=$false)]
[int32]$maxWhdloadSlaveBaseMemSize,
[Parameter(Mandatory=$false)]
[int32]$maxWhdloadSlaveExpMem,
[Parameter(Mandatory=$false)]
[switch]$bestVersion,
[Parameter(Mandatory=$false)]
[switch]$eachHardware,
[Parameter(Mandatory=$false)]
[switch]$skipCopying
)
# resolve paths
$entriesFile = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($entriesFile)
$outputEntriesFile = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($outputEntriesFile)
# read entries
$entries = @()
$entries += import-csv -delimiter ';' $entriesFile
# Patterns for filtering versions of whdload slaves
$hardwarePattern = '(CD32|AGA|CDTV|CD)$'
$languagePattern = '(En|De|DE|Fr|It|Se|Pl|Es|Cz|Dk|Fi|Gr|CV)$'
$memoryPattern = '(Slow|Fast|LowMem|Chip|1MB|1Mb|2MB|15MB|512k|512K|512kb|512Kb|512KB)$'
$demoPattern = '(Demo\d?|Demos|Preview|DemoLatest|DemoPlay|DemoRoll|Prerelease)$'
$otherPattern = '(Alt|AmigaPower|AmigaFormat|AmigaAction|CUAmiga|TheOne|NoMusic|NoSounds|NoVoice|Fix|Fixed|Aminet|ComicRelief|Util|Files|Image\d?|060|Intro|NoIntro|NTSC|Censored|Kick31|Kick13|\dDisk|\(EasyPlay\)|_Kernal1.1|Cracked|HiRes|LoRes|Crunched|Decrunched)$'
$compilationPattern = '(&Missions|&MissionDisk|&MissionDisks|&SceneryDisk\d*|&Hawaiian|&SceneryDisks|&CityDefense|&ExtraTime|&SpaceHarrier|&Missions|&ExtendedLevels|&CadaverThePayoff|&Planeteers|&ConstrSet|&ConstructionSet|&MstrTrcks|&DDisks|&DataDisk\d?|&DataDisks|&Profidisk|&Data|&TourDisk|&ChallengeGames|&VoyageBeyond|&RetrnFntZone|&RFantasyZone|&SummerGames2|&NewWorlds)'
foreach ($entry in $entries)
{
$name = $entry.EntryName
$flags = @()
if ($entry.WhdloadSlaveFlags)
{
$flags += $entry.WhdloadSlaveFlags -split ','
}
# Special replace for 'Invest' and 'Spirit of Adventure' german games for language pattern
if ($name -cmatch 'De\d+Disk')
{
$name = $name -creplace '(De)(\d+Disk)', '$2$1'
}
$hardware = @()
$language = @()
$memory = @()
$demo = @()
$other = @()
$compilation = @()
while ($name -cmatch $hardwarePattern -or $name -cmatch $languagePattern -or $name -cmatch $memoryPattern -or $name -cmatch $demoPattern -or $name -cmatch $otherPattern -or $name -cmatch $compilationPattern)
{
if ($name -cmatch $hardwarePattern)
{
$hardware +=, ($name | Select-String -Pattern $hardwarePattern -CaseSensitive -AllMatches | % { $_.Matches } | % { $_.Groups[0].Value } | Select-Object -First 1)
$name = $name -creplace $hardwarePattern, ''
}
if ($name -cmatch $languagePattern)
{
$match = ($name | Select-String -Pattern $languagePattern -CaseSensitive -AllMatches | % { $_.Matches } | % { $_.Groups[0].Value } | Select-Object -First 1)
if ($match -notmatch 'En')
{
$language +=, $match
}
$name = $name -creplace $languagePattern, ''
}
if ($name -cmatch $memoryPattern)
{
$memory +=, ($name | Select-String -Pattern $memoryPattern -CaseSensitive -AllMatches | % { $_.Matches } | % { $_.Groups[0].Value } | Select-Object -First 1)
$name = $name -creplace $memoryPattern, ''
}
if ($name -cmatch $demoPattern)
{
$demo +=, ($name | Select-String -Pattern $demoPattern -CaseSensitive -AllMatches | % { $_.Matches } | % { $_.Groups[0].Value } | Select-Object -First 1)
$name = $name -creplace $demoPattern, ''
}
if ($name -cmatch $otherPattern)
{
$other +=, ($name | Select-String -Pattern $otherPattern -CaseSensitive -AllMatches | % { $_.Matches } | % { $_.Groups[0].Value } | Select-Object -First 1)
$name = $name -creplace $otherPattern, ''
}
if ($name -cmatch $compilationPattern)
{
$match = ($name | Select-String -Pattern $compilationPattern -CaseSensitive -AllMatches | % { $_.Matches } | % { $_.Groups[0].Value } | Select-Object -First 1)
$compilation +=, $match -replace '^&', ''
$name = $name -creplace $compilationPattern, ''
}
}
$name = $name -replace '&$', ''
# skip, if any exclude pattern matches hardware
if ($excludeHardwarePattern -and ($hardware | Where { $_ -match $excludeHardwarePattern }).Count -gt 0)
{
continue
}
# skip, if any exclude pattern matches language
if ($excludeLanguagePattern -and ($language | Where { $_ -match $excludeLanguagePattern }).Count -gt 0)
{
continue
}
# if hardware doesn't contain CD32 or AGA and flags has ReqAGA, then add AGA to hardware
if ((($hardware | Where { $_ -match '(CD32|AGA)' }).Count -eq 0) -and (($flags | Where { $_ -match 'ReqAGA' }).Count -gt 0))
{
$hardware +=, 'AGA'
}
if ($hardware.Count -eq 0)
{
$hardware +=, 'OCS/ECS'
}
$entry | Add-Member -MemberType NoteProperty -Name 'FilteredName' -Value $name -Force
$entry | Add-Member -MemberType NoteProperty -Name 'FilteredHardware' -Value ([string]::Join(',', $hardware)) -Force
$entry | Add-Member -MemberType NoteProperty -Name 'FilteredLanguage' -Value ([string]::Join(',', $language)) -Force
$entry | Add-Member -MemberType NoteProperty -Name 'FilteredMemory' -Value ([string]::Join(',', $memory)) -Force
$entry | Add-Member -MemberType NoteProperty -Name 'FilteredDemo' -Value ([string]::Join(',', $demo)) -Force
$entry | Add-Member -MemberType NoteProperty -Name 'FilteredOther' -Value ([string]::Join(',', $other)) -Force
$entry | Add-Member -MemberType NoteProperty -Name 'FilteredCompilation' -Value ([string]::Join(',', $compilation)) -Force
}
# create output dir, if it doesn't exist
$outputDir = Split-Path $outputEntriesFile -Parent
if(!(test-path -path $outputDir))
{
mkdir $outputDir | Out-Null
}
# write filtered entries list
$entries | export-csv -delimiter ';' -path $outputEntriesFile -NoTypeInformation -Encoding UTF8