Make Enemizer version check work on all platforms

This commit is contained in:
Fabian Dill 2020-09-03 03:54:12 +02:00
parent 9d9a13dd1d
commit ecf5c505d3
1 changed files with 22 additions and 23 deletions

45
Rom.py
View File

@ -168,30 +168,29 @@ def check_enemizer(enemizercli):
if not os.path.exists(enemizercli) and not os.path.exists(enemizercli + ".exe"):
raise Exception(f"Enemizer not found at {enemizercli}, please install it."
f"Such as https://github.com/Ijwu/Enemizer/releases")
if sys.platform == "win32":
# the win32api calls appear to not be threadsafe, which is the reason for the lock
with check_lock:
# some time may have passed since the lock was acquired, as such a quick re-check doesn't hurt
if getattr(check_enemizer, "done", None):
return
try:
import pythoncom
from win32com.client import Dispatch
pythoncom.CoInitialize()
except ImportError:
logging.info("Could not check Enemizer Version info as pywin32 bindings are missing.")
else:
# version info is saved on the lib, for some reason
library = os.path.join(os.path.dirname(enemizercli), "EnemizerLibrary.dll")
ver_parser = Dispatch('Scripting.FileSystemObject')
info = ver_parser.GetFileVersion(library)
if info != 'No Version Information Available':
version = tuple(int(part) for part in info.split("."))
if version < (6, 1, 0, 222):
raise Exception(
f"Enemizer found at {enemizercli} is outdated ({info}), please update your Enemizer. "
f"Such as https://github.com/Ijwu/Enemizer/releases")
with check_lock:
# some time may have passed since the lock was acquired, as such a quick re-check doesn't hurt
if getattr(check_enemizer, "done", None):
return
# version info is saved on the lib, for some reason
library_info = os.path.join(os.path.dirname(enemizercli), "EnemizerCLI.Core.deps.json")
with open(library_info) as f:
info = json.load(f)
for lib in info["libraries"]:
if lib.startswith("EnemizerLibrary/"):
version = lib.split("/")[-1]
version = tuple(int(element) for element in version.split("."))
logging.info(version)
if version < (6, 2, 0):
raise Exception(
f"Enemizer found at {enemizercli} is outdated ({info}), please update your Enemizer. "
f"Such as https://github.com/Ijwu/Enemizer/releases")
break
else:
raise Exception(f"Could not find Enemizer library version information in {library_info}")
check_enemizer.done = True