190 lines
6.9 KiB
Python
190 lines
6.9 KiB
Python
# -----------------------read me?---------------------------
|
|
|
|
|
|
# compiling this is super easy, just run `pip install wget` and `pip install pyinstaller` and then
|
|
# compile with `python -m PyInstaller --onefile installer.py --icon image.ico`
|
|
|
|
# (wget is a dependency for this python script that doesnt come with python by default)
|
|
# (and pyinstaller is the packagey thingamajig that compiles the code into an executable.)
|
|
|
|
# also, peep the organized code blocks!! am i cool or what?
|
|
|
|
# something worthy of note: this code desperately needs to be refactored. right now literally
|
|
# everything important happens under a big if elif statement and its pretty fucking stupid
|
|
|
|
|
|
# -----------------import dependencies----------------------
|
|
|
|
|
|
import wget; import os; import platform; import time
|
|
|
|
import shutil; import tarfile
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
# -----------define some functions ahead of time------------
|
|
|
|
|
|
# idea! consolidate both delete things and add an extra option to the functions that toggles-
|
|
# -error outputs using an if statement in the function's code `if quiet = true then... else...`
|
|
|
|
# as far as i can tell, i wanted to add an "option" to the function that toggled the warning m-
|
|
# -essage, so i dont have to use all this space here defining functions i dont really need.
|
|
|
|
def delete_directory_warn(directory_to_delete, warn=False):
|
|
#this defines a function to delete a directory (no shit)
|
|
try:
|
|
shutil.rmtree(str(directory_to_delete))
|
|
except OSError as e:
|
|
print("[ERR!]: %s - %s." % (e.filename, e.strerror))
|
|
|
|
def delete_file_warn(file_to_delete):
|
|
#this defines a function to delete a file (no shit)
|
|
try:
|
|
os.remove(str(file_to_delete))
|
|
except OSError as e:
|
|
print("[ERR!]: %s - %s." % (e.filename, e.strerror))
|
|
|
|
def delete_directory(directory_to_delete):
|
|
#this defines a function to delete a directory (without any warnings)
|
|
try:
|
|
shutil.rmtree(str(directory_to_delete))
|
|
except:
|
|
pass
|
|
|
|
def delete_file(file_to_delete):
|
|
#this defines a function to delete a file (without any warnings)
|
|
try:
|
|
os.remove(str(file_to_delete))
|
|
except:
|
|
pass
|
|
|
|
def compress_tar(folder_path, output_file):
|
|
#this defines a function to compress a folder into a tarball
|
|
with tarfile.open(output_file, "w:gz") as tar:
|
|
tar.add(folder_path, arcname=os.path.basename(folder_path))
|
|
#gemini lowkey slayed w this one
|
|
|
|
def extract_tar(tar_file_path, extract_to):
|
|
#this defines a function to decompress a tar.gz file
|
|
with tarfile.open(tar_file_path, 'r') as tar:
|
|
tar.extractall(extract_to)
|
|
|
|
def print_ascii_art():
|
|
#someone's gonna think im a furry or a femboy or some shit because of this.
|
|
print()
|
|
print()
|
|
print(" :+++++=")
|
|
print(" -++++++.")
|
|
print(" :++++++. .")
|
|
print(" .++++++. -=. -: .::")
|
|
print(" =+++++. :=. =- .--:. -")
|
|
print(" =+++++. .+ =: -=. :=")
|
|
print(" =+++++. +. :.=* .=: =:")
|
|
print(" =++++= .+ +. -- :+ .=")
|
|
print(" .+++++= .= ..=: :. =")
|
|
print(" .++=++- .= .+- =")
|
|
print(" ==++*=::.. * +")
|
|
print(" =*#-+- .:---:. :=-- .-=%. --=#- ..::.--")
|
|
print(" :#=-*- .::--:.*: .+ #@. - *@@- .. -#:")
|
|
print(" ++:*. .:--==:--:: .%%-.. :=.")
|
|
print(" =++.:...::::::..... :---+-:. .:.: --")
|
|
print(" *=..:::.. .=.")
|
|
print(" :-. .=:::")
|
|
print(" ..:=. :-..-:---:")
|
|
print(" ==:- .=-: :=-")
|
|
print(" .= =- :--. .--")
|
|
print(" -- :-:. -= .::::-:=.")
|
|
print(" :- =- :+ .+")
|
|
print(" --- -: .+ +.")
|
|
print(" := -= .+ =:")
|
|
print(" +. -: =: :=.")
|
|
print(" -. .=: --.....::-:")
|
|
print(" .=- .= :-:----- .::::.")
|
|
print(" .-: .= ..+:")
|
|
print(" -=......:.:-:+ :=")
|
|
print(" .::--::... := -")
|
|
print(" =: =:")
|
|
print(" --::.--")
|
|
print(" ....")
|
|
print()
|
|
|
|
def checkfor_and_delete_file(filepath):
|
|
#deletes old downloaded mod archives
|
|
if os.path.exists(filepath):
|
|
print("Found previously downloaded archive, deleting...")
|
|
os.remove(filepath)
|
|
|
|
|
|
# --------------------the real shit!------------------------
|
|
|
|
|
|
#detect operating system and find home, minecraft, & mod folders
|
|
homedir = os.path.expanduser("~")
|
|
os.chdir(homedir)
|
|
|
|
global mcfolder
|
|
global modfolder
|
|
# `global` sets these variables to exist outside of the scope of these specific `if` statements.
|
|
|
|
if platform.system() == "Linux":
|
|
print("Operating system detected: Linux")
|
|
os.chdir("/.minecraft")
|
|
mcfolder = Path.cwd()
|
|
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":
|
|
print("Operating system detected: Windows")
|
|
os.chdir("AppData/Roaming/.minecraft")
|
|
mcfolder = Path.cwd()
|
|
print("Changed current working directory to '" + str(mcfolder) + "'")
|
|
|
|
win_check_folder_exists("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)
|
|
time.sleep(2)
|
|
# unclear if this timeout is necessary for UX
|
|
|
|
# clear out preexisting mods
|
|
check_for_old_mod_archive("mods.tar.gz")
|
|
delete_directory("mods")
|
|
print("Deleting mod folder contents... Done.")
|
|
#shut up
|
|
os.mkdir(str("mods"))
|
|
|
|
|
|
|
|
# download mod archive from git repo and extract
|
|
print("Fetching mods...")
|
|
wget.download('https://git.sarushinobie.dev/saru/family-minecraft-modpack/releases/download/0.0.1/mods.tar.gz')
|
|
# this is insane. `wget` the fucking goat. who knew windows package manager was so cool?
|
|
|
|
extract_tar_archive('mods.tar.gz', 'mods')
|
|
# ('tarfile', 'directory to extract to')
|
|
|
|
ascii_art()
|
|
# print boykisser to console
|
|
|
|
print("sigma!")
|
|
print("all done!")
|
|
print("This window will exit and close in ten seconds. :)")
|
|
time.sleep(10)
|
|
|
|
|
|
# --------------------the real shit!------------------------
|
|
|