From 01a31a25785f7594cc4367449788ec27d87baa90 Mon Sep 17 00:00:00 2001 From: cxykevin Date: Sat, 4 May 2024 21:27:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=BB=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 2 +- VERSION | 1 + lang/zh_cn.toml | 8 ++++-- lib/vars.py | 1 + res/smile.gif | Bin 0 -> 1726 bytes ui/homeui.py | 65 ++++++++++++++++++++++++++++++++++++++++++ ui/installer.py | 22 +++++++++----- ui/win.py | 30 +++++++++++++------ 8 files changed, 111 insertions(+), 18 deletions(-) create mode 100644 VERSION create mode 100644 lib/vars.py create mode 100644 res/smile.gif create mode 100644 ui/homeui.py diff --git a/.vscode/settings.json b/.vscode/settings.json index 242c7c8..6956c3c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,4 @@ { "python.analysis.typeCheckingMode": "off", - "python.analysis.autoImportCompletions": true + "python.analysis.autoImportCompletions": false } \ No newline at end of file diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..8a9ecc2 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.1 \ No newline at end of file diff --git a/lang/zh_cn.toml b/lang/zh_cn.toml index aba61bd..7775745 100644 --- a/lang/zh_cn.toml +++ b/lang/zh_cn.toml @@ -2,7 +2,9 @@ UnsupportedSystem = "当前操作系统不受支持" PermissionDeniedLinux = "在 linux 操作系统系统下,请使用 root 权限进行安装" PermissionDeniedWin = "权限不足,请以管理员身份运行此程序" InstallWelcome = "欢迎安装 PEInjector" +UpgradeWelcome = "更新 PEInjector" InstallInfo = "PEinjector 是增强 WindowsPE 的一个工具和平台" +UpgradeInfo = "接下来将更新 PEinjector 和 ventoy" DownloadInstallTitle = "下载必要文件" DownloadInstall = "在开始之前,我们需要下载一些依赖文件\n如果您的网络状况不佳,请手动下载 peinjector 和 ventoy 并解压到 software 文件夹" StartInstall = "开始安装" @@ -17,5 +19,7 @@ InstallIjTitle = "安装 PEinjector" InstallIjInfo = "PEinjector主程序正在安装中,请稍等" FinishInstall = "完成安装" InstallFinishTitle = "安装已完成" -InstallFinishInfo = "PEinjector已经安装到您的设备\n点击下方按钮关闭程序并重新启动以管理 PEinjector" -InstallFinishBtn = "关闭" +InstallFinishInfo = "PEinjector已经安装到您的设备\n点击下方按钮重新启动程序以管理 PEinjector" +InstallFinishBtn = "重启" +HomeWelcome = "欢迎使用 PEinjector" +HomeInfo = "一个增强 WindowsPE 的一个工具和平台\n点击下方版本号进行更新" diff --git a/lib/vars.py b/lib/vars.py new file mode 100644 index 0000000..9c049b9 --- /dev/null +++ b/lib/vars.py @@ -0,0 +1 @@ +DISKMOUNT = "" diff --git a/res/smile.gif b/res/smile.gif new file mode 100644 index 0000000000000000000000000000000000000000..77cd1591fc402c804130f0f505bb636f3022fb1d GIT binary patch literal 1726 zcmaLSjXx9k1HkbO8(YY1*qFx`%j1qKji}~%jzkOPIFuGSGAkizG>kmXV|h-vJj*P< zQl@5}3AZKZ?zM_V7jYg=_ml6>{R6+x>-`UW+}vGlNTEy!6HVQuJ@cjh@G=snv5ZneXw1Y@4h~a^hK9Jf6?(hMN57PU=T>;1$0C_@?zi$wfjDYen zP%#FoC&0rg(EKZC5rI|_Xxk?Sk7q&GEa1Kc-ERSJ4m_CyJ->lx^Pu;4@Zt|3d=Ccq zeE>rr!0^5WFtPx~7Qy64@cJXzFPiuNm_zpa_XPsqTt&bB|qAQt6a`zc#C)DyN16RZ`ctBofU!IxWrG4(Y2Sp!c)uS(+S}dTXa( zKqw#@>A*O>&!ZZXQAX{9;x_}sh^+9*$UZh)b9P~IKp&nt@kc3JRU}=P8spiDpF`N{ zYkz%PG}Sr!&PgWsAS`)Ll~af6n0%UIjU35jde^%AY>KgA8Os&kgBlUDiu^A?sxv0- zOKL42U+TpvEzVzTJG5zT&|u0+U|j4nE&S|lB7S(YL_=K> z+aZzpeeJ{OGj7Z`1x5k(S^>gxHFEd+O*hBy>g<)}3-X{$s2^0>m?Jl(X61x8W*Y|M zp&?r}I8+u_H`2B25|g5_w;B2qRr{~?cP`6C`o2nZL)w(gEprLxZc>jz2p%c4nvP~D zN-(*xOEzb2I+hjlb8hWWFnM%r0xI^liqFi|Z+x4KY-e{9`C^S$R~U-UBAjM3vTZPB zvFwPcw2O+Neo*2mb~TG}c2@Q9E-V6meQn&Qnu=Y@MBgODg~5vu5fTCfilsW5SoUI z9Y@aB5yT7iZLA0+6C1XRG!J^IYA5XEyQmGCk2OeJa8tqtO7}D&wKe=rv>i_S*TiOQ zJ0abS7`o^4HIW!R+*CdTM}}|mWjXz31HHE0k#H{YxHtTH(pL{S-{S3-TZ;`MPzb+f z;t79cAvy-vqjk((#Se@xu3>R`o1X*^Ia3fX2DzdHuYH$$sW^My*XZ`+J;nvB)k#q~VSQ#zKn=d- zb;Lf;d5vo6`|NMFdx6Gy7I7yr0}s0}bU>GHbW zB;iLnjiEy@qm{{<;;tdZd^s|4SCC}&-)dduc(rYljsuECFCmeCLzH5(leZY|GIykD zgE3!%v}XCeF&eKh(&i&qc7}(1k7)ZZ%2|!hGm!^bX->Ff9)|(s+y*!l@!eG@ghj z+x>^0VvsX5?CRAoTUwEQ;6$8;mnJlyDk0xVP18GRNw%%`WI^XBdNWaiV)vL-166WP zgP~I)Pheyzl2bg0*)Sk7Q(!|4xtGMQXefnm>LtliQ&CcHWA@qgI;-?*|HhLS5qv;+=QZ#$ZS=SCMXOcb_BAI$i3P^+w>O;LeB?EVKf!9+*^ literal 0 HcmV?d00001 diff --git a/ui/homeui.py b/ui/homeui.py new file mode 100644 index 0000000..92f1c65 --- /dev/null +++ b/ui/homeui.py @@ -0,0 +1,65 @@ +import os +import sys +from magictk import mtk, color_tmpl +from magictk import fontconfig +from ui.lang import l +from logger.logger import * +from lib import vars +from tkinter import Label as tkLabel + +now_frame = None +master: mtk.Frame = None + + +def show_home_page(): + global now_frame, master + first_page = mtk.Frame(master) + mtk.Frame(first_page, w=10000).pack(fill="both", expand=True) + smileimg = mtk.PhotoImage(file="res"+os.sep+"smile.gif") + frames = mtk.Frame(first_page) + smilelabel = tkLabel(frames, image=smileimg, + background=color_tmpl.default_color["background"]) + smilelabel.pack() + smilelabel.image = smileimg + frames.pack(fill='x') + mtk.Frame(first_page, w=10000, height=40).pack(fill="x") + mtk.Label(first_page, text=l("HomeWelcome"), + anchor='center', font=(fontconfig.getfont(), 20), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["primary_text"]).pack(fill='x') + mtk.Label(first_page, text="\n"+l("HomeInfo"), + anchor='center', font=(fontconfig.getfont(), 10), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["secondary_text"]).pack(fill='x') + mtk.Frame(first_page, height=30).pack() + buttonlist = mtk.Frame(first_page) + + with open(vars.DISKMOUNT+os.sep+"PEinjector"+os.sep+"VERSION", 'r') as file: + version = file.read().replace("\n", "") + with open("VERSION", 'r') as file: + hubversion = file.read().replace("\n", "") + + def restart_to_update(*args): + warn("[homeui]start update, exit") + python_path = sys.executable + os.execl(python_path, python_path, __file__.replace( + "ui"+os.sep+"homeui.py", "main.py"), "--upgrade", "--dis-permission-error") + + def open_update(*args): + info("[homeui]open in webbrowser") + __import__("webbrowser").open( + "http://git.hmtsai.cn/cxykevin/injectorHub") + + mtk.Frame(buttonlist, height=10).pack(side="left") + mtk.ButtonLight(buttonlist, text="PEinjector "+version, + w=140, func=restart_to_update, color_type="success").pack(side="left") + mtk.ButtonLight(buttonlist, text="Hub "+hubversion, + w=100, color_type="primary", func=open_update).pack(side="left") + buttonlist.pack() + mtk.Frame(first_page, w=10000).pack(fill="both", expand=True) + first_page.pack(fill="both", expand=True) + now_frame = first_page + + +def home_ui(root: mtk.Frame): + global master + install_root_frame = mtk.Frame(root) + master = install_root_frame + show_home_page() + install_root_frame.pack(fill="both", expand=True) diff --git a/ui/installer.py b/ui/installer.py index aaa116c..6d6baba 100644 --- a/ui/installer.py +++ b/ui/installer.py @@ -1,6 +1,5 @@ import json import os -from turtle import bgcolor from magictk import mtk, color_tmpl from magictk import fontconfig from ui.lang import l @@ -12,16 +11,23 @@ from logger.logger import * now_frame = None master: mtk.Frame = None +UPGRADE = 0 def show_first_page(): global now_frame, master first_page = mtk.Frame(master,) mtk.Frame(first_page, w=10000).pack(fill="both", expand=True) - mtk.Label(first_page, text=l("InstallWelcome"), - anchor='center', font=(fontconfig.getfont(), 22), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["primary_text"]).pack(fill='x') - mtk.Label(first_page, text="\n"+l("InstallInfo"), - anchor='center', font=(fontconfig.getfont(), 12), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["secondary_text"]).pack(fill='x') + if (UPGRADE): + mtk.Label(first_page, text=l("UpgradeWelcome"), + anchor='center', font=(fontconfig.getfont(), 22), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["primary_text"]).pack(fill='x') + mtk.Label(first_page, text="\n"+l("InstallInfo"), + anchor='center', font=(fontconfig.getfont(), 12), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["secondary_text"]).pack(fill='x') + else: + mtk.Label(first_page, text=l("UpgradeWelcome"), + anchor='center', font=(fontconfig.getfont(), 22), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["primary_text"]).pack(fill='x') + mtk.Label(first_page, text="\n"+l("InstallInfo"), + anchor='center', font=(fontconfig.getfont(), 12), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["secondary_text"]).pack(fill='x') mtk.Frame(first_page, height=30).pack() buttonlist = mtk.Frame(first_page) @@ -279,8 +285,10 @@ def change_page_finish(): anchor='center', font=(fontconfig.getfont(), 12), background=color_tmpl.default_color["background"], foreground=color_tmpl.default_color["secondary_text"]).pack(fill='x') def closecallback(*args): - info("close from installer") - finish_page.root.quit() + warn("restart from installer") + python_path = sys.executable + os.execl(python_path, python_path, __file__.replace( + "ui"+os.sep+"installer.py", "main.py")) btnframe = mtk.Frame(finish_page, height=30) mtk.ButtonFill(finish_page, text=l( diff --git a/ui/win.py b/ui/win.py index da09e6c..038f7cf 100644 --- a/ui/win.py +++ b/ui/win.py @@ -1,11 +1,13 @@ -from doctest import debug +import shutil from tkinter import messagebox from magictk import mtk from logger.logger import * from logger import config from ui import nav from ui import installer +from ui import homeui from lib import get_disk +from lib import vars from ui.lang import load_lang, l import sys import getpass @@ -29,17 +31,20 @@ def check_args(arg, check): DISPERMISSION = 0 DEBUG = 0 NOTRACE = 0 +UPGRADE = 0 for i in sys.argv[1:]: if (check_args(i, "--lang")): nlang = i.split("=")[-1] - if (check_args(i, "--dis-permission-error")): + elif (check_args(i, "--dis-permission-error")): DISPERMISSION = 1 - if (check_args(i, "--log-level")): + elif (check_args(i, "--log-level")): config.LOGLEVEL = i.split("=")[-1] - if (check_args(i, "--debug")): + elif (check_args(i, "--debug")): DEBUG = 1 - if (check_args(i, "--no-trace")): + elif (check_args(i, "--no-trace")): NOTRACE = 1 + elif (check_args(i, "--upgrade")): + UPGRADE = 1 if (nlang+".toml" not in os.listdir("lang")): nlang = "en_us" @@ -65,8 +70,11 @@ def main(): if (errno == 1): messagebox.showerror("Injector Hub Error", root_disk) sys.exit(1) - elif (errno == 2): - info("[win]cannot find installed disk") + elif (errno == 2 or UPGRADE == 1): + if (UPGRADE == 0): + info("[win]cannot find installed disk") + else: + info("[win]upgrade") if DISPERMISSION == 0: if (platform.system() == "Linux" and getpass.getuser() != "root"): err("permission denied in linux") @@ -84,13 +92,19 @@ def main(): sys.exit(1) else: sys.exit() + installer.UPGRADE = 1 + if (UPGRADE == 1): + if (os.path.exists("software")): + info("[win]clean install cache") + shutil.rmtree("software") nav_list = [ {"icon": "lightning", "frame": installer.installer_ui, "side": "top"} ] else: + vars.DISKMOUNT = root_disk info(f"[win]found installed disk \"{root_disk}\"") nav_list = [ - {"icon": "home-filled", "frame": None, "side": "top"}, + {"icon": "home-filled", "frame": homeui.home_ui, "side": "top"}, {"icon": "dvd", "frame": None, "side": "top"}, {"icon": "plugin", "frame": None, "side": "top"}, {"icon": "setting", "frame": None, "side": "bottom"}