Skip to content

Instantly share code, notes, and snippets.

@ligfx
Created June 9, 2020 01:25
Show Gist options
  • Save ligfx/8e8ba516df00024ebb5eb3f1d48cfeee to your computer and use it in GitHub Desktop.
Save ligfx/8e8ba516df00024ebb5eb3f1d48cfeee to your computer and use it in GitHub Desktop.
what's in this zip file
# encoding: utf-8
import os.path
import sys
import zipfile
def file_to_gamenames(filename, f):
extension = filename.split(".")[-1].lower()
if extension == "spr":
return ("C1",)
if extension == "s16":
return ("C2", "C3")
if extension == "c16":
return ("C3",)
if extension == "blk":
return ("C3",)
if extension == "rcb":
return ("C1",)
if extension == "cob":
if f.read(4) == "COB2":
return ("C2",)
else:
return ("C1",)
return ()
def main():
if len(sys.argv) != 3 or sys.argv[1] != "--gamename":
sys.stderr.write("USAGE: {} --gamename FILE\n".format(sys.argv[0]))
exit(1)
filename = sys.argv[2]
sys.stderr.write("Checking file {}...\n".format(repr(filename)))
if not os.path.exists(filename):
sys.stderr.write("File {} does not exist!\n".format(repr(filename)))
exit(1)
if filename.lower().endswith(".zip"):
is_c1 = True
is_c2 = True
is_c3 = True
with zipfile.ZipFile(filename) as zf:
for name in zf.namelist():
with zf.open(name) as f:
gamenames = file_to_gamenames(name, f)
sys.stderr.write("- {} -> {}\n".format(repr(name), gamenames))
if gamenames:
is_c1 = is_c1 and "C1" in gamenames
is_c2 = is_c2 and "C2" in gamenames
is_c3 = is_c3 and "C3" in gamenames
if int(is_c1) + int(is_c2) + int(is_c3) != 1:
print("Unknown")
elif is_c1:
print("C1")
elif is_c2:
print("C2")
elif is_c3:
print("C3")
else:
sys.stderr.write("File {} is not a zip file".format(repr(filename)))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment