Last active
March 31, 2021 10:52
-
-
Save cosmo0/88f26899c59fbb49346ec7fba8e35c8b to your computer and use it in GitHub Desktop.
Script to clean and sort a full console romset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$folder = $Args[0] | |
if ($folder -eq $null) { | |
echo "please call 'clean.ps1 [folder path]'" | |
} | |
function movedest { | |
$file = $args[0] | |
$dest = $args[1] | |
$name = [System.IO.Path]::GetFileName($file) | |
if (test-path -LiteralPath $file) { | |
echo "moving $name to $dest" | |
$dest = (join-path $folder $dest) | |
if (-not(test-path $dest)) { mkdir $dest | out-null } | |
move-item -LiteralPath $file -destination $dest | |
} | |
} | |
echo "########## Cleaning $folder ##########" | |
echo "########## TAGS CHECK ##########" | |
$tag = @{ | |
"(proto)" = "prototype" | |
"(proto 1)" = "prototype" | |
"(proto 2)" = "prototype" | |
"(unl)" = "unofficial" | |
"(pd)" = "unofficial" | |
"[u]" = "unofficial" | |
"[u2]" = "unofficial" | |
"[u3]" = "unofficial" | |
"[u4]" = "unofficial" | |
"[unreleased]" = "unofficial" | |
"(demo)" = "demo" | |
"(alt 1)" = "alt" | |
"(rev 1)" = "alt" | |
"(v1.1)" = "alt" | |
"[a]" = "alt" | |
"[a2]" = "alt" | |
"[a3]" = "alt" | |
"[a4]" = "alt" | |
"[a5]" = "alt" | |
"[a6]" = "alt" | |
"[a7]" = "alt" | |
"[o]" = "alt" | |
"[o2]" = "alt" | |
"[o3]" = "alt" | |
"[o4]" = "alt" | |
"[o5]" = "alt" | |
"(beta)" = "beta" | |
"[b]" = "beta" | |
"[b2]" = "beta" | |
"[b3]" = "beta" | |
"[b4]" = "beta" | |
"[b5]" = "beta" | |
"[b6]" = "beta" | |
"[b7]" = "beta" | |
"[b8]" = "beta" | |
"[b9]" = "beta" | |
"[b10]" = "beta" | |
"[b11]" = "beta" | |
"[b12]" = "beta" | |
"[b13]" = "beta" | |
"[cr]" = "cracked" | |
"[cr " = "cracked" | |
"[h]" = "hack" | |
"[h " = "hack" | |
"[h2]" = "hack" | |
"[h2 " = "hack" | |
"[h3]" = "hack" | |
"[h3 " = "hack" | |
"[h4]" = "hack" | |
"[h5]" = "hack" | |
"[h6]" = "hack" | |
"[h7]" = "hack" | |
"[h8]" = "hack" | |
"[h9]" = "hack" | |
"[h10]" = "hack" | |
"[h11]" = "hack" | |
"[h12]" = "hack" | |
"[h13]" = "hack" | |
"[t]" = "trainer" | |
"[t " = "trainer" | |
"[t2]" = "trainer" | |
"[p]" = "prototype" | |
"[p2]" = "prototype" | |
"[p3]" = "prototype" | |
"[f]" = "fixed" | |
"[f1]" = "fixed" | |
"[f2]" = "fixed" | |
"[bios]" = "system" | |
"[tr " = "translation" | |
"ZZZ-UNK-" = "unknown" | |
"mahjong" = "board" | |
"chess" = "board" | |
"backgammon" = "board" | |
"shougi" = "board" | |
"checkers" = "board" | |
"casino" = "casino" | |
"poker" = "casino" | |
"slots" = "casino" | |
"blackjack" = "casino" | |
"black jack" = "casino" | |
"pachi-slot" = "casino" | |
"pachinko" = "casino" | |
} | |
gci $folder -File | % { | |
$file = $_.FullName | |
$name = $_.Name | |
$move = $false | |
$dest = "" | |
# check file name | |
foreach($t in $tag.keys) | |
{ | |
if ($name.ToUpper().Contains($t.ToUpper())) { | |
$move = $true | |
$dest = $tag[$t] | |
break | |
} | |
} | |
# move file | |
if ($move) { | |
movedest $file $dest | |
} | |
} | |
echo "########## REGION CHECK ##########" | |
# list of games | |
$games = @{} | |
gci $folder -File | % { | |
$file = $_.FullName | |
$name = $_.Name | |
#echo "extracting regions for $name" | |
# get game name | |
$game = $name.Substring(0, $name.IndexOf("(")).Trim() | |
# add or get entry | |
$gameEntry = $games[$game] | |
if ($gameEntry -eq $null) { | |
$games.Add($game, @{}) | |
$gameEntry = $games[$game] | |
} | |
# get game tags | |
$tagsString = $name.Substring($name.IndexOf("("), $name.LastIndexOf(".") - $name.IndexOf("(")) | |
$tags = Select-String -InputObject $tagsString -Pattern "\(([^\)]+)\)" -AllMatches | |
$hasRegion = $false | |
$moved = $false | |
# check tags | |
foreach ($t in $tags.Matches) { | |
# looking for region tag | |
$tval = $t.Groups[1].Value | |
("U", "US", "USA") | % { | |
if (($tval -match "^$_`$") -or ($tval -match "$_,") -or ($tval -match ",\s?$_")) { | |
if ($gameEntry.us -eq $null) { | |
$gameEntry.us = $file | |
$hasRegion = $true | |
} elseif (($gameEntry.us -ne $file) -and (-not $moved)) { | |
# we already found another US game | |
movedest $file "world" | |
$moved = $true | |
} | |
} | |
} | |
("J", "JP", "JAP", "Japan") | % { | |
if (($tval -match "^$_`$") -or ($tval -match "$_,") -or ($tval -match ",\s?$_")) { | |
if ($gameEntry.jp -eq $null) { | |
$gameEntry.jp = $file | |
$hasRegion = $true | |
} elseif (($gameEntry.jp -ne $file) -and (-not $moved)) { | |
# we already found another JP game | |
movedest $file "world" | |
$moved = $true | |
} | |
} | |
} | |
("E", "EU", "Europe") | % { | |
if (($tval -match "^$_`$") -or ($tval -match "$_,") -or ($tval -match ",\s?$_")) { | |
if ($gameEntry.eu -eq $null) { | |
$gameEntry.eu = $file | |
$hasRegion = $true | |
} elseif (($gameEntry.eu -ne $file) -and (-not $moved)) { | |
# we already found another EU game | |
movedest $file "world" | |
$moved = $true | |
} | |
} | |
} | |
} | |
if (-not ($hasRegion)) { | |
if ($gameEntry.world -eq $null) { | |
$gameEntry.world = $file | |
} elseif (($gameEntry.world -ne $file) -and (-not $moved)) { | |
# we already found a "world" game | |
movedest $file "world" | |
$moved = $true | |
} | |
} | |
#$gameEntry | |
} | |
# move files | |
foreach ($gk in $games.Keys) { | |
$g = $games[$gk] | |
if ($g.us -ne $null) { # there's a US version | |
#echo "US: $($g.us)" | |
# move EU | |
if (($g.eu -ne $null) -and ($g.eu -ne $g.us)) { | |
movedest $g.eu "world" | |
} | |
# move JP | |
if (($g.jp -ne $null) -and ($g.jp -ne $g.us)) { | |
movedest $g.jp "world" | |
} | |
# move generic | |
if (($g.world -ne $null) -and ($g.world -ne $g.us)) { | |
movedest $g.world "world" | |
} | |
} elseif ($g.eu -ne $null) { # there's a EU version | |
#echo "EU: $($g.eu)" | |
# move JP | |
if (($g.jp -ne $null) -and ($g.jp -ne $g.eu)) { | |
movedest $g.jp "world" | |
} | |
# move world | |
if (($g.world -ne $null) -and ($g.world -ne $g.eu)) { | |
movedest $g.world "world" | |
} | |
} elseif ($g.world -ne $null) { # there's a generic version | |
#echo "world: $($g.world)" | |
# move JP | |
if (($g.jp -ne $null) -and ($g.jp -ne $g.world)) { | |
movedest $g.jp "world" | |
} | |
} | |
} | |
echo "########## DONE ##########" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment