From 481eb48fec5cb02b9dbb9112d197aaeabc26e562 Mon Sep 17 00:00:00 2001 From: Zash Date: Sun, 19 Jan 2025 00:45:14 +0100 Subject: [PATCH] Fix Cyberpunk r6/cache file updates. --- games/game_cyberpunk2077.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/games/game_cyberpunk2077.py b/games/game_cyberpunk2077.py index ac50a6c6..1765ca92 100644 --- a/games/game_cyberpunk2077.py +++ b/games/game_cyberpunk2077.py @@ -575,25 +575,27 @@ def _map_cache_files(self): """ data_path = Path(self.dataDirectory().absolutePath()) overwrite_path = Path(self._organizer.overwritePath()) - cache_files = [ - file.relative_to(data_path) for file in data_path.glob("r6/cache/*") - ] + data_cache_path = data_path / "r6/cache" + overwrite_cache_path = overwrite_path / "r6/cache" + cache_files = ( + file.relative_to(data_path) for file in data_cache_path.glob("*") + ) if self._get_setting("clear_cache_after_game_update") and any( self._is_cache_file_updated(file, data_path) for file in cache_files ): qInfo('Updated game files detected, clearing "overwrite/r6/cache/*"') try: - shutil.rmtree(overwrite_path / "r6/cache") + shutil.rmtree(overwrite_cache_path) except FileNotFoundError: pass - new_cache_files = cache_files + qInfo('Updating "r6/cache" in overwrite') + shutil.copytree(data_cache_path, overwrite_cache_path, dirs_exist_ok=True) else: - new_cache_files = list(self._unmapped_cache_files(data_path)) - for file in new_cache_files: - qInfo(f'Copying "{file}" to overwrite (to catch file overwrites)') - dst = overwrite_path / file - dst.parent.mkdir(parents=True, exist_ok=True) - shutil.copy2(data_path / file, dst) + for file in self._unmapped_cache_files(data_path): + qInfo(f'Copying "{file}" to overwrite (to catch file overwrites)') + dst = overwrite_path / file + dst.parent.mkdir(parents=True, exist_ok=True) + shutil.copy2(data_path / file, dst) def _is_cache_file_updated(self, file: Path, data_path: Path) -> bool: """Checks if a cache file is updated (in game dir).