From 2b8e7076b422dc03443da782d40cf311d42607bb Mon Sep 17 00:00:00 2001 From: anne Date: Tue, 12 Sep 2023 23:01:34 +0200 Subject: [PATCH] added simple cache to getDataDir --- ostools.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ostools.py b/ostools.py index 83e198f..7fdf245 100644 --- a/ostools.py +++ b/ostools.py @@ -8,6 +8,7 @@ except ImportError: print("PyQt5 fallback (ostools.py)") from PyQt5.QtCore import QStandardPaths +DATADIR = None def isOSX(): return sys.platform == "darwin" @@ -75,6 +76,18 @@ def getDataDir(): # Temporary fix for non-ascii usernames # If username has non-ascii characters, just store userdata # in the Pesterchum install directory (like before) + + if DATADIR is not None: + # ~Lisanne + # On some systems (windows known 2b affected, OSX unknown, at least 1 linux distro unaffected) + # the QStandardPaths.writableLocation changes its return path after the QApplication initialises + # This means that anytime its called during runtime after init will just return a lie. it will just give you a different path + # (Because the Application now has a Name which in turn makes it return an application-name-specific writableLocation, which pchum isnt expecting anywhere) + # so + # here im caching the result at init & returning that + # seemed like the safest way to do this without breaking half of this program + return DATADIR + try: if isOSX(): return os.path.join( @@ -100,3 +113,5 @@ def getDataDir(): except UnicodeDecodeError as e: print(e) return "" + +DATADIR = getDataDir() \ No newline at end of file