ExecuteInfo.txt parsing
import os
from pathlib import Path
import platform
-
+import re
import logging
logger = logging.getLogger(__name__)
@@ -11,6 +11,12 @@ BASEDIR = {
"Linux": "~/StarCraftII"
}
+USERPATH = {
+ "Windows": "\Documents\StarCraft II\ExecuteInfo.txt",
+ "Darwin": "/Library/Application Support/Blizzard/StarCraft II/ExecuteInfo.txt",
+ "Linux": None
+}
+
BINPATH = {
"Windows": "SC2_x64.exe",
"Darwin": "SC2.app/Contents/MacOS/SC2",
@@ -46,7 +52,19 @@ class _MetaPaths(type):
exit(1)
try:
- self.BASE = Path(os.environ.get("SC2PATH", BASEDIR[PF])).expanduser()
+ base = os.environ.get("SC2PATH")
+ if base is None and USERPATH[PF] is not None:
+ einfo = str(Path.home().expanduser()) + USERPATH[PF]
+ if os.path.isfile(einfo):
+ with open(einfo) as f:
+ content = f.read()
+ if content:
+ base = re.search(r" = (.*)Versions", content).group(1)
+ if not os.path.exists(base):
+ base = None
+ if base is None:
+ base = BASEDIR[PF]
+ self.BASE = Path(base).expanduser()
self.EXECUTABLE = latest_executeble(self.BASE / "Versions")
self.CWD = self.BASE / CWD[PF] if CWD[PF] else None
