mirror of
https://github.com/xzb23/mods_unified_management.git
synced 2026-11-25 02:45:25 +08:00
完成菜单部分+hmcl适配
This commit is contained in:
4 files changed
+145
-16
No files matched your search
@@ -8,6 +8,8 @@ build
|
|||||||
/mods
|
/mods
|
||||||
/.vscode
|
/.vscode
|
||||||
/mum_list
|
/mum_list
|
||||||
|
/count
|
||||||
|
/work_l
|
||||||
|
|
||||||
*.c
|
*.c
|
||||||
*.bat
|
*.bat
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import runing_config
|
|||||||
import runing_tmp_data
|
import runing_tmp_data
|
||||||
|
|
||||||
|
|
||||||
def r_mods():
|
def r_mods(pass_hash: list[str] = []):
|
||||||
runing_config.g_mods_dir = common.get_config("g_mods_dir")
|
runing_config.g_mods_dir = common.get_config("g_mods_dir")
|
||||||
while runing_config.g_mods_dir == "":
|
while runing_config.g_mods_dir == "":
|
||||||
print("g_mods_dir未设置, 请先设置g_mods_dir")
|
print("g_mods_dir未设置, 请先设置g_mods_dir")
|
||||||
@@ -35,6 +35,8 @@ def r_mods():
|
|||||||
|
|
||||||
with open(mod_list, "a") as f:
|
with open(mod_list, "a") as f:
|
||||||
for mod in runing_tmp_data.file_hash_results:
|
for mod in runing_tmp_data.file_hash_results:
|
||||||
|
if mod.hash_value in pass_hash:
|
||||||
|
continue
|
||||||
f.write(mod.hash_value+" : "+mod.filepath.split(runing_config.MODS_DIR)[1]+"\n")
|
f.write(mod.hash_value+" : "+mod.filepath.split(runing_config.MODS_DIR)[1]+"\n")
|
||||||
if os.path.exists(g_mods_archive_dir+mod.hash_value):
|
if os.path.exists(g_mods_archive_dir+mod.hash_value):
|
||||||
continue
|
continue
|
||||||
@@ -74,6 +76,10 @@ def w_mods():
|
|||||||
mod_hash = mod.split(":")[0].strip()
|
mod_hash = mod.split(":")[0].strip()
|
||||||
mod_name = mod.split(":")[1].strip()
|
mod_name = mod.split(":")[1].strip()
|
||||||
# 可选流程,验证temp和archive内文件hash,待开发
|
# 可选流程,验证temp和archive内文件hash,待开发
|
||||||
|
if os.path.exists(runing_config.MODS_DIR+mod_name):
|
||||||
|
continue
|
||||||
|
if not os.path.exists(os.path.dirname(runing_config.MODS_DIR+mod_name)):
|
||||||
|
os.makedirs(os.path.dirname(runing_config.MODS_DIR+mod_name))
|
||||||
if os.path.exists(g_mods_temp_dir+mod_hash) and os.path.isfile(g_mods_temp_dir+mod_hash):
|
if os.path.exists(g_mods_temp_dir+mod_hash) and os.path.isfile(g_mods_temp_dir+mod_hash):
|
||||||
os.rename(g_mods_temp_dir+mod_hash, runing_config.MODS_DIR+mod_name)
|
os.rename(g_mods_temp_dir+mod_hash, runing_config.MODS_DIR+mod_name)
|
||||||
elif os.path.exists(g_mods_archive_dir+mod_hash) and os.path.isfile(g_mods_archive_dir+mod_hash):
|
elif os.path.exists(g_mods_archive_dir+mod_hash) and os.path.isfile(g_mods_archive_dir+mod_hash):
|
||||||
@@ -92,31 +98,66 @@ def menu():
|
|||||||
print("err!")
|
print("err!")
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
exit(-2) # modlist文件被占用
|
exit(-2) # modlist文件被占用
|
||||||
|
print(runing_config.menu)
|
||||||
|
match input("> "):
|
||||||
|
case runing_config.MENU_CODE.add_:
|
||||||
|
modhsah_l, _ = common.get_modlist()
|
||||||
|
r_mods(modhsah_l)
|
||||||
|
w_mods()
|
||||||
|
case runing_config.MENU_CODE.del_:
|
||||||
|
for path, dirs, files in os.walk(runing_config.MODS_DIR):
|
||||||
|
path = common.formatting_path(path)
|
||||||
|
for file in files:
|
||||||
|
os.remove(path+file)
|
||||||
|
w_mods()
|
||||||
|
case runing_config.MENU_CODE.re_:
|
||||||
|
os.remove(mod_list)
|
||||||
|
r_mods()
|
||||||
|
case runing_config.MENU_CODE.uninstall:
|
||||||
|
w_mods()
|
||||||
|
with open(runing_config.WORK_DIR + "mum_list/lock", "w") as f: f.write("1")
|
||||||
|
|
||||||
|
|
||||||
|
runing_config.EXE_DIR = common.get_exe_dir()
|
||||||
if common.get_config("eula") != "true":
|
if common.get_config("eula") != "true":
|
||||||
print("这是一个实验性质的程序,你需要具备mc mod加载、存档管理相关知识,出现问题概不负责\n本程序理论上不修改存档,但是如果mod转移出现问题仍然加载存档可能发生数据丢失,请积极备份")
|
print("这是一个实验性质的程序,你需要具备mc mod加载、存档管理相关知识,出现问题概不负责\n本程序理论上不修改存档,但是如果mod转移出现问题仍然加载存档可能发生数据丢失,请积极备份")
|
||||||
if not common.eula():
|
if not common.eula():
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
exit_tips_flag = False
|
exit_tips_flag = False
|
||||||
|
def init_():
|
||||||
|
runing_config.WORK_DIR = common.formatting_path(os.getcwd())
|
||||||
|
runing_config.MODS_DIR = common.formatting_path(runing_config.WORK_DIR + "mods/")
|
||||||
|
|
||||||
runing_config.WORK_DIR = common.formatting_path(os.getcwd())
|
if os.path.exists(runing_config.WORK_DIR + "mum_list/lock"):
|
||||||
runing_config.MODS_DIR = common.formatting_path(runing_config.WORK_DIR + "mods/")
|
exit(0)
|
||||||
|
|
||||||
if not (os.path.exists(runing_config.MODS_DIR) and os.path.isdir(runing_config.MODS_DIR)):
|
if not (os.path.exists(runing_config.MODS_DIR) and os.path.isdir(runing_config.MODS_DIR)):
|
||||||
print("err!")
|
print("err!")
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
exit(-1) # 未找到mods目录
|
exit(-1) # 未找到mods目录
|
||||||
|
|
||||||
runing_config.VERSIONS_MODS_LIST_PATH = common.formatting_path(runing_config.WORK_DIR + "mum_list/")
|
runing_config.VERSIONS_MODS_LIST_PATH = common.formatting_path(runing_config.WORK_DIR + "mum_list/")
|
||||||
if not os.path.exists(runing_config.VERSIONS_MODS_LIST_PATH):
|
if not os.path.exists(runing_config.VERSIONS_MODS_LIST_PATH):
|
||||||
os.mkdir(runing_config.VERSIONS_MODS_LIST_PATH)
|
os.mkdir(runing_config.VERSIONS_MODS_LIST_PATH)
|
||||||
elif not os.path.isdir(runing_config.VERSIONS_MODS_LIST_PATH):
|
elif not os.path.isdir(runing_config.VERSIONS_MODS_LIST_PATH):
|
||||||
print("err!")
|
print("err!")
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
exit(-2) # mum_list目录被占用
|
exit(-2) # mum_list目录被占用
|
||||||
|
|
||||||
|
init_()
|
||||||
|
|
||||||
|
common.check_file(runing_config.EXE_DIR+"work_l", "")
|
||||||
|
|
||||||
if len(sys.argv) >= 2 and sys.argv[1] == "gameexit":
|
if len(sys.argv) >= 2 and sys.argv[1] == "gameexit":
|
||||||
|
if common.sub_game() > 0:
|
||||||
|
exit(0)
|
||||||
|
with open(runing_config.EXE_DIR+"work_l", "r") as f:
|
||||||
|
work_l = f.read().strip()
|
||||||
|
work_l = work_l.split("\n")
|
||||||
|
for work in work_l:
|
||||||
|
os.chdir(work.strip())
|
||||||
|
init_()
|
||||||
runing_config.g_mods_dir = common.get_config("g_mods_dir")
|
runing_config.g_mods_dir = common.get_config("g_mods_dir")
|
||||||
g_mods_archive_dir = common.formatting_path(runing_config.g_mods_dir)+"archive/"
|
g_mods_archive_dir = common.formatting_path(runing_config.g_mods_dir)+"archive/"
|
||||||
g_mods_temp_dir = common.formatting_path(runing_config.g_mods_dir)+"temp/"
|
g_mods_temp_dir = common.formatting_path(runing_config.g_mods_dir)+"temp/"
|
||||||
@@ -153,10 +194,15 @@ if len(sys.argv) >= 2 and sys.argv[1] == "gameexit":
|
|||||||
os.rename(runing_config.MODS_DIR+mod_name, g_mods_temp_dir+mod_hash)
|
os.rename(runing_config.MODS_DIR+mod_name, g_mods_temp_dir+mod_hash)
|
||||||
elif not os.path.isfile(g_mods_archive_dir+mod_hash):
|
elif not os.path.isfile(g_mods_archive_dir+mod_hash):
|
||||||
print(f"W: {mod_name}在g_mods_temp_dir中被占用")
|
print(f"W: {mod_name}在g_mods_temp_dir中被占用")
|
||||||
|
with open(runing_config.EXE_DIR+"work_l", "w") as f: f.write()
|
||||||
if exit_tips_flag:
|
if exit_tips_flag:
|
||||||
input()
|
input()
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
common.add_game()
|
||||||
|
with open(runing_config.EXE_DIR+"work_l", "a") as f:
|
||||||
|
f.write(runing_config.WORK_DIR+"\n")
|
||||||
|
|
||||||
if len(os.listdir(runing_config.MODS_DIR)) == 0:
|
if len(os.listdir(runing_config.MODS_DIR)) == 0:
|
||||||
w_mods()
|
w_mods()
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -20,10 +20,7 @@ def eula():
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def w_config(config_name: str, config_v: str, create_config_flag: bool = False):
|
def w_config(config_name: str, config_v: str, create_config_flag: bool = False):
|
||||||
if getattr(sys, "frozen", False):
|
exe_dir = runing_config.EXE_DIR
|
||||||
exe_dir = os.path.dirname(os.path.abspath(sys.executable))
|
|
||||||
else:
|
|
||||||
exe_dir = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
config_path = formatting_path(os.path.dirname(exe_dir))+"config.json"
|
config_path = formatting_path(os.path.dirname(exe_dir))+"config.json"
|
||||||
|
|
||||||
if create_config_flag:
|
if create_config_flag:
|
||||||
@@ -39,19 +36,83 @@ def w_config(config_name: str, config_v: str, create_config_flag: bool = False):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def get_config(config_name):
|
def get_config(config_name):
|
||||||
if getattr(sys, "frozen", False):
|
exe_dir = runing_config.EXE_DIR
|
||||||
exe_dir = os.path.dirname(os.path.abspath(sys.executable))
|
|
||||||
else:
|
|
||||||
exe_dir = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
config_path = formatting_path(exe_dir)+"config.json"
|
config_path = formatting_path(exe_dir)+"config.json"
|
||||||
if not os.path.exists(config_path):
|
if not os.path.exists(config_path):
|
||||||
return ""
|
return ""
|
||||||
elif not os.path.isfile(config_path):
|
elif not os.path.isfile(config_path):
|
||||||
print("err")
|
print("err")
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
exit(-1) # config.json文件被占用
|
exit(runing_config.EXIT_CODE["te"]) # config.json文件被占用
|
||||||
with open(config_path, "r") as f:
|
with open(config_path, "r") as f:
|
||||||
config_json = json.loads(f.read().strip())
|
config_json = json.loads(f.read().strip())
|
||||||
config_json: dict
|
config_json: dict
|
||||||
return config_json.get(config_name, "")
|
return config_json.get(config_name, "")
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
def get_modlist():
|
||||||
|
mod_list_path = runing_config.VERSIONS_MODS_LIST_PATH + "modlist"
|
||||||
|
if not os.path.exists(mod_list_path):
|
||||||
|
with open(mod_list_path, "w") as f: f.write("")
|
||||||
|
elif not os.path.isfile(mod_list_path):
|
||||||
|
print("err!")
|
||||||
|
time.sleep(3)
|
||||||
|
exit(-2) # mod_list文件被占用
|
||||||
|
mod_hash_list = []
|
||||||
|
mod_name_list = []
|
||||||
|
with open(mod_list_path, "r") as f:
|
||||||
|
mod_list = f.read().strip()
|
||||||
|
mod_list = mod_list.split("\n")
|
||||||
|
for mod in mod_list:
|
||||||
|
mod_hash_list.append(mod.split(":")[0].strip())
|
||||||
|
mod_name_list.append(mod.split(":")[1].strip())
|
||||||
|
return mod_hash_list, mod_name_list
|
||||||
|
|
||||||
|
|
||||||
|
def add_game(c:int = 1):
|
||||||
|
exe_dir = runing_config.EXE_DIR
|
||||||
|
count = formatting_path(exe_dir)+"count"
|
||||||
|
if not os.path.exists(count):
|
||||||
|
with open(count, "w") as f:
|
||||||
|
f.write("0")
|
||||||
|
elif not os.path.isfile(count):
|
||||||
|
print("err")
|
||||||
|
time.sleep(3)
|
||||||
|
exit(runing_config.EXIT_CODE["te"]) # count文件被占用/文件类型错误
|
||||||
|
with open(count, "r+") as f:
|
||||||
|
c = int(f.read().strip()) + 1
|
||||||
|
f.seek(0)
|
||||||
|
f.write(str(c))
|
||||||
|
|
||||||
|
def sub_game(c:int = 1):
|
||||||
|
exe_dir = runing_config.EXE_DIR
|
||||||
|
count = formatting_path(exe_dir)+"count"
|
||||||
|
if not os.path.exists(count):
|
||||||
|
with open(count, "w") as f:
|
||||||
|
f.write("0")
|
||||||
|
return 0
|
||||||
|
elif not os.path.isfile(count):
|
||||||
|
print("err")
|
||||||
|
time.sleep(3)
|
||||||
|
exit(runing_config.EXIT_CODE["te"]) # count文件被占用/文件类型错误
|
||||||
|
with open(count, "r+") as f:
|
||||||
|
c = int(f.read().strip()) - 1
|
||||||
|
f.seek(0)
|
||||||
|
f.write(str(c))
|
||||||
|
return c
|
||||||
|
|
||||||
|
def get_exe_dir():
|
||||||
|
if getattr(sys, "frozen", False):
|
||||||
|
exe_dir = os.path.dirname(os.path.abspath(sys.executable))
|
||||||
|
else:
|
||||||
|
exe_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
return formatting_path(exe_dir)
|
||||||
|
|
||||||
|
def check_file(file_path: str, def_):
|
||||||
|
if not os.path.exists(file_path):
|
||||||
|
with open(file_path, "w") as f:
|
||||||
|
f.write(def_)
|
||||||
|
elif not os.path.isfile(file_path):
|
||||||
|
print("err")
|
||||||
|
time.sleep(3)
|
||||||
|
exit(runing_config.EXIT_CODE["te"]) # 文件被占用/文件类型错误
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from _in_package import typing
|
||||||
|
|
||||||
WORK_DIR: str = "./"
|
WORK_DIR: str = "./"
|
||||||
MODS_DIR: str
|
MODS_DIR: str
|
||||||
VERSIONS_MODS_LIST_PATH: str
|
VERSIONS_MODS_LIST_PATH: str
|
||||||
@@ -9,3 +11,21 @@ wait_c: int = 100
|
|||||||
# nf: Not found
|
# nf: Not found
|
||||||
# te: Type err
|
# te: Type err
|
||||||
EXIT_CODE = {"ok": 0, "nf": -1, "te": -2}
|
EXIT_CODE = {"ok": 0, "nf": -1, "te": -2}
|
||||||
|
|
||||||
|
menu = """
|
||||||
|
检测到mods文件改动
|
||||||
|
请选择:
|
||||||
|
1. 添加到mum模组清单,并按照清单拉取模组
|
||||||
|
2. 清除当前mods变更并按照清单拉取模组
|
||||||
|
3. 按照当前mods目录重建模组清单(请确认你知道这会发生什么)
|
||||||
|
4. 按照清单拉取模组并取消管理
|
||||||
|
"""
|
||||||
|
|
||||||
|
class MenuCode(typing.NamedTuple):
|
||||||
|
add_: str = "1"
|
||||||
|
del_: str = "2"
|
||||||
|
re_: str = "3"
|
||||||
|
uninstall: str = "4"
|
||||||
|
MENU_CODE = MenuCode()
|
||||||
|
|
||||||
|
EXE_DIR: str
|
||||||
Reference in new issue
Block a user