#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
SQLite数据库查看器启动脚本
"""

import sys
import os
from loguru import logger

def check_dependencies():
    """检查依赖包"""
    missing_deps = []
    
    try:
        import PySide6
    except ImportError:
        missing_deps.append("PySide6")
    
    try:
        import loguru
    except ImportError:
        missing_deps.append("loguru")
    
    if missing_deps:
        print("❌ 缺少以下依赖包:")
        for dep in missing_deps:
            print(f"   - {dep}")
        print("\n请使用以下命令安装:")
        print("pip install -r requirements_gui.txt")
        return False
    
    return True

def main():
    """主函数"""
    logger.info("启动SQLite数据库查看器")
    
    # 检查依赖
    if not check_dependencies():
        sys.exit(1)
    
    # 导入主程序
    try:
        from sqlite_viewer import main as viewer_main
    except ImportError as e:
        logger.error(f"导入主程序失败: {e}")
        print("❌ 无法导入主程序，请检查文件是否存在")
        sys.exit(1)
    
    # 运行主程序
    try:
        viewer_main()
    except Exception as e:
        logger.error(f"程序运行错误: {e}")
        print(f"❌ 程序运行错误: {e}")
        sys.exit(1)

if __name__ == "__main__":
    main()