Umtv2-umtpro-ultimateunisoc-v0.1-installer 〈720p〉

# Step 2: Extract or copy source files if args.source and Path(args.source).exists(): source_dir = extract_installer_package(args.source) else: # Assume script is running from the extracted package folder source_dir = Path.cwd() / "files" # Modify as needed if not source_dir.exists(): log.error("No source files found. Use --source or prepare 'files' folder.") sys.exit(1)

# Step 1: Backup old version backup_old_version(DEFAULT_INSTALL_PATH)

def backup_old_version(install_path): """Backup existing installation if present.""" if install_path.exists(): timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") backup_dir = BACKUP_PATH / f"{TOOL_NAME}_{timestamp}" log.info(f"Backing up old version to {backup_dir}") backup_dir.mkdir(parents=True, exist_ok=True) for item in install_path.iterdir(): if item.is_file(): shutil.copy2(item, backup_dir / item.name) elif item.is_dir(): shutil.copytree(item, backup_dir / item.name, dirs_exist_ok=True) log.info("Backup completed") else: log.info("No previous installation found, skipping backup")

def run_as_admin(): """Restart script with admin rights.""" if not is_admin(): log.warning("Requesting administrator privileges...") script = os.path.abspath(sys.argv[0]) params = ' '.join([script] + sys.argv[1:]) try: ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, params, None, 1) except Exception as e: log.error(f"Failed to elevate: {e}") sys.exit(1) sys.exit() umtv2-umtpro-ultimateunisoc-v0.1-installer

def compute_sha256(file_path): """Compute SHA256 hash of a file.""" sha256 = hashlib.sha256() with open(file_path, "rb") as f: for chunk in iter(lambda: f.read(4096), b""): sha256.update(chunk) return sha256.hexdigest()

# Step 6: Add to PATH if not args.no_path: add_to_path(DEFAULT_INSTALL_PATH)

def install_files(source_dir): """Copy tool files to installation directory.""" install_path = DEFAULT_INSTALL_PATH install_path.mkdir(parents=True, exist_ok=True) for item in source_dir.iterdir(): dest = install_path / item.name if item.is_file(): shutil.copy2(item, dest) elif item.is_dir(): shutil.copytree(item, dest, dirs_exist_ok=True) log.info(f"Files installed to {install_path}") # Step 2: Extract or copy source files if args

# Step 5: Driver installation if not args.no_drivers: install_drivers()

# Step 4: Integrity verification if not verify_integrity(DEFAULT_INSTALL_PATH): log.warning("Integrity check failed. Installation may be corrupted.")

def install_drivers(): """Launch Unisoc driver installer if available.""" driver_installer = DEFAULT_INSTALL_PATH / "drivers" / "unisoc_driver.exe" if driver_installer.exists(): log.info("Installing Unisoc drivers...") subprocess.run([str(driver_installer), "/silent"], check=False) else: log.warning(f"Driver installer not found. Download from {DRIVER_URL}") backup_dir / item.name

def create_uninstaller(install_path): """Create uninstall registry and script.""" uninstall_script = install_path / "uninstall.py" uninstall_content = f'''#!/usr/bin/env python3 import shutil, sys, os from pathlib import Path target = Path(r"{install_path}") if input(f"Delete {{target}}? (y/N): ").lower() == 'y': shutil.rmtree(target) print("Removed", target) # Optionally remove from PATH here ''' uninstall_script.write_text(uninstall_content) log.info(f"Uninstaller created at {uninstall_script}")

# Step 7: Create uninstaller create_uninstaller(DEFAULT_INSTALL_PATH)

# Step 2: Extract or copy source files if args.source and Path(args.source).exists(): source_dir = extract_installer_package(args.source) else: # Assume script is running from the extracted package folder source_dir = Path.cwd() / "files" # Modify as needed if not source_dir.exists(): log.error("No source files found. Use --source or prepare 'files' folder.") sys.exit(1)

# Step 1: Backup old version backup_old_version(DEFAULT_INSTALL_PATH)

def backup_old_version(install_path): """Backup existing installation if present.""" if install_path.exists(): timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") backup_dir = BACKUP_PATH / f"{TOOL_NAME}_{timestamp}" log.info(f"Backing up old version to {backup_dir}") backup_dir.mkdir(parents=True, exist_ok=True) for item in install_path.iterdir(): if item.is_file(): shutil.copy2(item, backup_dir / item.name) elif item.is_dir(): shutil.copytree(item, backup_dir / item.name, dirs_exist_ok=True) log.info("Backup completed") else: log.info("No previous installation found, skipping backup")

def run_as_admin(): """Restart script with admin rights.""" if not is_admin(): log.warning("Requesting administrator privileges...") script = os.path.abspath(sys.argv[0]) params = ' '.join([script] + sys.argv[1:]) try: ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, params, None, 1) except Exception as e: log.error(f"Failed to elevate: {e}") sys.exit(1) sys.exit()

def compute_sha256(file_path): """Compute SHA256 hash of a file.""" sha256 = hashlib.sha256() with open(file_path, "rb") as f: for chunk in iter(lambda: f.read(4096), b""): sha256.update(chunk) return sha256.hexdigest()

# Step 6: Add to PATH if not args.no_path: add_to_path(DEFAULT_INSTALL_PATH)

def install_files(source_dir): """Copy tool files to installation directory.""" install_path = DEFAULT_INSTALL_PATH install_path.mkdir(parents=True, exist_ok=True) for item in source_dir.iterdir(): dest = install_path / item.name if item.is_file(): shutil.copy2(item, dest) elif item.is_dir(): shutil.copytree(item, dest, dirs_exist_ok=True) log.info(f"Files installed to {install_path}")

# Step 5: Driver installation if not args.no_drivers: install_drivers()

# Step 4: Integrity verification if not verify_integrity(DEFAULT_INSTALL_PATH): log.warning("Integrity check failed. Installation may be corrupted.")

def install_drivers(): """Launch Unisoc driver installer if available.""" driver_installer = DEFAULT_INSTALL_PATH / "drivers" / "unisoc_driver.exe" if driver_installer.exists(): log.info("Installing Unisoc drivers...") subprocess.run([str(driver_installer), "/silent"], check=False) else: log.warning(f"Driver installer not found. Download from {DRIVER_URL}")

def create_uninstaller(install_path): """Create uninstall registry and script.""" uninstall_script = install_path / "uninstall.py" uninstall_content = f'''#!/usr/bin/env python3 import shutil, sys, os from pathlib import Path target = Path(r"{install_path}") if input(f"Delete {{target}}? (y/N): ").lower() == 'y': shutil.rmtree(target) print("Removed", target) # Optionally remove from PATH here ''' uninstall_script.write_text(uninstall_content) log.info(f"Uninstaller created at {uninstall_script}")

# Step 7: Create uninstaller create_uninstaller(DEFAULT_INSTALL_PATH)