diff options
Diffstat (limited to 'py_modules/lsfg_vk/installation.py')
| -rw-r--r-- | py_modules/lsfg_vk/installation.py | 84 |
1 files changed, 65 insertions, 19 deletions
diff --git a/py_modules/lsfg_vk/installation.py b/py_modules/lsfg_vk/installation.py index 767a97a..d193219 100644 --- a/py_modules/lsfg_vk/installation.py +++ b/py_modules/lsfg_vk/installation.py @@ -51,8 +51,11 @@ class InstallationService(BaseService): # Extract and install files self._extract_and_install_files(zip_path) - # Create the lsfg script - self._create_lsfg_script() + # Create the config file + self._create_config_file() + + # Create the lsfg launch script + self._create_lsfg_launch_script() self.log.info("lsfg-vk installed successfully") return {"success": True, "message": "lsfg-vk installed successfully", "error": None} @@ -102,17 +105,38 @@ class InstallationService(BaseService): shutil.copy2(src_file, dst_file) self.log.info(f"Copied {file} to {dst_file}") - def _create_lsfg_script(self) -> None: - """Create the lsfg script in home directory with default configuration""" - # Get default configuration - defaults = ConfigurationManager.get_defaults() + def _create_config_file(self) -> None: + """Create the TOML config file in ~/.config/lsfg-vk with default configuration and detected DLL path""" + # Import here to avoid circular imports + from .dll_detection import DllDetectionService + + # Try to detect DLL path + dll_service = DllDetectionService(self.log) + config = ConfigurationManager.get_defaults_with_dll_detection(dll_service) + + # Generate TOML content using centralized manager + toml_content = ConfigurationManager.generate_toml_content(config) - # Generate script content using centralized manager - script_content = ConfigurationManager.generate_script_content(defaults) + # Write initial config file + self._write_file(self.config_file_path, toml_content, 0o644) + self.log.info(f"Created config file at {self.config_file_path}") - # Use atomic write to prevent corruption - self._atomic_write(self.lsfg_script_path, script_content, 0o755) - self.log.info(f"Created executable lsfg script at {self.lsfg_script_path}") + # Log detected DLL path if found + if config["dll"]: + self.log.info(f"Configured DLL path: {config['dll']}") + + def _create_lsfg_launch_script(self) -> None: + """Create the ~/lsfg launch script for easier game setup""" + script_content = """#!/bin/bash +# lsfg-vk launch script generated by decky-lossless-scaling-vk plugin +# This script sets up the environment for lsfg-vk to work with the plugin configuration +export LSFG_PROCESS=decky-lsfg-vk +exec "$@" +""" + + # Write the script file + self._write_file(self.lsfg_launch_script_path, script_content, 0o755) + self.log.info(f"Created lsfg launch script at {self.lsfg_launch_script_path}") def check_installation(self) -> InstallationCheckResponse: """Check if lsfg-vk is already installed @@ -123,18 +147,18 @@ class InstallationService(BaseService): try: lib_exists = self.lib_file.exists() json_exists = self.json_file.exists() - script_exists = self.lsfg_script_path.exists() + config_exists = self.config_file_path.exists() - self.log.info(f"Installation check: lib={lib_exists}, json={json_exists}, script={script_exists}") + self.log.info(f"Installation check: lib={lib_exists}, json={json_exists}, config={config_exists}") return { "installed": lib_exists and json_exists, "lib_exists": lib_exists, "json_exists": json_exists, - "script_exists": script_exists, + "script_exists": config_exists, # Keep script_exists for backward compatibility "lib_path": str(self.lib_file), "json_path": str(self.json_file), - "script_path": str(self.lsfg_script_path), + "script_path": str(self.config_file_path), # Keep script_path for backward compatibility "error": None } @@ -148,7 +172,7 @@ class InstallationService(BaseService): "script_exists": False, "lib_path": str(self.lib_file), "json_path": str(self.json_file), - "script_path": str(self.lsfg_script_path), + "script_path": str(self.config_file_path), "error": str(e) } @@ -160,12 +184,24 @@ class InstallationService(BaseService): """ try: removed_files = [] - files_to_remove = [self.lib_file, self.json_file, self.lsfg_script_path] + files_to_remove = [self.lib_file, self.json_file, self.config_file_path, self.lsfg_launch_script_path] for file_path in files_to_remove: if self._remove_if_exists(file_path): removed_files.append(str(file_path)) + # Also try to remove the old script file if it exists (for backward compatibility) + if self._remove_if_exists(self.lsfg_script_path): + removed_files.append(str(self.lsfg_script_path)) + + # Remove config directory if it's empty + try: + if self.config_dir.exists() and not any(self.config_dir.iterdir()): + self.config_dir.rmdir() + removed_files.append(str(self.config_dir)) + except OSError: + pass # Directory not empty or other error, ignore + if not removed_files: return { "success": True, @@ -198,10 +234,12 @@ class InstallationService(BaseService): self.log.info("Checking for lsfg-vk files to clean up:") self.log.info(f" Library file: {self.lib_file}") self.log.info(f" JSON file: {self.json_file}") - self.log.info(f" lsfg script: {self.lsfg_script_path}") + self.log.info(f" Config file: {self.config_file_path}") + self.log.info(f" Launch script: {self.lsfg_launch_script_path}") + self.log.info(f" Old script file: {self.lsfg_script_path}") removed_files = [] - files_to_remove = [self.lib_file, self.json_file, self.lsfg_script_path] + files_to_remove = [self.lib_file, self.json_file, self.config_file_path, self.lsfg_launch_script_path, self.lsfg_script_path] for file_path in files_to_remove: try: @@ -210,6 +248,14 @@ class InstallationService(BaseService): except OSError as e: self.log.error(f"Failed to remove {file_path}: {e}") + # Try to remove config directory if empty + try: + if self.config_dir.exists() and not any(self.config_dir.iterdir()): + self.config_dir.rmdir() + removed_files.append(str(self.config_dir)) + except OSError: + pass # Directory not empty or other error, ignore + if removed_files: self.log.info(f"Cleaned up {len(removed_files)} lsfg-vk files during plugin uninstall: {removed_files}") else: |
