Jump to content
LaunchBox Community Forums

Script to automatically unzip CHD files correctly in MAME (on Windows only)


fab1o

Recommended Posts

Hi there, thought I could share my powershell script that auto extracts zipped CHDs into your mame roms folder for Windows 10 (It might work on previous versions but I didn't test it).

It's an automation script that follows this process: How to Get CHD Files to Work With MAME

Requirements:

  • 7-zip - you can download at 7-zip.org (located in your C:\Program Files\7-Zip, but you can change that in the script).
  • CHD zipped files, like the series of 0.221 CHD mame files for example from archive.org
  • My script - Download the script below. Make sure it is located in the same folder where you downloaded all the zipped CHD files. Also, make sure there's no other .7z file that is not a CHD in this folder.

There's two ways to run the script:

1st way:

  1. Right-click on the script file, choose Edit or Open / Notepad (whatever works).
  2. Change the $Destination to your own roms folder in mame. Save the file and close the editor.
  3. Right-click on it again, and choose Run with PowerShell.

Another way:

  1. Hit the Windows key in your keyboard and type: powershell then hit enter.
  2. Once in Powershell, go to the folder where you downloaded the script with the CHD zipped files by typing: cd "<your folder>"
    (for example: cd "C:\Users\Admin\Downloads") 
  3. Then execute the script by typing:  .\unzip_chd.ps1  -Destination "<your roms path folder>"
    (path where your roms folder is located, for example: .\unzip_chd.ps1  -Destination "C:\MAME\roms")
  4. If you receive an error message "File...cannot be loaded because running scripts is disabled on this system...", do this:
  5. Type: Set-ExecutionPolicy ByPass -Scope Process then type Y and hit enter. (This will be undone once you close Powershell)
  6. Now type:  .\unzip_chd.ps1  -Destination "<your roms path folder>"

Observations:

I'm NOT the author of CHD zipped files you may download online.

This script will unzip .7z files into the roms folder in mame (the one you typed in the script or command line) into their respective folders, enabling CHDs to work correctly.

If you downloaded CHD files that are not zipped with 7zip but with another extension (like .zip) then all you need to do is add -ext "zip" to the command:

.\unzip_chd.ps1  -Destination "<your roms path folder>" -ext "zip"

The script will delete each zipped file once everything is done. If for any reason you want to keep the original zipped files, remove line 19 from the script.

A version 2 of this script will be to read the roms you have in your roms folder in mame, find out if you don't have their respective CHD yet, and automatically download them. If anybody wants to help with this project, feel free to join me.

If the attached file below is unavailable, you can download it from (Right-click > Save as...) https://raw.githubusercontent.com/fab1o/unzip-chd/master/unzip_chd.ps1

 

 

unzip_chd.ps1

Edited by fab1o
Link to comment
Share on other sites

I have to ask why you are Zipping CHD files?  CHD files are already compressed to an equivalent compression ratio of Maximum within 7z.  So compressing can actually make the files larger than a standard CHD file.

1 hour ago, fab1o said:

CHD zipped files, like the series of 0.221 CHD mame files for example from archive.org

Also just in case people are unsure, Mame 0.221 does not exist as of yet.

image.thumb.png.0d358608d582f4e5aba80548261c759e.png

Just adding this image, the same chd compressed in 7zip at Maximum compression, is 1k larger than the chd itself, i know that size is not even worth bothering with, but its just a time waste imho for no gain other than adding an unpack step where there doesn't need to be one.

 

I guess getting them from other sources means they are 7z already which i find a little strange, so yeah the script can help a few people get to grips with it via a script, or just highlight all your 7zipped chds and bulk extract to mame folder using the context menu.

 

Edited by MadK9
Link to comment
Share on other sites

Hey @MadK9 I didn't create the CHDs zipped files. Those CHDs downloaded from archive.org are zipped, Because I believe some games have multiple CHD files. Take a look at Virtua Striker 4 "vs4" for instance. It's just easier to download 1 zip fle than multiple chd ones corresponding to the same rom (even thou the zip file might not necessarily help reducing the size in certain cases).

Just to be clear, for those wanting to download CHDs from archive.org, (not sure where other easier source for this is but anyhow..) if you type  "0.221 CHD mame" in the search bar, you can find latest version of CHDs - (even thou it's not really 221 - not sure why the author named this way, go figure) it's just a way you can find CHDs, and I just wanted to make it easier for everyone to find (I'm not the author of those CHD zipped files). The  "0.221 CHD mame" search is a working example. Go try it out.

I find archive.org to be a breeze to download CHDs.

In conclusion, the script will automatically unzip those CHD zipped files exacly the way they should be for mame to work with them. Otherwise, you will have to do this process manually. And it works with any version of CHDs you download online because it's simply a general script for extracting files in a certain way. As long as they are zipped.

I hope this helps.

 

Edited by fab1o
Link to comment
Share on other sites

Or you can always just download your CHD files from Pleasuredome in the correct format and not bother with any of this. Also last time I checked you can always just select multiple files at once right click them and have winrar or 7zip unpack them all to separate folders. Anyway thanks for sharing in case there are some people who may be downloading them from Archive

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...