Advertisement
Guest User

recalbox-systems.py

a guest
Jul 27th, 2017
2,318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.48 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from hashlib import md5
  4. from os.path import isfile
  5.  
  6. systems = {
  7.     "atari7800": { "name": "Atari 7800",                           "biosFiles": [ { "md5": "0763f1ffb006ddbe32e52d497ee848ae", "file": "bios/7800 BIOS (U).rom" } ] },
  8.     "atarist":   { "name": "Atari ST",                             "biosFiles": [ { "md5": "b2a8570de2e850c5acf81cb80512d9f6", "file": "bios/tos.img"           } ] },
  9.     "dreamcast": { "name": "Dreamcast",                            "biosFiles": [ { "md5": "e10c53c2f8b90bab96ead2d368858623", "file": "bios/dc_boot.bin"       },
  10.                                                                                   { "md5": "0a93f7940c455905bea6e392dfde92a4", "file": "bios/dc_flash.bin"      } ] },
  11.     "fds":       { "name": "Nintendo Family Computer Disk System", "biosFiles": [ { "md5": "ca30b50f880eb660a320674ed365ef7a", "file": "bios/disksys.rom"       } ] },
  12.     "gba":       { "name": "Game Boy Advance",                     "biosFiles": [ { "md5": "a860e8c0b6d573d191e4ec7db1b1e4f6", "file": "bios/gba_bios.bin"      } ] },
  13.     "lynx":      { "name": "Lynx",                                 "biosFiles": [ { "md5": "fcd403db69f54290b51035d82f835e7b", "file": "bios/lynxboot.img"      } ] },
  14.     "msx":       { "name": "MSX",                                  "biosFiles": [ { "md5": "d6dedca1112ddfda94cc9b2e426b818b", "file": "bios/CARTS.SHA"         },
  15.                                                                                   { "md5": "85b38e4128bbc300e675f55b278683a8", "file": "bios/CYRILLIC.FNT"      },
  16.                                                                                   { "md5": "80dcd1ad1a4cf65d64b7ba10504e8190", "file": "bios/DISK.ROM"          },
  17.                                                                                   { "md5": "af8537262df8df267072f359399a7635", "file": "bios/FMPAC16.ROM"       },
  18.                                                                                   { "md5": "6f69cc8b5ed761b03afd78000dfb0e19", "file": "bios/FMPAC.ROM"         },
  19.                                                                                   { "md5": "c83e50e9f33b8dd893c414691822740d", "file": "bios/ITALIC.FNT"        },
  20.                                                                                   { "md5": "febe8782b466d7c3b16de6d104826b34", "file": "bios/KANJI.ROM"         },
  21.                                                                                   { "md5": "2183c2aff17cf4297bdb496de78c2e8a", "file": "bios/MSX2EXT.ROM"       },
  22.                                                                                   { "md5": "7c8243c71d8f143b2531f01afa6a05dc", "file": "bios/MSX2PEXT.ROM"      },
  23.                                                                                   { "md5": "6d8c0ca64e726c82a4b726e9b01cdf1e", "file": "bios/MSX2P.ROM"         },
  24.                                                                                   { "md5": "ec3a01c91f24fbddcbcab0ad301bc9ef", "file": "bios/MSX2.ROM"          },
  25.                                                                                   { "md5": "6418d091cd6907bbcf940324339e43bb", "file": "bios/MSXDOS2.ROM"       },
  26.                                                                                   { "md5": "aa95aea2563cd5ec0a0919b44cc17d47", "file": "bios/MSX.ROM"           },
  27.                                                                                   { "md5": "403cdea1cbd2bb24fae506941f8f655e", "file": "bios/PAINTER.ROM"       },
  28.                                                                                   { "md5": "279efd1eae0d358eecd4edc7d9adedf3", "file": "bios/RS232.ROM"         } ] },
  29.     "neogeo":    { "name": "NeoGeo",                               "biosFiles": [ { "md5": "5765698aed250f054658e8598c0e4975", "file": "roms/neogeo/neogeo.zip" } ] },
  30.     "o2em":      { "name": "Odyssey 2",                            "biosFiles": [ { "md5": "562d5ebf9e030a40d6fabfc2f33139fd", "file": "bios/o2rom.bin"         } ] },
  31.     "pcengine":  { "name": "PC Engine",                            "biosFiles": [ { "md5": "ff1a674273fe3540ccef576376407d1d", "file": "bios/syscard3.pce"      } ] },
  32.     "psx":       { "name": "PSX",                                  "biosFiles": [ { "md5": "924e392ed05558ffdb115408c263dccf", "file": "bios/SCPH1001.BIN"      },
  33.                                                                                   { "md5": "239665b1a3dade1b5a52c06338011044", "file": "bios/SCPH1000.BIN"      },
  34.                                                                                   { "md5": "490f666e1afb15b7362b406ed1cea246", "file": "bios/SCPH7003.BIN"      } ] },
  35.     "saturn":    { "name": "Sega Saturn",                          "biosFiles": [ { "md5": "3240872c70984b6cbfda1586cab68dbe", "file": "bios/saturn_bios.bin"   } ] },
  36.     "sega32x":   { "name": "Sega 32x",                             "biosFiles": [ { "md5": "6a5433f6a132a2b683635819a6dcf085", "file": "bios/32X_G_BIOS.BIN"    },
  37.                                                                                   { "md5": "f88354ec482be09aeccd76a97bb75868", "file": "bios/32X_M_BIOS.BIN"    },
  38.                                                                                   { "md5": "7f041b6a55cd7423a6c08a219335269e", "file": "bios/32X_S_BIOS.BIN"    } ] },
  39.     "segacd":    { "name": "Sega CD",                              "biosFiles": [ { "md5": "854b9150240a198070150e4566ae1290", "file": "bios/us_scd2_9306.bin"  },
  40.                                                                                   { "md5": "d8b8b720dea6c6ba25c309ed633930f4", "file": "bios/eu_mcd2_9306.bin"  },
  41.                                                                                   { "md5": "bdeb4c47da613946d422d97d98b21cda", "file": "bios/jp_mcd1_9112.bin"  } ] }
  42. }
  43.  
  44. class BiosStatus:
  45.     MISSING = "MISSING"
  46.     INVALID = "INVALID"
  47.  
  48. def md5sum(filename, blocksize=65536):
  49.     hash = md5()
  50.     with open(filename, "rb") as f:
  51.         for block in iter(lambda: f.read(blocksize), b""):
  52.             hash.update(block)
  53.     return hash.hexdigest()
  54.  
  55. def checkBios(systems, prefix):
  56.     missingBios = {}
  57.     for system in systems.keys():
  58.         for file in systems[system]["biosFiles"]:
  59.             filepath = prefix + "/" + file["file"]
  60.             if isfile(filepath):
  61.                 md5 = md5sum(filepath)
  62.                 if md5 != file["md5"] and file["md5"] != "":
  63.                     if system not in missingBios:
  64.                         missingBios[system] = {}
  65.                     missingBios[system][file["file"]] = { "status": BiosStatus.INVALID, "md5": file["md5"], "file": file["file"] }
  66.             else:
  67.                 if system not in missingBios:
  68.                     missingBios[system] = {}
  69.                 missingBios[system][file["file"]] = { "status": BiosStatus.MISSING, "md5": file["md5"], "file": file["file"] }
  70.     return missingBios
  71.  
  72. def displayMissingBios(systems, missingBios):
  73.     if missingBios:
  74.         for system in missingBios:
  75.             print "> {}".format(systems[system]["name"])
  76.             for file in missingBios[system].keys():
  77.                 md5str = "-"
  78.                 if missingBios[system][file]["md5"] != "":
  79.                     md5str = missingBios[system][file]["md5"]
  80.                 print "{} {} {}".format(missingBios[system][file]["status"], md5str, missingBios[system][file]["file"])
  81.     else:
  82.         print "No missing bios"
  83.  
  84. if __name__ == '__main__':
  85.     prefix = "/recalbox/share"
  86. displayMissingBios(systems, checkBios(systems, prefix))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement