-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
124 lines (100 loc) · 4.2 KB
/
Copy pathmain.py
File metadata and controls
124 lines (100 loc) · 4.2 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
# -*- coding: utf-8 -*-
"""
main.py - Application entry point for RuntimeFix
"""
import json
import os
import platform
import sys
import traceback
# core/ klasörünü Python modül yoluna ekle
_ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(_ROOT_DIR, "core"))
from PyQt6.QtWidgets import QApplication, QMessageBox # noqa: E402
from security import SecurityManager # noqa: E402
from ui import MainWindow, configure_application # noqa: E402
from utils import is_admin, relaunch_as_admin, setup_logging # noqa: E402
from app_info import APP_NAME, APP_PUBLISHER, APP_VERSION # noqa: E402
logger = setup_logging()
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
LOCAL_CONFIG = os.path.join(BASE_DIR, "data", "config.json")
def _load_local_config() -> dict:
with open(LOCAL_CONFIG, encoding="utf-8") as fh:
return json.load(fh)
def load_config() -> dict:
# Config yalnızca yerel dosyadan okunur. (Eski "uzak config güncelleme"
# mekanizması kaldırıldı: imzasız uzak config, allowed_domains ve sha256
# değerlerini değiştirebildiği için güvenlik riskiydi ve kullanılmıyordu.)
try:
return _load_local_config()
except Exception as exc:
logger.critical(f"Cannot load data/config.json: {exc}")
raise SystemExit(f"Cannot load data/config.json:\n{exc}") from exc
def main() -> None:
logger.info("=" * 60)
logger.info(f" RuntimeFix v{APP_VERSION}")
logger.info(f" Python: {platform.python_version()} | Platform: {platform.system()} {platform.release()}")
logger.info("=" * 60)
logger.info("Program başlatılıyor...")
app = QApplication(sys.argv)
app.setApplicationName(APP_NAME)
app.setOrganizationName(APP_PUBLISHER)
app.setApplicationVersion(APP_VERSION)
configure_application(app)
# Admin check
if platform.system() == "Windows":
if not is_admin():
logger.info("Yönetici yetkisi yok — UAC yükseltmesi isteniyor...")
if relaunch_as_admin():
sys.exit(0)
else:
QMessageBox.critical(
None, "Administrator Required",
"This program must be run as administrator.\n"
"Right-click → Run as administrator."
)
sys.exit(1)
logger.info("✔ Yönetici yetkileriyle çalışıyor.")
# Load config
try:
config = load_config()
except SystemExit as exc:
QMessageBox.critical(None, "Configuration Error", str(exc))
sys.exit(1)
components = config.get("components", [])
allowed_domains = config.get("allowed_domains", [])
logger.info(f"✔ data/config.json yüklendi — {len(components)} bileşen tanımlı")
logger.info(f" İzin verilen domainler: {', '.join(allowed_domains[:5])}{'...' if len(allowed_domains) > 5 else ''}")
if not components:
QMessageBox.warning(None, "Empty Config",
"data/config.json contains no components.")
sys.exit(0)
security = SecurityManager(allowed_domains if allowed_domains else None)
logger.info("✔ Ana pencere oluşturuluyor...")
window = MainWindow(components, security, APP_VERSION)
window.show()
logger.info("✔ Program hazır — kullanıcı etkileşimi bekleniyor")
logger.info("-" * 60)
exit_code = app.exec()
logger.info(f"Program kapatıldı (exit code={exit_code})")
sys.exit(exit_code)
if __name__ == "__main__":
try:
main()
except Exception:
tb = traceback.format_exc()
logger.critical(f"Unhandled exception:\n{tb}")
summary = tb.strip().splitlines()[-1] if tb.strip() else "Bilinmeyen hata"
try:
error_app = QApplication.instance() or QApplication([])
configure_application(error_app)
QMessageBox.critical(
None,
"RuntimeFix — Beklenmeyen Hata",
"Program beklenmeyen bir hatayla kapandı.\n\n"
f"{summary}\n\n"
"Teknik ayrıntılar RuntimeFix log dosyasına kaydedildi.",
)
except Exception:
print(f"RuntimeFix beklenmeyen hata:\n{tb}", file=sys.stderr)
sys.exit(1)