UX improvements and better code comments

This commit is contained in:
Obie Hinojosa 2024-11-02 03:03:29 -07:00
parent e5a645f2cb
commit 370e4a7e33

View File

@ -3,6 +3,8 @@
# (wget is a dependency for this python script that doesnt come with python by default) # (wget is a dependency for this python script that doesnt come with python by default)
#import dependencies #import dependencies
import wget import wget
import tarfile import tarfile
@ -90,6 +92,13 @@ def check_for_old_mod_archive(filepath):
os.remove(filepath) os.remove(filepath)
#deletes old downloaded mod archives #deletes old downloaded mod archives
def compress_tar(folder_path, output_file):
with tarfile.open(output_file, "w:gz") as tar:
tar.add(folder_path, arcname=os.path.basename(folder_path))
#thank you google gemini you are a literal lifesaver
#detect operating system and find home, minecraft, & mod folders #detect operating system and find home, minecraft, & mod folders
homedir = os.path.expanduser("~") homedir = os.path.expanduser("~")
os.chdir(homedir) os.chdir(homedir)
@ -103,18 +112,29 @@ if platform.system() == "Linux":
os.chdir("/.minecraft") os.chdir("/.minecraft")
mcfolder = Path.cwd() mcfolder = Path.cwd()
modfolder = mcfolder + '/mods' modfolder = mcfolder + '/mods'
print("Changed current working directory to '" + str(mcfolder) + "'")
print("Backing up mod folder...")
print()
print("Don't close the window! This'll take a moment...")
compress_tar(mcfolder, "mod-backup.tar.gz")
elif platform.system() == "Windows": elif platform.system() == "Windows":
print("Operating system detected: Windows") print("Operating system detected: Windows")
os.chdir("AppData/Roaming/.minecraft") os.chdir("AppData/Roaming/.minecraft")
mcfolder = Path.cwd() mcfolder = Path.cwd()
print("Changed current working directory to '" + str(mcfolder) + "'")
win_check_folder_exists("mods") win_check_folder_exists("mods")
modfolder = str(mcfolder) + '/mods' modfolder = str(mcfolder) + '/mods'
print("Backing up mod folder...")
print()
print("Don't close the window! This'll take a moment...")
compress_tar(mcfolder, "mod-backup.tar.gz")
os.chdir(mcfolder) os.chdir(mcfolder)
print("Changed current working directory to '" + str(mcfolder) + "'")
time.sleep(2) time.sleep(2)
# unclear if this timeout is necessary for UX # unclear if this timeout is necessary for UX