Upload main.py with huggingface_hub
Browse files
main.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Android Data Recovery - Main Entry Point
|
| 3 |
+
======================================
|
| 4 |
+
|
| 5 |
+
Main application entry point for Android Data Recovery.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import sys
|
| 9 |
+
import os
|
| 10 |
+
import logging
|
| 11 |
+
from datetime import datetime
|
| 12 |
+
from PyQt6.QtWidgets import QApplication, QMessageBox # type: ignore
|
| 13 |
+
from PyQt6.QtCore import Qt # type: ignore
|
| 14 |
+
|
| 15 |
+
# Add project root to path
|
| 16 |
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
| 17 |
+
|
| 18 |
+
from core.adb_manager import ADBManager
|
| 19 |
+
from gui.main_window import MainWindow
|
| 20 |
+
from gui.styles import DARK_THEME
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def setup_logging():
|
| 24 |
+
"""Setup application logging."""
|
| 25 |
+
# Create logs directory
|
| 26 |
+
logs_dir = os.path.join(os.path.dirname(__file__), "logs")
|
| 27 |
+
os.makedirs(logs_dir, exist_ok=True)
|
| 28 |
+
|
| 29 |
+
# Setup logging
|
| 30 |
+
log_file = os.path.join(
|
| 31 |
+
logs_dir,
|
| 32 |
+
f"recovery_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
logging.basicConfig(
|
| 36 |
+
level=logging.INFO,
|
| 37 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
| 38 |
+
handlers=[
|
| 39 |
+
logging.FileHandler(log_file, encoding='utf-8'),
|
| 40 |
+
logging.StreamHandler(sys.stdout)
|
| 41 |
+
]
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
return logging.getLogger(__name__)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def check_adb():
|
| 48 |
+
"""Check if ADB is available."""
|
| 49 |
+
try:
|
| 50 |
+
import subprocess
|
| 51 |
+
result = subprocess.run(
|
| 52 |
+
["adb", "version"],
|
| 53 |
+
capture_output=True,
|
| 54 |
+
text=True,
|
| 55 |
+
timeout=5
|
| 56 |
+
)
|
| 57 |
+
if result.returncode == 0:
|
| 58 |
+
return True
|
| 59 |
+
except Exception:
|
| 60 |
+
pass
|
| 61 |
+
return False
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def main():
|
| 65 |
+
"""Main application entry point."""
|
| 66 |
+
# Setup logging
|
| 67 |
+
logger = setup_logging()
|
| 68 |
+
logger.info("Starting Android Data Recovery")
|
| 69 |
+
|
| 70 |
+
# Create Qt application
|
| 71 |
+
app = QApplication(sys.argv)
|
| 72 |
+
app.setApplicationName("Android Data Recovery")
|
| 73 |
+
app.setApplicationVersion("1.0.0")
|
| 74 |
+
app.setOrganizationName("AndroidDataRecovery")
|
| 75 |
+
|
| 76 |
+
# High DPI scaling is enabled by default in PyQt6 6.6+
|
| 77 |
+
# These attributes were removed in newer versions
|
| 78 |
+
|
| 79 |
+
# Check ADB availability
|
| 80 |
+
if not check_adb():
|
| 81 |
+
reply = QMessageBox.question(
|
| 82 |
+
None,
|
| 83 |
+
"ADB Não Encontrado",
|
| 84 |
+
"ADB (Android Debug Bridge) não foi encontrado no sistema.\n\n"
|
| 85 |
+
"O aplicativo pode não funcionar corretamente sem ADB.\n\n"
|
| 86 |
+
"Deseja continuar mesmo assim?",
|
| 87 |
+
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
| 88 |
+
QMessageBox.StandardButton.No
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
if reply == QMessageBox.StandardButton.No:
|
| 92 |
+
logger.warning("Application terminated due to missing ADB")
|
| 93 |
+
sys.exit(1)
|
| 94 |
+
|
| 95 |
+
logger.warning("ADB not found, continuing anyway")
|
| 96 |
+
|
| 97 |
+
# Initialize ADB manager
|
| 98 |
+
try:
|
| 99 |
+
adb_manager = ADBManager()
|
| 100 |
+
logger.info("ADB manager initialized successfully")
|
| 101 |
+
except Exception as e:
|
| 102 |
+
logger.error(f"Failed to initialize ADB manager: {e}")
|
| 103 |
+
QMessageBox.critical(
|
| 104 |
+
None,
|
| 105 |
+
"Erro de Inicialização",
|
| 106 |
+
f"Falha ao inicializar o gerenciador ADB:\n{str(e)}\n\n"
|
| 107 |
+
"Por favor, instale o Android SDK Platform Tools."
|
| 108 |
+
)
|
| 109 |
+
sys.exit(1)
|
| 110 |
+
|
| 111 |
+
# Create and show main window
|
| 112 |
+
try:
|
| 113 |
+
window = MainWindow(adb_manager)
|
| 114 |
+
window.show()
|
| 115 |
+
logger.info("Main window displayed")
|
| 116 |
+
except Exception as e:
|
| 117 |
+
logger.error(f"Failed to create main window: {e}")
|
| 118 |
+
QMessageBox.critical(
|
| 119 |
+
None,
|
| 120 |
+
"Erro de Inicialização",
|
| 121 |
+
f"Falha ao criar a janela principal:\n{str(e)}"
|
| 122 |
+
)
|
| 123 |
+
sys.exit(1)
|
| 124 |
+
|
| 125 |
+
# Run application
|
| 126 |
+
logger.info("Application started successfully")
|
| 127 |
+
exit_code = app.exec()
|
| 128 |
+
|
| 129 |
+
# Cleanup
|
| 130 |
+
logger.info(f"Application exiting with code: {exit_code}")
|
| 131 |
+
sys.exit(exit_code)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
if __name__ == "__main__":
|
| 135 |
+
main()
|