添加更多命令行功能

This commit is contained in:
cxykevin 2024-05-04 22:07:05 +08:00
parent 01a31a2578
commit f329f83ec0
1 changed files with 58 additions and 5 deletions

View File

@ -32,8 +32,31 @@ DISPERMISSION = 0
DEBUG = 0
NOTRACE = 0
UPGRADE = 0
DEVICE = ""
SHOW_VERSION = 0
for i in sys.argv[1:]:
if (check_args(i, "--lang")):
if (check_args(i, "/?") or check_args(i, "--help")):
print(""" injector Hub
Usage: hub [options]
Options:
--help Show this help info and exit
--version, -V Get hub version
--lang=<zh_cn/en_us> Set language
--install, -i Install PEinjector
--upgrade, -U Upgrade PEinjector
--device, -D Set device (mount path)
--clean Clean download cache
Debug Options:
--debug Open debug mode (raise all errors)
--dis-permission-error Do not show permission error
--log-level=<level> Set log level (debug,info,warning,err)
--no-trace Do not trace OS version
""")
sys.exit()
elif (check_args(i, "--lang")):
nlang = i.split("=")[-1]
elif (check_args(i, "--dis-permission-error")):
DISPERMISSION = 1
@ -43,8 +66,22 @@ for i in sys.argv[1:]:
DEBUG = 1
elif (check_args(i, "--no-trace")):
NOTRACE = 1
elif (check_args(i, "--upgrade")):
elif (check_args(i, "--upgrade") or check_args(i, "-U")):
UPGRADE = 1
elif (check_args(i, "--install") or check_args(i, "-i")):
UPGRADE = 2
elif (check_args(i, "--device") or check_args(i, "-D")):
DEVICE = i.split("=")[-1]
elif (check_args(i, "--clean")):
if (os.path.exists("software")):
info("[win]clean install cache")
shutil.rmtree("software")
sys.exit()
elif (check_args(i, "--version") or check_args(i, "-V")):
SHOW_VERSION = 1
else:
print("Unknown Command: \""+i+"\"\nUse Command \"--help\" to get info")
sys.exit(128)
if (nlang+".toml" not in os.listdir("lang")):
nlang = "en_us"
@ -66,14 +103,30 @@ def main():
disk_res = get_disk.find_hub_disk()
errno = disk_res[0]
if (DEVICE == ""):
root_disk = disk_res[1]
else:
root_disk = DEVICE
if (errno == 1):
messagebox.showerror("Injector Hub Error", root_disk)
sys.exit(1)
elif (errno == 2 or UPGRADE == 1):
if (SHOW_VERSION == 1):
with open("VERSION", 'r') as file:
ver = file.read()
print(f" injector Hub \n\nHub Version: "+ver)
if (DEVICE == "" and errno == 2):
print("PEinjector Version: Not Found")
elif not (os.path.exists(root_disk+os.sep+"PEinjector"+os.sep+"VERSION")):
print("PEinjector Version: Not Found")
else:
with open(root_disk+os.sep+"PEinjector"+os.sep+"VERSION", 'r') as file:
pver = file.read()
print("PEinjector Version: "+pver)
sys.exit()
if (errno == 2 or UPGRADE == 1 or UPGRADE == 2):
if (UPGRADE == 0):
info("[win]cannot find installed disk")
else:
elif (UPGRADE == 1):
info("[win]upgrade")
if DISPERMISSION == 0:
if (platform.system() == "Linux" and getpass.getuser() != "root"):