Skip to content

Commit

Permalink
feat:添加自动保存log 和 打开插件目录功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzdyl committed Oct 7, 2024
1 parent 074603c commit 04eae4f
Showing 1 changed file with 78 additions and 31 deletions.
109 changes: 78 additions & 31 deletions LaunchQQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def get_qq_exe_path():
raise FileNotFoundError("未选择 QQ.exe 文件。")
return file_path


def read_registry_key(hive, subkey, value_name):
try:
# 打开指定的注册表项
Expand All @@ -41,35 +40,43 @@ def read_registry_key(hive, subkey, value_name):

def launch_qq(exe_path):
"""
启动 QQ.exe,并附加参数 --enable-logging,同时打印启动过程中的输出内容
启动 QQ.exe,并附加参数 --enable-logging,同时将启动过程中的输出内容保存到桌面日志文件中
:param exe_path: QQ.exe 的完整路径
"""
try:
print(f"正在启动 QQ: {exe_path} --enable-logging")
# 获取桌面路径
desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
log_file_path = os.path.join(desktop_path, "qq_launch_log.txt")

# 启动 QQ.exe 并附加参数 --enable-logging
process = subprocess.Popen(
[exe_path, '--enable-logging'],
stdout=subprocess.PIPE, # 捕获标准输出
stderr=subprocess.PIPE, # 捕获标准错误
text=True, # 以文本模式处理输出
encoding='utf-8', # 显式指定编码为 UTF-8
errors='replace' # 替换无法解码的字节
)
print(f"正在启动 QQ: {exe_path} --enable-logging")
print(f"日志将保存到: {log_file_path}")

# 实时打印标准输出和标准错误
for stdout_line in iter(process.stdout.readline, ''):
print(stdout_line, end='')

for stderr_line in iter(process.stderr.readline, ''):
print(stderr_line, end='', file=sys.stderr)
with open(log_file_path, 'w', encoding='utf-8') as log_file:
# 启动 QQ.exe 并附加参数 --enable-logging
process = subprocess.Popen(
[exe_path, '--enable-logging'],
stdout=subprocess.PIPE, # 捕获标准输出
stderr=subprocess.PIPE, # 捕获标准错误
text=True, # 以文本模式处理输出
encoding='utf-8', # 显式指定编码为 UTF-8
errors='replace' # 替换无法解码的字节
)

# 实时打印并保存标准输出和标准错误
for stdout_line in iter(process.stdout.readline, ''):
print(stdout_line, end='')
log_file.write(stdout_line)

process.stdout.close()
process.stderr.close()
process.wait()

print("QQ 已启动。")
for stderr_line in iter(process.stderr.readline, ''):
print(stderr_line, end='', file=sys.stderr)
log_file.write(stderr_line)

process.stdout.close()
process.stderr.close()
process.wait()

print("QQ 已启动,日志已保存。")
except Exception as e:
print(f"启动 QQ 失败: {e}")
traceback.print_exc()
Expand All @@ -91,19 +98,59 @@ def get_qq_path():

return qq_exe_path

def main():
def open_plugin_folder(file_path):
try:
qq_exe_path = get_qq_path()
file_path = os.path.dirname(qq_exe_path)

# 启动 QQ.exe
launch_qq(qq_exe_path)
# 获取LITELOADERQQNT_PROFILE和ML_LITELOADERQQNT_TEMP环境变量的值
lite_loader_profile = os.getenv("LITELOADERQQNT_PROFILE")
lite_loader_temp = os.getenv("ML_LITELOADERQQNT_TEMP")

# 如果环境变量不存在,则使用默认路径
default_path = os.path.join(file_path, "resources", "app", "LiteLoaderQQNT", "plugins")
if lite_loader_profile:
plugin_path = os.path.join(lite_loader_profile, "plugins")
elif lite_loader_temp:
print(
"未能检测到LITELOADERQQNT_PROFILE,但检测到安装器临时环境变量,使用安装器临时环境变量")
plugin_path = os.path.join(lite_loader_temp, "plugins")
else:
print("未能检测到LITELOADERQQNT_PROFILE,使用默认路径")
plugin_path = default_path

if os.path.exists(plugin_path):
os.startfile(plugin_path)
else:
print(f"插件文件夹不存在: {plugin_path}")

except Exception as e:
print(f"发生错误: {e}")

def main():
try:
while True:
print("请选择一个操作:")
print("1. 带log启动QQ")
print("2. 打开插件文件夹")
print("3. 退出")

choice = input("请输入选项: ")

qq_exe_path = get_qq_path()
file_path = os.path.dirname(qq_exe_path)

if choice == '1':
launch_qq(qq_exe_path)
elif choice == '2':
open_plugin_folder(file_path)
elif choice == '3':
print("退出程序")
break
else:
print("无效的选项,请重新选择。")

except Exception as e:
print(f"发生错误: {e}")
traceback.print_exc()
input("按 回车键 退出。")



if __name__ == "__main__":
main()

0 comments on commit 04eae4f

Please sign in to comment.