Last active
August 29, 2017 19:04
-
-
Save Miss-Inputs/5789e1688232225029e756e0324eba60 to your computer and use it in GitHub Desktop.
The ROM Recognizer
This file contains 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
#I have a folder full of folders of ROMs and a folder full of No-Intro DATS. Time to stay up all night | |
#Doesn't work with zips | |
function md5($path){ | |
$md5 = [Security.Cryptography.MD5]::create("MD5") | |
$file = [IO.File]::openRead($path) | |
$buf = new-object byte[] (1024*8) | |
while (($read_len = $file.read($buf,0,$buf.length)) -eq $buf.length){ | |
[void]$md5.transformBlock($buf, $offset, $buf.length, $buf, $offset) | |
} | |
[void]$md5.transformFinalBlock($buf,0,$read_len) | |
$hash = $md5.hash | |
return -join ($hash | % { $_.toString('x2') }) | |
} | |
if($gamelist -eq $null){ | |
$gamelist = initGamelist | |
} | |
function initGamelist(){ | |
$gamelist = @() | |
gci Z:\Roms\No-Intro\*.dat | % { | |
$xml = (gc $_) -as [xml] | |
$platform = $_.name -replace '\([^\(]+\)\.dat$', '' | |
if($xml -ne $null){ | |
write-host "Loading data file: $_" | |
$xml.datafile | % { | |
$_.game | % { | |
$game = $_ | |
if($game -ne $null){ | |
#$game | add-member -membertype noteproperty -name platform -value $platform | |
#$gamelist += $game | |
$gamelist += ($game | add-member -passthru -membertype noteproperty -name platform -value $platform) | |
} | |
} | |
} | |
} | |
} | |
return $gamelist | |
} | |
function lookupGame($path){ | |
$md5 = md5 $path | |
$game = $gamelist | ? { | |
$_.rom.md5 -eq $md5 | |
} | |
return $game | |
} | |
#lookupGame Z:\Roms\DS\CNVPv01.nds | |
function list(){ | |
return $args | |
} | |
$romfolders = list 32X Amiga Atari CD-i ColecoVision Commodore DS Dreamcast ` | |
E-Reader GBA Gameboy Gamecube Intellivision Jaguar 'Master System' Megadrive N64 ` | |
NES 'Neo Geo Pocket' 'PC Engine' PC-98 PS2 PSP Playstation 'Pokemon Mini' SNES ` | |
Saturn 'Sega CD' TI-83 'Virtual Boy' Wii* WonderSwan ` | |
| % { | |
"Z:\Roms\$_" | |
} | |
gci $romfolders -Recurse | ? {-not $_.PSisContainer} | % { | |
if($_.extension -ne '.zip'){ | |
$game = lookupGame $_.fullname | |
if($game -ne $null){ | |
$game | add-member -passthru -force -membertype noteproperty -name filename -value $_.name | |
} | |
} | |
} | ft |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment