diff --git a/requirements.txt b/requirements.txt index 2f5e4ee..55feafa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ aiohttp==3.8.1 appdirs~=1.4.4 aiopath~=0.6.10 -setuptools==60.9.3 xdelta3~=0.0.5 \ No newline at end of file diff --git a/worthless/patcher.py b/worthless/patcher.py index dcd121d..c5fe025 100644 --- a/worthless/patcher.py +++ b/worthless/patcher.py @@ -1,3 +1,6 @@ +import os +import platform + import xdelta3 import tarfile import appdirs @@ -164,11 +167,29 @@ class Patcher: if crash_fix: self.apply_xlua_patch(fallback=fallback) + @staticmethod + def _creation_date(file_path: Path): + """ + 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 platform.system() == 'Windows': + return os.path.getctime(file_path) + else: + stat = file_path.stat() + try: + return stat.st_birthtime + except AttributeError: + # We're probably on Linux. No easy way to get creation dates here, + # so we'll settle for when its content was last modified. + return stat.st_mtime + def _revert_file(self, original_file: str, base_file: Path, ignore_error=False): original_path = self._gamedir.joinpath(original_file + ".bak").resolve() target_file = self._gamedir.joinpath(original_file).resolve() if original_path.exists(): - if abs(base_file.stat().st_mtime_ns - original_path.stat().st_mtime_ns) > 3600: + if abs(self._creation_date(base_file) - self._creation_date(original_path)) > 3600: if not ignore_error: raise RuntimeError("{} is not for this game version.".format(original_path.name)) original_path.unlink(missing_ok=True)