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...
This commit is contained in:
tretrauit 2022-06-26 01:53:37 +07:00
parent d4773bc38d
commit 23980276ee
Signed by: tretrauit
GPG Key ID: CDDE1C97EE305DAF
2 changed files with 14 additions and 12 deletions

View File

@ -9,7 +9,7 @@ README = (HERE / "README.md").read_text()
setup( setup(
name='worthless', name='worthless',
version='2.0.1', version='2.1.0',
packages=['worthless', 'worthless.classes', 'worthless.classes.launcher', 'worthless.classes.installer'], packages=['worthless', 'worthless.classes', 'worthless.classes.launcher', 'worthless.classes.installer'],
url='https://git.froggi.es/tretrauit/worthless-launcher', url='https://git.froggi.es/tretrauit/worthless-launcher',
license='MIT License', license='MIT License',
@ -23,5 +23,5 @@ setup(
"Programming Language :: Python :: 3" "Programming Language :: Python :: 3"
], ],
include_package_data=True, include_package_data=True,
install_requires=["aiohttp", "appdirs", "aiopath", "aiofiles"] install_requires=["aiohttp", "appdirs", "aiopath"]
) )

View File

@ -237,20 +237,22 @@ class Patcher:
self._installer.get_game_data_name() + "Plugins/crashreport.exe", self._installer.get_game_data_name() + "Plugins/crashreport.exe",
] ]
for file in disable_files: for file in disable_files:
file_path = Path(file).resolve() file_path = Path(self._gamedir.joinpath(file)).resolve()
if file_path.exists(): 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()) patch_jobs.append(disable_crashreporters())
await asyncio.gather(*patch_jobs) await asyncio.gather(*patch_jobs)
@staticmethod @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 Try to get the date that a file was created, falling back to when it was
last modified if that isn't possible. last modified if that isn't possible.
See http://stackoverflow.com/a/39501288/1709587 for explanation. See http://stackoverflow.com/a/39501288/1709587 for explanation.
""" """
if isinstance(file_path, str | Path):
file_path = AsyncPath(file_path)
if platform.system() == 'Windows': if platform.system() == 'Windows':
return os.path.getctime(file_path) return os.path.getctime(file_path)
else: else:
@ -263,9 +265,9 @@ class Patcher:
return stat.st_mtime return stat.st_mtime
async def _revert_file(self, original_file: str, base_file: AsyncPath, ignore_error=False): async def _revert_file(self, original_file: str, base_file: AsyncPath, ignore_error=False):
original_path = await self._gamedir.joinpath(original_file + ".bak").resolve() original_path = Path(self._gamedir.joinpath(original_file + ".bak")).resolve()
target_file = await self._gamedir.joinpath(original_file).resolve() target_file = Path(self._gamedir.joinpath(original_file)).resolve()
if await original_path.exists(): if original_path.exists():
if abs(await self._creation_date(base_file) - await self._creation_date(original_path)) > 86400: # 24 hours if abs(await self._creation_date(base_file) - await self._creation_date(original_path)) > 86400: # 24 hours
if not ignore_error: if not ignore_error:
raise RuntimeError("{} is not for this game version.".format(original_path.name)) 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"]: for file in ["launcher.bat", "mhyprot2_running.reg"]:
revert_job.append(self._gamedir.joinpath(file).unlink(missing_ok=True)) revert_job.append(self._gamedir.joinpath(file).unlink(missing_ok=True))
async def get_files(extensions): def get_files(extensions):
all_files = [] all_files = []
for ext in extensions: for ext in extensions:
all_files.extend(await self._gamedir.glob(ext)) all_files.extend(Path(self._gamedir).glob(ext))
return all_files 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: 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) await asyncio.gather(*revert_job)