From 23980276eeb6b0f8f44a087972f066470de18890 Mon Sep 17 00:00:00 2001 From: tretrauit Date: Sun, 26 Jun 2022 01:53:37 +0700 Subject: [PATCH] fix: patcher.py properly disable crash reporters. fix: revert_patch now works correctly. It was because of me forgetting to merge the game data name with the game directory I hope my crash log wasn't uploaded to mHY since I blocked their hosts... --- setup.py | 4 ++-- worthless/patcher.py | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index 1483bb0..c672fa9 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ README = (HERE / "README.md").read_text() setup( name='worthless', - version='2.0.1', + version='2.1.0', packages=['worthless', 'worthless.classes', 'worthless.classes.launcher', 'worthless.classes.installer'], url='https://git.froggi.es/tretrauit/worthless-launcher', license='MIT License', @@ -23,5 +23,5 @@ setup( "Programming Language :: Python :: 3" ], include_package_data=True, - install_requires=["aiohttp", "appdirs", "aiopath", "aiofiles"] + install_requires=["aiohttp", "appdirs", "aiopath"] ) diff --git a/worthless/patcher.py b/worthless/patcher.py index 7766036..dbe3267 100644 --- a/worthless/patcher.py +++ b/worthless/patcher.py @@ -237,20 +237,22 @@ class Patcher: self._installer.get_game_data_name() + "Plugins/crashreport.exe", ] for file in disable_files: - file_path = Path(file).resolve() + file_path = Path(self._gamedir.joinpath(file)).resolve() if file_path.exists(): - file_path.rename(str(file_path) + ".bak") + await AsyncPath(file_path).rename(str(file_path) + ".bak") patch_jobs.append(disable_crashreporters()) await asyncio.gather(*patch_jobs) @staticmethod - async def _creation_date(file_path: AsyncPath): + async def _creation_date(file_path: str | Path | AsyncPath): """ Try to get the date that a file was created, falling back to when it was last modified if that isn't possible. See http://stackoverflow.com/a/39501288/1709587 for explanation. """ + if isinstance(file_path, str | Path): + file_path = AsyncPath(file_path) if platform.system() == 'Windows': return os.path.getctime(file_path) else: @@ -263,9 +265,9 @@ class Patcher: return stat.st_mtime async def _revert_file(self, original_file: str, base_file: AsyncPath, ignore_error=False): - original_path = await self._gamedir.joinpath(original_file + ".bak").resolve() - target_file = await self._gamedir.joinpath(original_file).resolve() - if await original_path.exists(): + original_path = Path(self._gamedir.joinpath(original_file + ".bak")).resolve() + target_file = Path(self._gamedir.joinpath(original_file)).resolve() + if original_path.exists(): if abs(await self._creation_date(base_file) - await self._creation_date(original_path)) > 86400: # 24 hours if not ignore_error: raise RuntimeError("{} is not for this game version.".format(original_path.name)) @@ -293,15 +295,15 @@ class Patcher: for file in ["launcher.bat", "mhyprot2_running.reg"]: revert_job.append(self._gamedir.joinpath(file).unlink(missing_ok=True)) - async def get_files(extensions): + def get_files(extensions): all_files = [] for ext in extensions: - all_files.extend(await self._gamedir.glob(ext)) + all_files.extend(Path(self._gamedir).glob(ext)) return all_files - files = await get_files(('*.dxvk-cache', '*_d3d9.log', '*_d3d11.log', '*_dxgi.log')) + files = get_files(('*.dxvk-cache', '*_d3d9.log', '*_d3d11.log', '*_dxgi.log')) for file in files: - revert_job.append(file.unlink(missing_ok=True)) + revert_job.append(AsyncPath(file).unlink(missing_ok=True)) await asyncio.gather(*revert_job)