diff --git a/mmm-nsf-changer.py b/mmm-nsf-changer.py index f83333e..a2d78b9 100644 --- a/mmm-nsf-changer.py +++ b/mmm-nsf-changer.py @@ -4,6 +4,7 @@ from glob import glob import shutil import pathlib import filecmp +import webbrowser ##Here goes the actual code @@ -22,10 +23,12 @@ def safelist(): #add -def check_folder_structure(megamaker_folder): +def check_folder_structure(megamaker_folder, og_music=False): megamaker_folder = os.path.abspath(megamaker_folder) subfolders = ([ f.path for f in os.scandir(megamaker_folder) if f.is_dir() ]) music_folder = f"{megamaker_folder}/Music" + if og_music: + music_folder = f"{megamaker_folder}/original_music" file_names = [] if music_folder in subfolders: file_paths = (glob(f"{music_folder}/*/*.nsf")) @@ -43,7 +46,11 @@ def move_music_to_ogmusic(path): path = os.path.abspath(path) original_filepaths = check_folder_structure(path) if original_filepaths: - shutil.move(f"{path}/Music", f"{path}/original_music") + if not filecmp.cmp(f'{path}/Music/MM1/Cutman.nsf', f'{path}/Music/MM1/Oilman.nsf', shallow=False): + shutil.move(f"{path}/Music", f"{path}/original_music") + else: + print("Cutman.nsf and Oilman.nsf match in Music folder.") + return False if not os.path.exists(f"{path}/Music"): os.makedirs(f"{path}/Music") @@ -58,41 +65,67 @@ def restore_ogmusic(path): if os.path.exists(f"{path}/original_music"): if os.path.exists(f'{path}/Music'): if check_folder_structure(f"{path}"): - if not filecmp.cmp(f'{path}/Music/MM1/Cutman.nsf', f'{path}/original_music/MM1/Cutman.nsf', shallow=False): - shutil.rmtree(f"{path}/Music") - shutil.move(f"{path}/original_music/", f"{path}/Music") + if check_folder_structure(f"{path}", og_music=True): + if not filecmp.cmp(f'{path}/Music/MM1/Cutman.nsf', f'{path}/original_music/MM1/Cutman.nsf', shallow=False): + shutil.rmtree(f"{path}/Music") + shutil.move(f"{path}/original_music/", f"{path}/Music") + return True + else: + print("something went wrong...") else: - print("something went wrong...") + return False + else: + return False + else: + return False + else: + return False def nsf_changer (nsf_path, megamaker_folder): original_path = check_folder_structure(megamaker_folder) if original_path: move_music_to_ogmusic(megamaker_folder) recreate_structure(nsf_path, original_path) + return True + else: + return False - +sg.theme('LightBlue') +gif = b"R0lGODdhQgAmAHcAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQJCgAAACwAAAAAQgAmAIAAAAAAefsCzISPqcvtD6OctNqLs95chg92YgOGT/mNExpArOqhrgzPpW3WznvSHM8AknwbocK4QGKUBybCWYFCDdMV8XhNZpfbZvf5BUjD1fFteA6GqeR2WvtWxxPmHNwux9PdevAc++cVyDYotmZYWJeCaFLGt5i3yON4NvnYwih5aFl5Sdi4ScPZJwjaeWo3qpko2ooKmYmpKutqaruaWou7S/vae4v5ySv8OxxLjFxqPJvMfKxcHN2sK/087XsNnA3r3E29HfzsjS3+rXOOnn5QAAAh+QQJCgAAACwCAAYAPgAeAIAAAAAAefsClYSPqcvtD6OctNqLcw28a9R5W0hy31FaZXoCLLWSrSuPsdm+0y2eusTD+Wqw4OwXCQaOxJ0x1wQ+hyHV9IOEKJlV243bc/IM2QerTH6iG+doYkvrFrtr+JrRli/stXr/T6cGGKaQJ2IYkxa4eDiIg7ii2Mj46LgUN/mFWUl5CSnJqfm56WkJWjpGerqq2go5CmvqSlIAACH5BAkKAAAALAIABgA+AB4AgAAAAAB5+wKthI+pF+0Lo5zTPYqzBrbtDyZdEJbfaKYYqm4s9C5xOYudVIM5c0e724MFZUNaj/XjFEPI4xKRzDQthqT1qaRmL1et0GvTTi9fMhEMdYqxVfbWc+aqzYounbfO39Po8P5NAtjWxyenB1c3B2e3qBiYeBjIKOlY1hiJUykYd2n4N+jZiegnSkmIF2o6kgpa2qrqCjgWOwtr+1r7qruZK6vZC+wYjMn7u0o8zFpsUQAAIfkECQoAAAAsAgAGAD4AHgCAAAAAAHn7AqGEb6GL7Q+jfIvNi3OrSvsPcQFIkmKJAifFpaW4ru4Ht6o9e3WV4K7M2o1uvBzQIewQLbPjJtkrNn1I6FI5LcaszpdtK4wyf99y+DrMWsA7MVbDVsZh7jTcvMbX6vzIvJ809OenJ1g42HWAeFjYF9KIVrcoFZSnxXiZOValKYdpCerZaTgqCTkZSpqKKpoK+Nkaqyr7Oso6i1u7espbGolWAAAh+QQJCgAAACwCAAgAPgAcAIAAAAAAefsCooSPCcGtD6OcqTmKs142bNl5nxKOUGkiaKp27LG+nCXPVx2nObuPvfnbBD/DzPDokiFpkd/y9ngyDCGp6JTEMqvZaJf0rSS5TC0UXPZuydPm+J1GX9htcxtlpdJB8Hm4tcbGF+gXJ0bIpYcogvcH05docwfJ6KhYSHY5uah5pYYZ2cgp6Sm3mUnaqZrKKorqehpbOUo3C2oruwpbpUvZS9tRAAA7" layout = [ + [sg.Text("Mega Man Maker NSF Music Changer | Made by Timothy GFO", justification="center")], + [sg.Text("YouTube", enable_events = True, key="-YT-", text_color="red"), sg.Text("GitLab",enable_events = True,key="-GIT-", text_color="purple"), sg.Text("Blog",enable_events = True,key="-SITE-", text_color="blue")], [sg.Text("Input NSF File:"), sg.Input(key="-IN-"),sg.FileBrowse(file_types=(("NSF Files", "*.nsf*"),))], [sg.Text("MegaMaker Folder:"), sg.Input(key="-OUT-"), sg.FolderBrowse()], - [sg.Exit(), sg.Button("Replace NSF Music"), sg.Button("Restore Original Music")], + [sg.Exit(),sg.Button("About") , sg.Button("Replace NSF Music"), sg.Button("Restore Original Music"), sg.Image(data=gif, key='_IMAGE_')], ] -window = sg.Window("MMM NSF Changer", layout, resizable=True) -while True: +how_to_use = "I made this tool to be able to change the music for any Mega Man Maker level while playing the game. It works by replacing every nsf file with a custom one, but while preserving the original folders and file names.\n\nTo use it, just choose a nsf file and then tell the program where you store the *game* folder. That is where the .exe is, not the user folder.\n\nIf you find this useful, you can check out my YouTube Channel or my blog since I will keep making tools like this. Also, if you find any bugs or errors remember to notify me at GitLab by making an Issue." - disclaimer = sg.popup_yes_no('NSF Changer, by Timothy GFO', 'This program is not complete, there WILL be bugs. Use at your own risk.', 'Do you want to continue?') - if disclaimer == "Yes": - event,values = window.read() - if event in (sg.WINDOW_CLOSED,"Exit"): - break - if event == "Replace NSF Music": - #sg.popup_error("DOESNT WORK HAHAHAA") - nsf_changer(values["-IN-"], values["-OUT-"]) - #recreate_structure(values["-IN-"], values["-OUT-"]) - if event == "Restore Original Music": - # sg.popup_error("DOESNT WORK EITHER HAHAHAHAHAHAA") - restore_ogmusic(values["-OUT-"]) - else: + +window = sg.Window("MMM NSF Music Changer v1.0", layout, grab_anywhere=True) +disclaimer = sg.popup_yes_no('NSF Changer, by Timothy GFO', 'This program is not complete, there WILL be bugs. Use at your own risk.', 'Do you want to continue?') +while disclaimer == "Yes": + event,values = window.read(timeout=50) + if event in (sg.WINDOW_CLOSED,"Exit"): break + window.Element('_IMAGE_').UpdateAnimation(gif, time_between_frames=100) + if event == "-YT-": + webbrowser.open("https://youtube.com/gamefeveronline") + if event == "-SITE-": + webbrowser.open("https://gamefeveronline.gitlab.io") + if event == "-GIT-": + webbrowser.open("https://gitlab.com/gamefeveronline") + if event == "About": + sg.popup(how_to_use) + if event == "Replace NSF Music": + if not nsf_changer(values["-IN-"], values["-OUT-"]): + restore_ogmusic(values["-OUT-"]) + if not nsf_changer(values["-IN-"], values["-OUT-"]): + sg.popup_error("MegaMaker folder is not valid or definitions out of date.") + if event == "Restore Original Music": + # sg.popup_error("DOESNT WORK EITHER HAHAHAHAHAHAA") + if not restore_ogmusic(values["-OUT-"]): + sg.popup_error("Unexpected folder structure or differing") window.close()