Last active
April 24, 2025 22:15
-
-
Save milnak/3be57b8ae57d6e03d5ff1131912ab29b to your computer and use it in GitHub Desktop.
MAME installation updater
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
if (-not (Get-Command -Name '7z.exe' -CommandType Application)) { | |
Write-Warning '7z.exe not found' | |
return | |
} | |
$output = ./mame.exe -version | |
# e.g. 0.275 (mame0275) | |
if ($output -notmatch '(?<friendly>\d+\.\d+) \((?<version>.+)\)') { | |
Write-Warning 'Unable to determine local MAME version. Expecting MAME.exe in current folder.' | |
return | |
} | |
$localMameFriendlyVer = $matches['friendly'] # e.g. '0.276' | |
$localMameVer = $matches['version'] # e.g. 'mame0276' | |
'Checking for update ...' | |
$response = (Invoke-WebRequest -Uri 'https://www.mamedev.org/release.php').Content | |
if ($response -notmatch '<a href="(?<url>https://github.com/mamedev/mame/releases/download)/(?<version>mame\d+)/(?<binary>mame\d+b_64bit.exe)">mame\d+b_64bit\.exe</a>') { | |
Write-Warning 'Unable to determine remote MAME version' | |
return | |
} | |
$url = $matches['url'] | |
$remoteMameVer = $matches['version'] | |
$binary = $matches['binary'] | |
if ($localMameVer -eq $remoteMameVer) { | |
"Local MAME ($localMameFriendlyVer) is up to date." | |
return | |
} | |
$tempFile = New-TemporaryFile | |
"Downloading $remoteMameVer to $tempFile ..." | |
Invoke-WebRequest -Uri "$url/$remoteMameVer/$binary" -OutFile $tempFile | |
$mamePath = (Get-Location).Path | |
"Extracting file to $mamePath ..." | |
Start-Process -Wait -NoNewWindow -FilePath '7z.exe' -ArgumentList 'x', '-bso0', '-y', "-o$mamePath", $tempFile | |
'Removing temporary file ...' | |
Remove-Item -LiteralPath $tempFile | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment