Skip to content

Instantly share code, notes, and snippets.

@jsmolina
Created October 23, 2022 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsmolina/6d1c43341ad01571194a231629f1b70c to your computer and use it in GitHub Desktop.
Save jsmolina/6d1c43341ad01571194a231629f1b70c to your computer and use it in GitHub Desktop.
import os, glob
import shutil
import string
# generates RLOADER https://github.com/marco-sacchi/RLoader LIST.txr
translation_table = dict.fromkeys(map(ord, ' [](),.~!@#$%^&*{}: '), None)
OUT = "/Users/jordism/Downloads/DOS/GAMES"
ROOT = ["./DIST/games1",
"./games2",
"./games3"]
DOSnames = []
def dir_to_dos(longname):
# FAT12 doesn't support unicode - avert thine eyes
dname = longname.encode('ascii', 'ignore').decode()
# Truncate basename while keeping extension
if len(longname) > 12:
dname = dname.translate(translation_table)
dname = str.upper(dname)
dname = dname[0:8]
dname = dname.replace(" ", "")
collided = dname
# Do we have a collision?
if dname in DOSnames:
for i in string.ascii_uppercase + string.digits:
dname = longname.translate(translation_table) + i
dname = str.upper(dname)
dname = dname[0:8]
if dname not in DOSnames:
break
else:
# If we still have a collision, we need to mangle the name some more
for i in string.ascii_uppercase + string.digits:
for j in string.ascii_uppercase + string.digits:
oldname = dname
dname = longname.translate(translation_table)[0:6] + i + j + longname[-4:]
dname = str.upper(dname)
if dname not in DOSnames:
break
if dname not in DOSnames:
break
# If we got here, too many collisions (need more code!)
if dname in DOSnames:
print("Namespace collision converting", longname, "to", dname)
print("Ask the progammer to enhance the collision algorithm.")
exit(8)
dname = dname[0:8]
dname = dname.replace(" ", "")
DOSnames.append(dname)
return dname
def find_executable(directory):
for w in os.listdir(directory):
filename = w.lower()
if filename.endswith(".exe") or filename.endswith(".bat") or filename.endswith(".com"):
return w
def main():
with open("LIST.txt", "wb") as f:
f.write(f"#path\texecutable\tsetup\r\n".encode('utf-8'))
for origin in ROOT:
for dirname in os.listdir(origin):
if dirname.startswith("."):
continue
fulldirpath = os.path.join(origin, dirname)
executable = find_executable(fulldirpath)
shortname = dir_to_dos(dirname)
f.write(f"c:\games\{shortname}\t{executable}\tsetup.exe".encode('utf-8'))
f.write(b"\r\n")
#shutil.copytree(fulldirpath, os.path.join(OUT, shortname))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment