Compare commits

...

14 Commits

Author SHA1 Message Date
6a2a102cf5 Merge pull request 'MERGE: Fully featured python installer and documentation/code comment improvements.' (#17) from untested into main
Reviewed-on: https://git.adolin.xyz/saru/lobotomy-mod-pack/pulls/17
2024-11-01 22:05:15 -05:00
fb6eeb5364 UX improvements and better code comments 2024-11-02 03:03:29 -07:00
5531d63870 add comments, add compilation instructions, upload image.ico 2024-11-02 02:44:42 -07:00
4976901191 add error handling in case mod folder doesn't exist
also now deletes previously downloaded tarballs
2024-10-30 23:02:27 -07:00
bda84a726f trim unnecessary code from os specific section 2024-10-30 21:48:12 -07:00
b4b604f685 this will drastically affect fishing season 2024-10-30 21:45:28 -07:00
2aeb553d64 update .gitignore 2024-10-30 21:39:50 -07:00
e2304cc847 Delete .vscode/settings.json 2024-10-30 16:37:51 -05:00
b915443ccf massive code refactor
most if not all functions were moved out of the main code body, lots of reformatting, whitespace and general spacing fixes, etc.
2024-10-30 21:33:57 -07:00
a4545bed16 trim redundant code under os specific operations 2024-10-30 21:08:00 -07:00
a0594137d1 refactor code snippets and concatenate os.chdir lines under os specific ops 2024-10-30 21:03:46 -07:00
210082ce3e update .gitignore and hide ascii art with collapsible function 2024-10-30 20:38:38 -07:00
fe72d9c8fe switch to wget over urllib 2024-10-30 20:20:36 -07:00
bb6a4d39c9 Merge pull request 'MERGE: Sync branch: "untested" with branch: "main"' (#13) from main into untested
Reviewed-on: https://git.adolin.xyz/saru/lobotomy-mod-pack/pulls/13
2024-10-28 22:01:44 -05:00
103 changed files with 140 additions and 86 deletions

3
.gitignore vendored
View File

@ -1,7 +1,8 @@
*.log *.log
*.env *.env
*.spec *.spec
test.py *.test.py
checklist.md checklist.md
/build /build
/dist /dist
/.*

BIN
image.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 422 KiB

View File

@ -1,115 +1,168 @@
import urllib # compiling this is easy, just run `pip install wget` and `pip install pyinstaller` and then...
import urllib.request # 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)
#import dependencies
import wget
import tarfile import tarfile
import os import os
import platform import platform
import time import time
import shutil import shutil
import sys
from pathlib import Path from pathlib import Path
#detect operating system and find home folder #define some functions ahead of time
homedir = os.path.expanduser("~") def delete_directory(directory):
try:
shutil.rmtree(str(directory))
except OSError as e:
print("Error: %s - %s." % (e.filename, e.strerror))
#this defines a function to delete a directory (no shit)
def extract_tar_archive(tar_file_path, extract_to):
with tarfile.open(tar_file_path, 'r') as tar:
tar.extractall(extract_to)
#this defines a function to decompress a tar.gz file
def ascii_art():
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()
#someone's gonna think im a furry or a femboy or some shit because of this.
def win_check_folder_exists(folder):
dir = os.path.normpath(str(Path.cwd()) + "/" + str(folder))
# fuck you microsoft
# this is some high-tier BULLSHIT right here
#print(dir)
if not os.path.exists(dir):
print()
print("[WARN!]: Mod folder not found. (is Fabric installed?)")
print("[WARN!]: (note: the script WILL KEEP GOING ANYWAYS and the mods directory will be MADE AUTOMATICALLY, but")
print("[WARM!]: if you don't have fabric, the mods won't be loaded and you won't be able to join the server.)")
print()
print("[WARN!] THIS IS NOT A FATAL ERROR! DON'T CLOSE THE WINDOW!")
os.mkdir("mods")
print()
time.sleep(20)
#checks for mod folder existence and outputs [WARN!]
def check_for_old_mod_archive(filepath):
if os.path.exists(filepath):
print("Found previously downloaded archive, deleting... Done.")
#shut up
os.remove(filepath)
#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
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.
#operating system specific operations.
#we find the minecraft folder in this section.
if platform.system() == "Linux": if platform.system() == "Linux":
print("Operating system detected: Linux") print("Operating system detected: Linux")
global mcfolder os.chdir("/.minecraft")
global modfolder
os.chdir(homedir + '/.minecraft')
mcfolder = Path.cwd() mcfolder = Path.cwd()
modfolder = homedir + '/.minecraft/mods' modfolder = mcfolder + '/mods'
os.chdir(mcfolder)
print("Changed current working directory to '" + str(mcfolder) + "'") print("Changed current working directory to '" + str(mcfolder) + "'")
time.sleep(2)
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(homedir) os.chdir("AppData/Roaming/.minecraft")
os.chdir("AppData")
os.chdir("Roaming")
os.chdir(".minecraft")
mcfolder = Path.cwd() mcfolder = Path.cwd()
os.chdir("mods")
modfolder = Path.cwd
os.chdir(mcfolder)
print("Changed current working directory to '" + str(mcfolder) + "'") print("Changed current working directory to '" + str(mcfolder) + "'")
time.sleep(2)
os.chdir(mcfolder) win_check_folder_exists("mods")
#begin mod backup and deletion modfolder = str(mcfolder) + '/mods'
#THIS DOESN'T CURRENTLY BACK UP EXISTING MODS.
try:
shutil.rmtree(str("mods"))
print("Cleared previous mods.")
except OSError as e:
print("Error: %s - %s." % (e.filename, e.strerror))
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")
#custom function*
print("Deleting mod folder contents... Done.")
#shut up again
os.mkdir(str("mods")) os.mkdir(str("mods"))
#begin download and extract # download mod archive from https://git.adolin.xyz/saru and extract
#this snippet below defines a tar extract FUNCTION
def extract_tar_archive(tar_file_path, extract_to):
with tarfile.open(tar_file_path, 'r') as tar:
tar.extractall(extract_to)
print("Starting install...")
print("Fetching mods...") print("Fetching mods...")
#this is the SIMPLEST implementation of curl i have ever seen i just NUTTED SO FUCKING HARD wget.download('https://git.adolin.xyz/saru/lobotomy-mod-pack/raw/branch/main/mods.tar.gz')
url = 'https://git.adolin.xyz/saru/lobotomy-mod-pack/raw/branch/main/mods.tar.gz' # #this is the SIMPLEST implementation of curl i have ever seen i just NUTTED SO FUCKING HARD
urllib.request.urlretrieve(url, 'mods.tar.gz') # take the last one back, this is fucking insane. `wget` the fucking goat. who knew windows package manager was so damn cool?
print("Extracting and writing to disk...") extract_tar_archive('mods.tar.gz', 'mods')
# ('tarfile', 'directory to extract to')
tar_file_path = 'mods.tar.gz' ascii_art()
extract_to = 'mods' #call func to print ascii art to console
extract_tar_archive(tar_file_path, extract_to)
print("sigma!")
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(" ....")
#someone's gonna think im a furry or a femboy or some shit because of this.
print()
print("sigma")
print("all done!") print("all done!")
print("This script will exit and close in ten seconds. :)") print("This windows will exit and close in ten seconds. :)")
time.sleep(10) time.sleep(10)

Some files were not shown because too many files have changed in this diff Show More