Created
October 23, 2022 19:17
-
-
Save jsmolina/6d1c43341ad01571194a231629f1b70c to your computer and use it in GitHub Desktop.
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
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