Skip to content

Commit

Permalink
Fix Unpack Crash
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdWindScholar committed Sep 30, 2023
1 parent 34cd7ac commit d91afd8
Showing 1 changed file with 99 additions and 3 deletions.
102 changes: 99 additions & 3 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import time
import zipfile
from argparse import Namespace
from configparser import ConfigParser

import extract_dtb
import requests
Expand Down Expand Up @@ -463,7 +464,7 @@ def subbed(project):
if op_pro == '66':
path = input("请输入插件路径或[拖入]:")
if os.path.exists(path):
install(path)
installmpk(path)
else:
ywarn(f"{path}不存在!")
time.sleep(2)
Expand All @@ -488,8 +489,103 @@ def subbed(project):
subbed(project)


def install(plugin):
pass
class installmpk:
def __init__(self, mpk):
super().__init__()
self.mconf = ConfigParser()
if not mpk:
messpop(lang.warn2)
self.destroy()
return
self.title(lang.text31)
self.resizable(False, False)
with zipfile.ZipFile(mpk, 'r') as myfile:
with myfile.open('info') as info_file:
self.mconf.read_string(info_file.read().decode('utf-8'))
try:
with myfile.open('icon') as myfi:
try:
pyt = ImageTk.PhotoImage(Image.open(BytesIO(myfi.read())))
except Exception as e:
print(e)
pyt = ImageTk.PhotoImage(Image.open(elocal + os.sep + "images" + os.sep + "none"))
except:
pyt = ImageTk.PhotoImage(Image.open("".join([elocal, os.sep, "bin", os.sep, "images", os.sep, "none"])))
with myfile.open('%s' % (self.mconf.get('module', 'resource')), 'r') as inner_file:
self.inner_zipdata = inner_file.read()
self.inner_filenames = zipfile.ZipFile(BytesIO(self.inner_zipdata)).namelist()
Label(self, image=pyt).pack(padx=10, pady=10)
Label(self, text="%s" % (self.mconf.get('module', 'name')), font=('黑体', 14)).pack(padx=10, pady=10)
Label(self, text=lang.text32.format((self.mconf.get('module', 'version'))), font=('黑体', 12)).pack(padx=10,
pady=10)
Label(self, text=lang.text33.format((self.mconf.get('module', 'author'))), font=('黑体', 12)).pack(padx=10,
pady=10)
text = Text(self)
text.insert("insert", "%s" % (self.mconf.get('module', 'describe')))
text.pack(padx=10, pady=10)
self.prog = ttk.Progressbar(self, length=200, mode='determinate', orient=HORIZONTAL, maximum=100, value=0)
self.prog.pack()
self.state = Label(self, text=lang.text40, font=('黑体', 12))
self.state.pack(padx=10, pady=10)
self.installb = ttk.Button(self, text=lang.text41, command=lambda: cz(self.install))
self.installb.pack(padx=10, pady=10, expand=True, fill=X)
jzxs(self)
self.wait_window()

def install(self):
if self.installb.cget('text') == lang.text34:
self.destroy()
return True
self.installb.config(state=DISABLED)
try:
supports = self.mconf.get('module', 'supports').split()
except:
supports = [sys.platform]
if sys.platform not in supports:
self.state['text'] = lang.warn15.format(sys.platform)
return False
for dep in self.mconf.get('module', 'depend').split():
if not os.path.isdir("".join([elocal, os.sep, "bin", os.sep, "module", os.sep, dep])):
self.state['text'] = lang.text36 % (self.mconf.get('module', 'name'), dep, dep)
self.installb['text'] = lang.text37
self.installb.config(state='normal')
return False
if os.path.exists(
"".join([elocal, os.sep, "bin", os.sep, "module", os.sep, self.mconf.get('module', 'identifier')])
):
rmtree("".join([elocal, os.sep, "bin", os.sep, "module", os.sep, self.mconf.get('module', 'identifier')]))
fz = zipfile.ZipFile(BytesIO(self.inner_zipdata), 'r')
uncompress_size = sum((file.file_size for file in fz.infolist()))
extracted_size = 0
for file in self.inner_filenames:
try:
file = str(file).encode('cp437').decode('gbk')
except:
file = str(file).encode('utf-8').decode('utf-8')
info = fz.getinfo(file)
extracted_size += info.file_size
self.state['text'] = lang.text38.format(file)
fz.extract(file,
"".join(
[elocal, os.sep, "bin", os.sep, "module", os.sep, self.mconf.get('module', 'identifier')]))
self.prog['value'] = extracted_size * 100 / uncompress_size
try:
depends = self.mconf.get('module', 'depend')
except:
depends = ''
minfo = {"name": "%s" % (self.mconf.get('module', 'name')),
"author": "%s" % (self.mconf.get('module', 'author')),
"version": "%s" % (self.mconf.get('module', 'version')),
"identifier": "%s" % (self.mconf.get('module', 'identifier')),
"describe": "%s" % (self.mconf.get('module', 'describe')),
"depend": "%s" % depends}
with open("".join([elocal, os.sep, "bin", os.sep, "module", os.sep, self.mconf.get('module', 'identifier'),
os.sep, "info.json"]),
'w') as f:
json.dump(minfo, f, indent=2)
self.state['text'] = lang.text39
self.installb['text'] = lang.text34
self.installb.config(state='normal')


def unpackChoo(project):
Expand Down

0 comments on commit d91afd8

Please sign in to comment.