mirror of
https://github.com/xzb23/mods_unified_management.git
synced 2026-11-25 02:45:25 +08:00
完成移动mods到g_mods_dir部分
This commit is contained in:
8 files changed
+228
No files matched your search
+13
@@ -0,0 +1,13 @@
|
|||||||
|
__pycache__
|
||||||
|
dist
|
||||||
|
test
|
||||||
|
build
|
||||||
|
*.spec
|
||||||
|
*.backup
|
||||||
|
/.venv
|
||||||
|
/mods
|
||||||
|
/.vscode
|
||||||
|
/mum_list
|
||||||
|
|
||||||
|
*.c
|
||||||
|
*.bat
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 xz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import hashlib
|
||||||
|
import typing
|
||||||
|
# import collections
|
||||||
|
import time
|
||||||
|
import json
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
from _in_package import *
|
||||||
|
|
||||||
|
import common
|
||||||
|
import hash_
|
||||||
|
import runing_config
|
||||||
|
import runing_tmp_data
|
||||||
|
|
||||||
|
|
||||||
|
def r_mods():
|
||||||
|
runing_config.g_mods_dir = common.get_config("g_mods_dir")
|
||||||
|
while runing_config.g_mods_dir == "":
|
||||||
|
print("g_mods_dir未设置, 请先设置g_mods_dir")
|
||||||
|
common.w_config("g_mods_dir", input("g_mods_dir: "))
|
||||||
|
runing_config.g_mods_dir = common.get_config("g_mods_dir")
|
||||||
|
runing_config.g_mods_dir = common.formatting_path(runing_config.g_mods_dir)
|
||||||
|
|
||||||
|
hash_.traverse_dir(runing_config.MODS_DIR)
|
||||||
|
hash_.hash_files_from_glist(hashlib.sha256)
|
||||||
|
|
||||||
|
archive_dir = common.formatting_path(runing_config.g_mods_dir+"archive/")
|
||||||
|
mod_list = runing_config.VERSIONS_MODS_LIST_PATH + "modlist"
|
||||||
|
if not os.path.exists(archive_dir):
|
||||||
|
os.mkdir(archive_dir)
|
||||||
|
elif not os.path.isdir(archive_dir):
|
||||||
|
print("err!")
|
||||||
|
time.sleep(3)
|
||||||
|
exit(-2) # archive目录被占用
|
||||||
|
|
||||||
|
if not os.path.exists(mod_list):
|
||||||
|
with open(mod_list, "w") as f: f.write("")
|
||||||
|
elif not os.path.isfile(mod_list):
|
||||||
|
print("err!")
|
||||||
|
time.sleep(3)
|
||||||
|
exit(-2) # mod_list文件被占用
|
||||||
|
|
||||||
|
with open(mod_list, "a") as f:
|
||||||
|
for mod in runing_tmp_data.file_hash_results:
|
||||||
|
f.write(mod.hash_value+" : "+os.path.basename(mod.filepath)+"\n")
|
||||||
|
os.rename(mod.filepath, archive_dir+mod.hash_value)
|
||||||
|
|
||||||
|
def w_mods():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def menu():
|
||||||
|
mod_list = runing_config.VERSIONS_MODS_LIST_PATH + "modlist"
|
||||||
|
if not os.path.exists(mod_list):
|
||||||
|
r_mods()
|
||||||
|
elif not os.path.isfile(mod_list):
|
||||||
|
print("err!")
|
||||||
|
time.sleep(3)
|
||||||
|
exit(-2) # modlist文件被占用
|
||||||
|
|
||||||
|
if common.get_config("eula") != "true":
|
||||||
|
print("这是一个实验性质的程序,你需要具备mc mod加载、存档管理相关知识,出现问题概不负责\n本程序理论上不修改存档,但是如果mod转移出现问题仍然加载存档可能发生数据丢失,请积极备份")
|
||||||
|
if not common.eula():
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
runing_config.WORK_DIR = common.formatting_path(os.getcwd())
|
||||||
|
runing_config.MODS_DIR = common.formatting_path(runing_config.WORK_DIR + "mods/")
|
||||||
|
|
||||||
|
if not (os.path.exists(runing_config.MODS_DIR) and os.path.isdir(runing_config.MODS_DIR)):
|
||||||
|
print("err!")
|
||||||
|
time.sleep(3)
|
||||||
|
exit(-1) # 未找到mods目录
|
||||||
|
|
||||||
|
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):
|
||||||
|
os.mkdir(runing_config.VERSIONS_MODS_LIST_PATH)
|
||||||
|
elif not os.path.isdir(runing_config.VERSIONS_MODS_LIST_PATH):
|
||||||
|
print("err!")
|
||||||
|
time.sleep(3)
|
||||||
|
exit(-2) # mum_list目录被占用
|
||||||
|
|
||||||
|
if len(os.listdir(runing_config.MODS_DIR)) == 0:
|
||||||
|
w_mods()
|
||||||
|
else:
|
||||||
|
menu()
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
from _in_package import *
|
||||||
|
import runing_config
|
||||||
|
|
||||||
|
|
||||||
|
def formatting_path(path: str) -> str:
|
||||||
|
path = path.strip()
|
||||||
|
path = path.replace("\\", "/")
|
||||||
|
if path[-1] != "/":
|
||||||
|
path += "/"
|
||||||
|
return path
|
||||||
|
|
||||||
|
def eula():
|
||||||
|
print("请确认继续(Y/n): ")
|
||||||
|
user_in = input()
|
||||||
|
if user_in in ["", "y", "Y"]:
|
||||||
|
w_config("eula", "true", True)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
exit(0)
|
||||||
|
return False
|
||||||
|
|
||||||
|
def w_config(config_name: str, config_v: str, create_config_flag: bool = False):
|
||||||
|
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__))
|
||||||
|
config_path = formatting_path(os.path.dirname(exe_dir))+"config.json"
|
||||||
|
|
||||||
|
if create_config_flag:
|
||||||
|
with open(config_path, "w") as f:
|
||||||
|
f.write(json.dumps({config_name: config_v}))
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
with open(config_path, "r") as f:
|
||||||
|
config_ = json.loads(f.read().strip())
|
||||||
|
config_[config_name] = config_v
|
||||||
|
with open(config_path, "w") as f:
|
||||||
|
f.write(json.dumps(config_))
|
||||||
|
return True
|
||||||
|
|
||||||
|
def get_config(config_name):
|
||||||
|
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__))
|
||||||
|
config_path = formatting_path(os.path.dirname(exe_dir))+"config.json"
|
||||||
|
if not os.path.exists(config_path):
|
||||||
|
return ""
|
||||||
|
elif not os.path.isfile(config_path):
|
||||||
|
print("err")
|
||||||
|
time.sleep(3)
|
||||||
|
exit(-1) # config.json文件被占用
|
||||||
|
with open(config_path, "r") as f:
|
||||||
|
config_json = json.loads(f.read().strip())
|
||||||
|
config_json: dict
|
||||||
|
return config_json.get(config_name, "")
|
||||||
|
return ""
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
from _in_package import *
|
||||||
|
|
||||||
|
import common
|
||||||
|
import runing_config
|
||||||
|
import runing_tmp_data
|
||||||
|
|
||||||
|
def traverse_dir(root_dir):
|
||||||
|
print("正在遍历mod文件ing...")
|
||||||
|
for path, dirs, files in os.walk(root_dir):
|
||||||
|
path = common.formatting_path(path)
|
||||||
|
for filename in files:
|
||||||
|
runing_tmp_data.file_path_list.append(path + filename)
|
||||||
|
print(f"完成\t总计 {len(runing_tmp_data.file_path_list)} 个文件")
|
||||||
|
|
||||||
|
|
||||||
|
def hash_files_from_glist(algorithm: function):
|
||||||
|
print("正在计算mod文件散列ing...")
|
||||||
|
i = 0
|
||||||
|
p_old_i = -1
|
||||||
|
for f_path in runing_tmp_data.file_path_list:
|
||||||
|
with open(f_path, "rb") as f:
|
||||||
|
f_hash = hashlib.file_digest(f, algorithm)
|
||||||
|
runing_tmp_data.file_hash_results.append(runing_tmp_data.FileHashResult(f_path, f_hash.hexdigest(), algorithm.__name__))
|
||||||
|
runing_tmp_data.hash_to_paths[(f_hash.hexdigest(), algorithm.__name__)] = f_path
|
||||||
|
i += 1
|
||||||
|
if i % runing_config.wait_c == 0:
|
||||||
|
p_old_i = i
|
||||||
|
print(f"\r{i}/{len(runing_tmp_data.file_path_list)}", end="")
|
||||||
|
if p_old_i != -1 and i != p_old_i:
|
||||||
|
print(f"\r{i}/{len(runing_tmp_data.file_path_list)}", end="")
|
||||||
|
print()
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
WORK_DIR: str = "./"
|
||||||
|
MODS_DIR: str
|
||||||
|
VERSIONS_MODS_LIST_PATH: str
|
||||||
|
|
||||||
|
g_mods_dir: str = ""
|
||||||
|
|
||||||
|
wait_c: int = 100
|
||||||
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
from _in_package import *
|
||||||
|
|
||||||
|
|
||||||
|
class FileHashResult(typing.NamedTuple):
|
||||||
|
filepath: str
|
||||||
|
hash_value: str
|
||||||
|
algorithm: str
|
||||||
|
|
||||||
|
|
||||||
|
file_path_list: list[str] = []
|
||||||
|
file_hash_results: list[FileHashResult] = []
|
||||||
|
|
||||||
|
# hash_to_files: { (hash_value, algorithm): [filepath, ...] }
|
||||||
|
hash_to_paths: dict[tuple[str, str], str] = {}
|
||||||
Reference in new issue
Block a user