added simple cache to getDataDir

This commit is contained in:
anne 2023-09-12 23:01:34 +02:00
parent 22cda74bb9
commit 2b8e7076b4

View file

@ -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()