#!/usr/bin/env python3
"""IEC-60870-5-103 模拟主站调试工具"""

import sys, os

INSTALL_DIR = "/opt/apps/iec103-master-tool"

# 优先读取安装目录配置 (postinst 写入), 缺省回退默认路径
_conf = "/etc/iec103-master-tool.conf"
try:
    if os.path.isfile(_conf):
        with open(_conf, "r", encoding="utf-8") as _f:
            for _line in _f:
                _line = _line.strip()
                if _line.startswith("INSTALL_DIR="):
                    _v = _line.split("=", 1)[1].strip().strip('"').strip("'")
                    if _v:
                        INSTALL_DIR = _v
                        break
except Exception:
    pass

sys.path.insert(0, INSTALL_DIR)
os.chdir(INSTALL_DIR)

try:
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtCore import Qt
except ImportError:
    print("错误: 需要 python3-pyqt5, 请执行: sudo apt-get install python3-pyqt5")
    sys.exit(1)

from main import main
sys.exit(main())
