-
Notifications
You must be signed in to change notification settings - Fork 0
/
Compress-Games.ps1
executable file
·242 lines (220 loc) · 7.71 KB
/
Compress-Games.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
<#
.SYNOPSIS
Compresses disc images according to support of emulators
.DESCRIPTION
Guide used from batocera wiki https://wiki.batocera.org/disk_image_compression
BIN/CUE will be compressed into CHD with chdman
ISO will be commpressed into CHD since pcsx2 supports CHD since 1.7
CSO to CHD via decompressing to ISO and then into CHD
PS3/Folders Games will be compressed with mksquashfs
.EXAMPLE
PS C:\> Compress-Games.ps1 -Path "C:\Games\roms"
Will try to compress all games in C:\Games\roms according to batocera filestructure e.g. c:\Games\roms\ps3
.PARAMETER Path
Path to batocera share folder
.PARAMETER CHDMan
Path to chdman binary e.g. chdman.exe
.PARAMETER MaxCso
Path to maxcso binary e.g. maxcso.exe
.PARAMETER Systems
Which systems should be looked for, defaults to psx.ps2,ps3,dreamcast
.INPUTS
Inputs (if any)
.OUTPUTS
Output (if any)
.NOTES
General notes
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[Alias("RomPath")]
[String]
$Path,
[String]
$CHDMan = "/usr/bin/chdman",
[String]
$MaxCSO = "~/maxcso/maxcso",
[String[]]
[ValidateSet("PS", "PS2", "PS3", "Dreamcast")]
$Systems = @("PS", "PS2", "PS3", "Dreamcast"),
[Switch]
$Silent,
[Switch]
$Whatif
)
$ErrorActionPreference = "Stop"
function Compress-Game {
param (
[String]
$Source,
[String]
$Destination,
[String]
[ValidateSet("ISO", "CUE", "CSO", "Directory", "ps3")]
$Format,
[Switch]
$Whatif
)
# Testing source file
if (-not (Test-Path -LiteralPath $Source)) {
Write-Error "Source file $Source not found"
break
}
$Game = Get-ChildItem -LiteralPath $Source
if ($Format -eq "iso") {
Write-Verbose "Source format is ISO"
$CompressedFile = $Game.Fullname -replace "iso", "chd"
$Command = "'$MaxCSO '$($Game.FullName)''"
Write-Verbose "Compressing $($Game.FullName)"
if (-not (Test-Path -LiteralPath $CompressedFile)) {
if ($whatif) {
"$CHDMan createcd -i '$($Game.FullName)' -o '$CompressedFile' --force"
}
else {
& $CHDMan createcd -i "$($Game.FullName)" -o "$CompressedFile" --force
}
}
else {
if (-not $Silent) {
Write-Warning "$($Game.Name) already compressed"
}
}
}
elseif ($Format -eq "cue") {
Write-Verbose "Source format is BIN/CUE"
$CompressedFile = $Game.Fullname -replace "cue", "chd"
$Command = "$CHDMan createcd -i '$($Game.FullName)' -o '$CompressedFile' --force"
Write-Verbose "Compressing $($Game.FullName)"
if (-not (Test-Path -LiteralPath $CompressedFile)) {
if ($whatif) {
"$CHDMan createcd -i '$($Game.FullName)' -o '$CompressedFile' --force"
}
else {
& $CHDMan createcd -i "$($Game.FullName)" -o "$CompressedFile" --force
}
}
else {
if (-not $Silent) {
Write-Warning "$($Game.Name) already compressed"
}
}
}
elseif ($Format -eq "Directory") {
Write-Verbose "Source format is a folder"
Write-Verbose "$Game"
$Game = $Game.Directory
$CompressedFile = "$($Game.Fullname).squashfs"
Write-Verbose "Compressed file will be $CompressedFile"
$Command = "'mksquashfs '$($Game.FullName)' '$CompressedFile''"
Write-Verbose "Compressing $($Game.FullName)"
if (-not (Test-Path -LiteralPath $CompressedFile)) {
if ($whatif) {
$Command
}
else {
mksquashfs "$($Game.FullName)" "$CompressedFile"
}
}
else {
if (-not $Silent) {
Write-Warning "$($Game.Name) already compressed"
}
}
}
elseif ($Format -eq "CSO") {
Write-Verbose "Source format is CSO"
$CompressedFile = $Game.Fullname -replace "cso", "chd"
$tempfile = $Game.Fullname -replace "cso", "iso"
Write-Verbose "Compressing $($Game.FullName)"
if (-not (Test-Path -LiteralPath $CompressedFile)) {
if ($whatif) {
"$MaxCSO '$($Game.FullName)' --decompress -o '$tempfile'"
"$CHDMan createcd -i '$tempfile' -o '$CompressedFile' --force"
}
else {
Write-Verbose "Decompressing CSO"
& $MaxCSO "$($Game.FullName)" --decompress -o "$tempfile"
Write-Verbose "Compressing CHD"
& $CHDMan createcd -i "$tempfile" -o "$CompressedFile" --force
}
}
else {
if (-not $Silent) {
Write-Warning "$($Game.Name) already compressed"
}
}
}
}
if ($Whatif) {
$Global:whatif = $Whatif
}
foreach ($System in $Systems) {
Write-Verbose "Looking for $System"
# PSX Games
if ($System -eq "PS") {
if (-not $Silent) {
Write-Output "Checking PlayStation Games"
}
# Compress BIN/CUE to CHD
$Games = Get-ChildItem $Path/$($System.ToLower()) -File -Recurse | Where-Object { $_.Name -like "*.cue" }
foreach ($Game in $Games) {
Write-Output "Working on Game: $Game"
Write-Verbose "Working on Game: $($Game.FullName)"
Compress-Game -Source $Game.FullName -Format "cue"
}
}
# PS2 Games
if ($System -eq "PS2") {
if (-not $Silent) {
Write-Output "Checking PlayStation 2 Games"
}
# Compress ISOs to CHD
$Games = Get-ChildItem $Path/$($System.ToLower()) -File -Recurse | Where-Object { $_.Name -like "*.iso" }
foreach ($Game in $Games) {
Write-Output "Working on Game: $Game"
Write-Verbose "Working on Game: $($Game.FullName)"
Compress-Game -Source $Game.FullName -Format "iso"
}
# Compress ISOs to CSO
$Games = Get-ChildItem $Path/$($System.ToLower()) -File -Recurse | Where-Object { $_.Name -like "*.cso" }
foreach ($Game in $Games) {
Write-Output "Working on Game: $Game"
Write-Verbose "Working on Game: $($Game.FullName)"
Compress-Game -Source $Game.FullName -Format "cso"
}
# Compress BIN/CUE to CHD
$Games = Get-ChildItem $Path/$($System.ToLower()) -File -Recurse | Where-Object { $_.Name -like "*.cue" }
foreach ($Game in $Games) {
Write-Output "Working on Game: $Game"
Write-Verbose "Working on Game: $($Game.FullName)"
Compress-Game -Source $Game.FullName -Format "cue"
}
}
# PS3 Games
if ($System -eq "PS3") {
if (-not $Silent) {
Write-Output "Checking PlayStation 3 Games"
}
# Compress Folders to Squashfs
$Games = Get-ChildItem $Path/$($System.ToLower()) -Directory | Where-Object { $_.Name -like "*.ps3" }
foreach ($Game in $Games) {
Write-Output "Working on Game: $Game"
Write-Verbose "Working on Game: $($Game.FullName)"
Compress-Game -Source $Game.FullName -Format "Directory"
}
}
# Dreamcast Games
if ($System -eq "Dreamcast") {
if (-not $Silent) {
Write-Output "Checking Dreamcast Games"
}
# Compress BIN/CUE to CHD
$Games = Get-ChildItem $Path/roms/$($System.ToLower()) -File -Recurse | Where-Object { $_.Name -like "*.cue" }
foreach ($Game in $Games) {
Write-Output "Working on Game: $Game"
Write-Verbose "Working on Game: $($Game.FullName)"
Compress-Game -Source $Game.FullName -Format "cue"
}
}
}