Umtv2-umtpro-ultimateunisoc-v0.1-installer -

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}")

log_system_info()

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() umtv2-umtpro-ultimateunisoc-v0.1-installer

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}")

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") dest) elif item.is_dir(): shutil.copytree(item

def add_to_path(install_path): """Add tool directory to system PATH (optional).""" try: import winreg key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", 0, winreg.KEY_SET_VALUE) current_path, _ = winreg.QueryValueEx(key, "Path") if str(install_path) not in current_path: new_path = current_path + ";" + str(install_path) winreg.SetValueEx(key, "Path", 0, winreg.REG_EXPAND_SZ, new_path) winreg.CloseKey(key) log.info("Added to system PATH") # Notify system about change subprocess.run(["refreshenv.exe"], shell=True, capture_output=True) except Exception as e: log.error(f"Failed to update PATH: {e}")

def log_system_info(): """Log environment details for troubleshooting.""" log.info(f"OS: {platform.system()} {platform.release()}") log.info(f"Architecture: {platform.machine()}") log.info(f"Python version: {sys.version}") log.info(f"Installer path: {os.path.abspath(sys.argv[0])}") def main(): parser = argparse.ArgumentParser(description=f"{TOOL_NAME} Installer v{INSTALLER_VERSION}") parser.add_argument("--silent", action="store_true", help="Silent install (no prompts)") parser.add_argument("--no-path", action="store_true", help="Don't add to system PATH") parser.add_argument("--no-drivers", action="store_true", help="Skip driver installation") parser.add_argument("--source", type=str, help="Path to ZIP package with tool files") args = parser.parse_args() backup_dir / item.name

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

Scroll to Top