This repository was archived by the owner on Dec 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
90 lines (69 loc) · 2.51 KB
/
Copy pathmain.py
File metadata and controls
90 lines (69 loc) · 2.51 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
# main.py
import sys
import logging
from logging.handlers import RotatingFileHandler
import os
from PyQt6.QtWidgets import QApplication, QMessageBox
from PyQt6.QtGui import QImageReader, QIcon
from config import APP_LOG_DIR, load_settings
from language import t
from utils import icon_cache
from utils.paths import resource_path
def setup_logging():
"""配置全局日志记录器。"""
if not os.path.exists(APP_LOG_DIR):
os.makedirs(APP_LOG_DIR)
log_file = os.path.join(APP_LOG_DIR, "oracipher.log")
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
handler = RotatingFileHandler(
log_file, maxBytes=1 * 1024 * 1024, backupCount=5, encoding="utf-8"
)
handler.setFormatter(formatter)
root_logger = logging.getLogger()
log_level = os.getenv("LOG_LEVEL", "INFO").upper()
root_logger.setLevel(log_level)
root_logger.addHandler(handler)
logger = logging.getLogger(__name__)
logger.info("=" * 60)
logger.info(f"Oracipher Application Starting Up (Log Level: {log_level})")
logger.info(f"Logging configured. Log file at: {log_file}")
logger.info("=" * 60)
def main():
"""主函数,用于启动应用程序。"""
setup_logging()
logger = logging.getLogger(__name__)
app = QApplication(sys.argv)
supported_formats = [
f.data().decode("ascii").lower() for f in QImageReader.supportedImageFormats()
]
if "svg" not in supported_formats:
logger.critical("CRITICAL ERROR: SVG image format is NOT supported.")
QMessageBox.critical(
None,
"Critical Error",
"This application requires SVG image format support, which is missing in your current Qt installation.\nThe application will now exit.",
)
sys.exit(1)
try:
settings = load_settings()
t.set_language(settings.get("language", "zh_CN"))
except Exception as e:
logger.critical(f"Failed to load settings or set language: {e}", exc_info=True)
t.set_language("zh_CN")
icon_cache.preload()
from app import SafeKeyApp
logo_path = resource_path("images/icon-256.png")
app_icon = QIcon(logo_path)
if app_icon.isNull():
logger.critical(
f"Failed to load application icon from path: {logo_path}. The icon will be missing."
)
app.setWindowIcon(app_icon)
window = SafeKeyApp()
window.setWindowIcon(app_icon)
window.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()