Skip to content

Commit

Permalink
Rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
yituodab committed Aug 25, 2024
1 parent 15aca5f commit 95ba85c
Show file tree
Hide file tree
Showing 2 changed files with 232 additions and 141 deletions.
206 changes: 65 additions & 141 deletions Launcher.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
import minecraft_launcher_lib
import zipfile
import os
import requests
import json
import minecraft_launcher_lib
import subprocess
minecraft_directory = ".minecraft"
forge_version = '1.18.2-40.2.0'
version = "1.18.2"
launcher_version = '2.0.0'
home = os.environ.get('USERPROFILE')
if not os.path.exists(home+r"\.config\wangzhimeng"):
os.mkdir(home+r"\.config")
os.mkdir(home+r"\.config\wangzhimeng")
option_dir = home+r"\.config\wangzhimeng"
if not os.path.exists(home+r"\.config\wangzhimeng\user"):
files = open(home+r"\.config\wangzhimeng\user", "w+")
files.close()
config_path = home+"/.config/wzm/config.json"
if not os.path.exists(home+"/.config/wzm"):
os.mkdir(home+"/.config")
os.mkdir(home+"/.config/wzm")
if not os.path.exists(config_path):
file = open(config_path, "w+")
file.write("{\n}")
file.close
#write_file = open(config_path,'w+')
file = open(config_path, "r+")
try:
config_json = json.load(file)
file.close()
except Exception as e:
print(e)
os.system('pause')
current_max = 0
def set_status(status: str):
print('\n\r'+status)
def set_progress(progress: int):
if current_max != 0:
print(f"\r{progress}/{current_max}", end='')

def set_max(new_max: int):
global current_max
current_max = new_max
Expand All @@ -29,139 +36,56 @@ def set_max(new_max: int):
"setProgress": set_progress,
"setMax": set_max
}
runtime_version = "java-runtime-beta"
if os.path.exists(option_dir+r"\install"):
FILE = open(option_dir+r"\install", 'r')
LINE = FILE.readlines()
else:
LINE = minecraft_directory
mcdir = LINE[0]
runtime = minecraft_launcher_lib.runtime.get_executable_path(runtime_version, mcdir)
if runtime == 'None':
runtime = os.environ.get('JAVA_HOME')+r"\bin\java.exe"
else:
runtime = minecraft_launcher_lib.runtime.get_executable_path(runtime_version, mcdir)
def installJDK(path: str):
minecraft_launcher_lib.runtime.install_jvm_runtime(runtime_version, path, callback)

def cls():
os.system('cls')
def launcher(player: str):
options = minecraft_launcher_lib.utils.generate_test_options()
options['username'] = player
options['executablePath'] = runtime
options["launcherName"] = 'WZM'
options["launcherVersion"] = "114514"
print('检查游戏完整性...',end='')
minecraft_launcher_lib.install.install_minecraft_version('1.18.2', mcdir, callback)
if os.path.exists(mcdir+r'\versions\1.18.2-forge-40.2.0'):
print('forge已安装!')
forgeinput = input(r'是否使用forge?(是/否)')
if forgeinput == '是':
command = minecraft_launcher_lib.command.get_minecraft_command("1.18.2-forge-40.2.0", mcdir, options)
else:
command = minecraft_launcher_lib.command.get_minecraft_command("1.18.2", mcdir, options)
subprocess.run(command)
#install
def install():
Dir = input("(默认安装目录:.minecraft)\n安装目录?(按回车选择默认):")
if Dir == '':
print('安装中...',end='')
minecraft_launcher_lib.install.install_minecraft_version("1.18.2", minecraft_directory, callback=callback)
file = open(option_dir+r"\install", "a+")
file.write(minecraft_directory)
file.close()


else:
print('安装中...',end='')
minecraft_launcher_lib.install.install_minecraft_version("1.18.2", Dir,callback=callback)
file = open(option_dir+r"\install", "a+")
file.write(Dir)
file.close()

cls()
def info():
def install(path: str):
minecraft_launcher_lib.install.install_minecraft_version(version, path, callback)
print("安装完成!")
def body():
print('Warning:本启动器为往之门服务器定制,且仅能使用离线用户')
print('输入1:启动minecraft')
print(r'输入2:下载forge/服务器模组依赖')
print('输入3:更改用户')
print('输入4:更改安装目录')
print('输入2:更改用户')
print('输入3:更改安装目录')
print('输入4:设置')
print('输入0:退出')
if os.path.exists(option_dir+r"\install"):
print('已安装!')
else:
print('Warning:本启动器为往之门服务器定制,且仅能使用离线用户')
Input = input("是否安装?(是/否)(已安装选择否)")
if Input == '否':
put = input('已安装?(是/否):')
if put == '是':
Put = input("安装目录?:")
file = open(option_dir+r"\install", "a+")
file.write(Put)
file.close()
cls()
Input = int(input('输入:'))
if Input == 1:
if "installPath" in config_json:
option = minecraft_launcher_lib.utils.generate_test_options()
if 'user_name' in config_json:
option['username'] = config_json['user_name']
else:
option['username'] = 'Unknown'
option['launcherName'] = 'WZM Launcher'
option['launcherVersion'] = launcher_version
option['executablePath'] = minecraft_launcher_lib.runtime.get_executable_path("java-runtime-beta",config_json["installPath"])
print('检查游戏完整性...')
minecraft_launcher_lib.install.install_minecraft_version(version, config_json["installPath"], callback)
minecraft_command = minecraft_launcher_lib.command.get_minecraft_command(version, str(config_json["installPath"]), option)
subprocess.run(minecraft_command)
else:
exit()
if Input == '是':
install()
cls()

#主要部分
def body():
print('安装目录:'+mcdir)

with open(option_dir+r"\user", "r") as file:
# 读取文件内容
content = file.read()
if content == '':
content = 'unknown'
print('当前用户:'+content)
info()
Input = input('输入选项:')
INput = int(Input)
if INput == 0:
exit()
if INput == 3:
cls()
INPut = input('输入用户名:')
user = open(option_dir+r'\user', "w+")
user.write(INPut)
user.close()
cls()
print('您尚未安装Minecraft')
Input = input('已安装?(是/否)')
if Input == '是':
Input = input('安装目录:')
config_json['installPath'] = Input
file = open(config_path, "w+")
json.dump(config_json, file)
file.close()
body()
if INput == 2:
with open(option_dir+r"\install", "r") as file:
# 读取文件内容
content = file.read()
if not os.path.exists(content+r"\mods"):
os.mkdir(content+r"\mods")
print('安装forge中...',end='')
minecraft_launcher_lib.forge.install_forge_version(forge_version, content, callback, runtime)
if not os.path.exists(mcdir+r'\mods\mod.zip'):
print("\n下载中...")
get = requests.get("https://pan.miaoi.top/f/L2EDhB/mods.zip")
open(content+r"\mods\mod.zip", "wb").write(get.content)
Zipfile = zipfile.ZipFile(content+r"\mods\mod.zip", "r")
for Files in Zipfile.namelist():
Zipfile.extract(Files, content+r"\mods")
Zipfile.close()
cls()
body()
if INput == 1:
with open(option_dir+r"\user", "r") as file:
# 读取文件内容
player = file.read()
if player == '':
player = 'unknown'
print('当前用户:'+player)
print('安装目录:'+mcdir)
launcher(player)
cls()
elif Input == 2:
config_json['user_name'] = input('用户名:')
file = open(config_path, "w+")
json.dump(config_json, file)
file.close()
body()
elif Input == 3:
config_json["installPath"] = input('安装目录:')
file = open(config_path, "w+")
json.dump(config_json, file)
file.close()
body()
if INput == 4:
PUT = input('安装目录?')
open(option_dir+r'\install','w+').write(PUT)
cls()
elif Input == 4:
print('没写')
body()
else:
exit()
body()
Loading

0 comments on commit 95ba85c

Please sign in to comment.