Upload files to "/"
This commit is contained in:
109
p7mc.py
Normal file
109
p7mc.py
Normal file
@@ -0,0 +1,109 @@
|
||||
import minecraft_launcher_lib
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
# --- PROGRESS BAR CALLBACKS ---
|
||||
current_max = 0
|
||||
|
||||
def set_status(status: str):
|
||||
if status: print(f"{status}")
|
||||
|
||||
def set_progress(progress: int):
|
||||
if current_max != 0:
|
||||
percentage = int((progress / current_max) * 100)
|
||||
print(f"- Progress: [{percentage}%] {progress}/{current_max} files", end="\r")
|
||||
|
||||
def set_max(new_max: int):
|
||||
global current_max
|
||||
current_max = new_max
|
||||
|
||||
def list_local_versions(dir):
|
||||
print("\nExisting Versions")
|
||||
if not os.path.exists(dir):
|
||||
print("[None]")
|
||||
return
|
||||
local = minecraft_launcher_lib.utils.get_installed_versions(dir)
|
||||
if not local:
|
||||
print("[None]")
|
||||
else:
|
||||
for v in local:
|
||||
print(f" - {v['id']}")
|
||||
|
||||
# --- FIXED DIRECTORY LOGIC ---
|
||||
# This forces the folder to be in your 'P7MC' folder on the Desktop
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
minecraft_directory = os.path.join(script_dir, "minecraft")
|
||||
|
||||
# Create the folder immediately so you can see it in VSCode
|
||||
os.makedirs(minecraft_directory, exist_ok=True)
|
||||
|
||||
while True:
|
||||
try:
|
||||
print("\n" + "=" * 40)
|
||||
print("P7MC - P7MJ's MC Launcher")
|
||||
print(f"Path: {minecraft_directory}") # Debug line to show you the location
|
||||
print("=" * 40)
|
||||
choice = input("[1] Launch\n[2] Install\n[f] Open Folder\n[h] Help (For common errors)\n[e] Exit\n > ").strip().lower()
|
||||
|
||||
if choice == "e":
|
||||
break
|
||||
|
||||
# Opens the folder in File Explorer for you
|
||||
if choice == "f":
|
||||
os.startfile(minecraft_directory)
|
||||
continue
|
||||
|
||||
# --- INSTALLATION FLOW ---
|
||||
if choice == "2":
|
||||
list_local_versions(minecraft_directory)
|
||||
print("Type a version, or \"latest\" for the latest release.")
|
||||
version = input("Version > ").strip()
|
||||
|
||||
if version.lower() == "latest":
|
||||
version = minecraft_launcher_lib.utils.get_latest_version()["release"]
|
||||
|
||||
callback = {"setStatus": set_status, "setProgress": set_progress, "setMax": set_max}
|
||||
print(f"[*] Downloading and installing {version}...")
|
||||
minecraft_launcher_lib.install.install_minecraft_version(version, minecraft_directory, callback=callback)
|
||||
print("\nInstall complete!")
|
||||
|
||||
# --- LAUNCH FLOW ---
|
||||
elif choice == "1":
|
||||
list_local_versions(minecraft_directory)
|
||||
version = input("Version > ").strip()
|
||||
|
||||
# GET THE LOCAL VERSIONS LIST
|
||||
local_versions = minecraft_launcher_lib.utils.get_installed_versions(minecraft_directory)
|
||||
# CHECK IF THE TYPED VERSION IS IN THAT LIST
|
||||
is_installed = any(v['id'] == version for v in local_versions)
|
||||
|
||||
if not is_installed:
|
||||
print(f"[!] Error: {version} not found in local folder. Please install it first.")
|
||||
continue
|
||||
|
||||
username = input("Username > ").strip()
|
||||
|
||||
options = {
|
||||
"username": username,
|
||||
"uuid": "00000000-0000-0000-0000-000000000000",
|
||||
"token": "offline",
|
||||
}
|
||||
|
||||
print(f"Launching {version}...")
|
||||
minecraft_command = minecraft_launcher_lib.command.get_minecraft_command(version, minecraft_directory, options)
|
||||
subprocess.run(minecraft_command)
|
||||
print("\nGame closed.")
|
||||
|
||||
elif choice == "h":
|
||||
print("\nHELP")
|
||||
print("1. To delete versions, open the folder and manually delete it.")
|
||||
print("2. Use the open folder function to find your installs.")
|
||||
print("3. If in any case the download terminates prematurely, just install the same version again! It will automatically check what files are already there, do an integrity check, and finish it for you.")
|
||||
|
||||
else:
|
||||
print("Invalid choice. Please type \"1\", \"2\", \"f\", \"h\", or \"e\".")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n[!] Error: {e}")
|
||||
|
||||
print("Launcher closed.")
|
||||
Reference in New Issue
Block a user