update src/loader.py.

Signed-off-by: undefined <undefined_1@outlook.com>
This commit is contained in:
undefined 2024-02-10 12:28:20 +00:00 committed by Gitee
parent a83a627a11
commit 3325493ea6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 33 additions and 42 deletions

View File

@ -17,53 +17,44 @@ disk = ""
lists = []
def version_check(file_json, pkg_name):
try:
if "compatibility" in file_json:
if "injector" in file_json["compatibility"]:
with open(f"{disk}/PEinjector/VERSION", "r", encoding="utf-8") as file:
version = file.readlines()[0].rstrip("\n\r")
if "min" in file_json["compatibility"]["injector"]:
plugver = file_json["compatibility"]["injector"]["min"]
def __version_parse(version: str) -> list:
return [int(i) for i in version.split(".")]
def vererr():
log.warn(f"load moudle [{pkg_name}] failed: " +
f"PEinjector version too low, need [{plugver}]")
if int(plugver.split(".")[0]) > int(version.split(".")[0]):
vererr()
return 5
elif int(plugver.split(".")[0]) == int(version.split(".")[0]):
if plugver.split(".")[1] > version.split(".")[1]:
vererr()
return 5
elif int(plugver.split(".")[1]) == int(version.split(".")[1]):
if int(plugver.split(".")[2]) > int(version.split(".")[2]):
vererr()
return 5
if "max" in file_json["compatibility"]["injector"]:
plugver = file_json["compatibility"]["injector"]["max"]
def vererr():
log.warn(f"load moudle [{pkg_name}] failed: " +
f"PEinjector version too high, need [{plugver}]")
if int(plugver.split(".")[0]) < int(version.split(".")[0]):
vererr()
return 6
elif int(plugver.split(".")[0]) == int(version.split(".")[0]):
if int(plugver.split(".")[1] < version.split(".")[1]):
vererr()
return 6
elif plugver.split(".")[1] == version.split(".")[1]:
if int(plugver.split(".")[2] < version.split(".")[2]):
vererr()
return 6
except:
log.warn(f"load moudle [{pkg_name}] failed: " +
"The version number is formatted incorrectly")
return 7
def __version_compare(ver1: str, ver2: str) -> int:
version1 = __version_parse(ver1)
version2 = __version_parse(ver2)
for (i, j) in zip(version1, version2):
if i != j:
return 1 if i > j else -1
return 0
def version_check(configuration: dict, pkg_name: str) -> int:
ERROR_MESSAGE = "load moudle [{}] failed: PEinjector version too {}, need [{}]"
try:
if not "compatibility" in configuration or not "injector" in configuration["compatibility"]:
return 0
with open(f"{disk}/PEinjector/VERSION", 'r', encoding="utf-8") as f:
version = f.readlines()[0].rstrip("\n\r")
if "min" in configuration["compatibility"]["injector"]:
plugver = configuration["compatibility"]["injector"]["min"]
if __version_compare(version, plugver) == -1:
log.warn(ERROR_MESSAGE.format(pkg_name, "low", plugver))
return 5
if "max" in configuration["compatibility"]["injector"]:
plugver = configuration["compatibility"]["injector"]["max"]
if __version_compare(version, plugver) == 1:
log.warn(ERROR_MESSAGE.format(pkg_name, "high", plugver))
return 6
except Exception as e:
log.warn(f"load moudle [{pkg_name}] failed: {e}")
return 7
def file_check(file_json, pkg_name):
try:
if "compatibility" in file_json: