import os import sys import subprocess import ctypes if '-m' in sys.argv: sys.exit(0) from PyQt5.QtWidgets import QApplication from PyQt5.QtCore import QSharedMemory from core.activator import Activator from utils.helpers import hide_console from utils.logger import setup_logger from monitors.security_monitor import SecurityMonitor from gui.dialogs import CustomAlertBox class SingleInstanceApp: def __init__(self, key): self.shared_memory = QSharedMemory(key) def is_running(self): if self.shared_memory.attach(): return True else: if self.shared_memory.create(1): return False else: return True def release(self): if self.shared_memory.isAttached(): self.shared_memory.detach() def app_dir(): """Retorna el directorio donde está el ejecutable real (no el temp)""" if getattr(sys, 'frozen', False): return os.path.dirname(os.path.abspath(sys.executable)) else: return os.path.dirname(os.path.abspath(__file__)) BASE_DIR = app_dir() def run_updater_check(logger): updater = os.path.join(BASE_DIR, 'extra', 'updater.exe') if not os.path.exists(updater): logger.warning(f'Updater not found at: {updater}') return False else: try: result = subprocess.run([updater, '--check'], cwd=BASE_DIR, shell=False, timeout=30) return result.returncode == 10 except Exception as e: logger.error(f'Error running updater: {e}') return False def main(): logger = setup_logger() if run_updater_check(logger): logger.info('Update available, launching updater') updater_path = os.path.join(BASE_DIR, 'extra', 'updater.exe') try: subprocess.Popen([updater_path], cwd=BASE_DIR, shell=False, creationflags=subprocess.DETACHED_PROCESS | subprocess.CREATE_NEW_PROCESS_GROUP) except Exception as e: logger.error(f'Error launching updater: {e}') return 0 else: if sys.platform == 'win32': try: myappid = 'com.bookra1n.a12.1.0' ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid) except Exception as e: logger.warning(f'Could not set App ID: {e}') logger.debug('Application starting...') SecurityMonitor.configure(logger) hide_console() app = QApplication(sys.argv) app.setApplicationName('Bookra1n A12 Bypass') single_instance = SingleInstanceApp('Bookra1n_A12_SingleInstance_Key_2024') if single_instance.is_running(): logger.warning('Application is already running!') dialog = CustomAlertBox('Closing app', 'Bookra1n is already running.') dialog.exec_() return 0 else: try: window = Activator(logger) window.show() exit_code = app.exec_() logger.debug(f'Application closing with exit code: {exit_code}') return exit_code except Exception as e: logger.error(f'Fatal error in application: {e}', exc_info=True) return 1 if __name__ == '__main__': sys.exit(main())