支持自动更新音·创库,支持更优美的错误提示,支持选择输出目录

This commit is contained in:
2024-02-08 04:36:42 +08:00
parent 28ec743b86
commit c64d9c440f
12 changed files with 1934 additions and 315 deletions

View File

@ -4,7 +4,7 @@
伶伦转换器 打包存档组件
Linglun Converter Language Localization Component
版权所有 © 2024 金羿 & 睿开发组
版权所有 © 2024 金羿 & 睿开发组
Copyright © 2024 EillesWan & TriM Org.
开源相关声明请见 ./License.md
@ -12,7 +12,6 @@ Terms & Conditions: ./Lisense.md
"""
import hashlib
import dill
@ -62,3 +61,60 @@ def enpack_llc_pack(sth: Any, to_dist: str):
f.write(md5_value)
f.write(b" | \n")
f.write(packing_bytes)
def enpack_msct_pack(sth, to_dist: str):
packing_bytes = brotli.compress(
dill.dumps(
sth,
)
)
with open(
to_dist,
"wb",
) as f:
f.write(packing_bytes)
return hashlib.sha256(packing_bytes)
def unpack_msct_pack(from_dist: str, hash_value: str, raise_error: bool = True):
with open(from_dist, "rb") as f:
packed_data = f.read()
now_hash = hashlib.sha256(packed_data).hexdigest()
if now_hash == hash_value:
return dill.loads(brotli.decompress(packed_data))
else:
if raise_error:
raise ValueError(
"文件读取失败:\n传入:{}\n需求:{}\n签名不一致,可能存在注入风险。".format(
now_hash, hash_value
)
)
else:
return ValueError(
"文件读取失败:\n传入:{}\n需求:{}\n签名不一致,可能存在注入风险。".format(
now_hash, hash_value
)
)
def load_msct_packed_data(
packed_data: bytes, hash_value: str, raise_error: bool = True
):
now_hash = hashlib.sha256(packed_data).hexdigest()
if now_hash == hash_value:
return dill.loads(brotli.decompress(packed_data))
else:
if raise_error:
raise ValueError(
"文件读取失败:\n传入:{}\n需求:{}\n签名不一致,可能存在注入风险。".format(
now_hash, hash_value
)
)
else:
return ValueError(
"文件读取失败:\n传入:{}\n需求:{}\n签名不一致,可能存在注入风险。".format(
now_hash, hash_value
)
)