-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.py
More file actions
141 lines (111 loc) · 4.54 KB
/
main.py
File metadata and controls
141 lines (111 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
创建时间: 2025-05-24
作者: Evil0ctal
中文介绍:
SimpleTweakEditor 主程序入口
提供 iOS .deb 包编辑器的启动和命令行接口
支持 GUI 和命令行两种运行模式
英文介绍:
SimpleTweakEditor Main Entry Point
Provides startup and command-line interface for iOS .deb package editor
Supports both GUI and command-line operation modes
"""
import argparse
import os
import platform
import sys
# Check Python version
if sys.version_info < (3, 8):
sys.exit("Error: Python 3.8 or higher is required")
from PyQt6.QtWidgets import QApplication
from PyQt6.QtCore import QTimer, QLoggingCategory
from PyQt6.QtGui import QIcon
from src.core.app import TweakEditorApp
from src.utils.file_operations import batch_unpack_deb, batch_repack_folder
def print_usage():
"""打印命令行使用说明"""
print("iOS .deb Tweak Editor - Command Line Usage")
print("\nBasic Usage:")
print(" python main.py [options] [file.deb|folder]")
print("\nOptions:")
print(" --help, -h Show this help message")
print(" --unpack, -u <deb> Unpack specified .deb file")
print(" --repack, -r <dir> Repack specified folder")
print(" --output, -o <dir> Specify output directory (use with unpack/repack)")
print(" --batch, -b Batch mode, no GUI")
print(" --lang <code> Set language (en/zh)")
print("\nExamples:")
print(" python main.py # Start GUI mode")
print(" python main.py file.deb # Open .deb file in GUI")
print(" python main.py --unpack file.deb # Unpack file.deb")
print(" python main.py -u file.deb -o ~/output # Unpack to specified directory")
print(" python main.py -r ~/tweakfolder # Repack specified folder")
print(" python main.py -b -u *.deb # Batch unpack all deb files")
def setup_qt_environment():
"""设置Qt环境"""
# 忽略macOS上的NSOpenPanel警告
os.environ['QT_MAC_WANTS_LAYER'] = '1'
if platform.system() == "Darwin":
# 禁用Qt调试输出
QLoggingCategory.setFilterRules("*.debug=false")
def parse_arguments():
"""解析命令行参数"""
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--help', '-h', action='store_true', help='Show help message')
parser.add_argument('--unpack', '-u', metavar='DEB_FILE', help='Unpack specified .deb file')
parser.add_argument('--repack', '-r', metavar='FOLDER', help='Repack specified folder')
parser.add_argument('--output', '-o', metavar='DIR', help='Specify output directory')
parser.add_argument('--batch', '-b', action='store_true', help='Batch mode, no GUI')
parser.add_argument('--lang', choices=['en', 'zh'], help='Set language (en/zh)')
parser.add_argument('file_or_folder', nargs='?', help='File or folder to process')
return parser.parse_known_args()
def handle_batch_mode(args):
"""处理批处理模式"""
if args.unpack:
success = batch_unpack_deb(args.unpack, args.output)
sys.exit(0 if success else 1)
elif args.repack:
success = batch_repack_folder(args.repack, args.output)
sys.exit(0 if success else 1)
else:
print("\nError: Batch mode requires --unpack or --repack option")
sys.exit(1)
def main():
"""主函数"""
# 解析命令行参数
args, unknown = parse_arguments()
# 显示帮助
if args.help:
print_usage()
sys.exit(0)
# 批处理模式
if args.batch:
handle_batch_mode(args)
# 设置Qt环境
setup_qt_environment()
# 创建Qt应用程序
app = QApplication(sys.argv)
# 不设置Fusion样式,让qt-material处理
# app.setStyle("Fusion")
# 设置应用程序图标
icon_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'icons', 'app_icon.png')
if os.path.exists(icon_path):
app.setWindowIcon(QIcon(icon_path))
# 创建主应用程序
main_app = TweakEditorApp()
# 设置语言
if args.lang:
main_app.switch_language(args.lang)
# 处理命令行指定的文件或文件夹
input_path = args.file_or_folder or args.unpack or args.repack
if input_path and os.path.exists(input_path):
# 延迟处理输入文件,确保UI已完全加载
QTimer.singleShot(500, lambda: main_app.process_input_path(input_path))
# 显示主窗口
main_app.show()
# 启动应用程序事件循环
sys.exit(app.exec())
if __name__ == "__main__":
main()