完成path添加

This commit is contained in:
cxykevin 2024-02-10 16:15:59 +08:00
parent 6df3c9a197
commit 287afeca04
5 changed files with 45 additions and 11 deletions

1
package/cli/cli/1.bat Normal file
View File

@ -0,0 +1 @@
echo helloworld

View File

@ -29,10 +29,10 @@ import config
import utils
import pickle
import log
import uuid
import shutil
import subprocess
import makelnk
import regwrite
def force_copy(pkg_path, pkg_name, data_list, froms, tos):
@ -161,4 +161,10 @@ def do_action(actions_list):
except:
actionlogs = actionlogs + \
f" make shortcut \"{i[1]}\" failed: {repr(exp)}\r\n"
elif i[0] == 7:
try:
regwrite.add_path(i[1])
except:
actionlogs = actionlogs + \
f" add path \"{i[1]}\" failed: {repr(exp)}\r\n"
return actionlogs

View File

@ -253,14 +253,20 @@ def load_package(pkg_name):
if i not in file_json["start"]["icon"]:
log.warn(f"load moudle [{pkg_name}] warning: " +
f"Load icon syntax error (lost \"{i}\"), igrone")
if len(file_json["start"]["icon"]["icon"]) < 2 or file_json["start"]["icon"]["icon"][1] != ':':
file_json["start"]["icon"]["icon"] = pkg_path + \
"/"+file_json["start"]["icon"]["icon"]
if len(file_json["start"]["icon"]["command"]) < 2 or file_json["start"]["icon"]["command"][1] != ':':
file_json["start"]["icon"]["command"] = pkg_path + \
"/"+file_json["start"]["icon"]["command"]
actions["onload"].append(
(6, file_json["start"]["icon"]["command"], file_json["start"]["icon"]["icon"], file_json["start"]["icon"]["name"]))
if len(file_json["start"]["icon"]["icon"]) < 2 or file_json["start"]["icon"]["icon"][1] != ':':
file_json["start"]["icon"]["icon"] = pkg_path + \
"/"+file_json["start"]["icon"]["icon"]
if len(file_json["start"]["icon"]["command"]) < 2 or file_json["start"]["icon"]["command"][1] != ':':
file_json["start"]["icon"]["command"] = pkg_path + \
"/"+file_json["start"]["icon"]["command"]
actions["onload"].append(
(6, file_json["start"]["icon"]["command"], file_json["start"]["icon"]["icon"], file_json["start"]["icon"]["name"]))
if "path" in file_json["start"]:
for i in file_json["start"]["path"]:
if len(i) < 2 or i[1] != ':':
i = pkg_path + \
"/"+i
actions["onload"].append((7, i))
def load():

View File

@ -1,3 +1,7 @@
#####################################
## PEinjector/makelnk ##
#####################################
import os
import log
import pylnk3
@ -14,8 +18,6 @@ for i in os.listdir(f"{sysdrive}\\Users"):
def makelnk(name, exepath, iconpath):
print(f"{sysdrive}\\Users\\{username}" +
f"\\Desktop\\{name}.lnk")
log.info(f"make shortcut \"{name}\"")
pylnk3.for_file(exepath,
lnk_name=f"{sysdrive}\\Users\\{username}" +

19
src/regwrite.py Normal file
View File

@ -0,0 +1,19 @@
#####################################
## PEinjector/regwrite ##
#####################################
import winreg
import log
def add_path(path):
log.info(f"add path \"{path}\"")
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", 0, winreg.KEY_READ) as key:
old_path = winreg.QueryValueEx(key, "Path")[0]
if old_path[-1] != ';':
old_path = old_path+";"
new_path = old_path+path.replace("/", "\\")
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", 0, winreg.KEY_WRITE) as key:
winreg.SetValueEx(key, "Path", 0, winreg.REG_EXPAND_SZ, new_path)