2022-03-19 19:48:19 -04:00
|
|
|
import os
|
|
|
|
import sys
|
2011-08-23 05:28:58 -04:00
|
|
|
import platform
|
2022-09-06 07:26:14 -04:00
|
|
|
|
2022-08-19 07:12:58 -04:00
|
|
|
try:
|
|
|
|
from PyQt6.QtCore import QStandardPaths
|
|
|
|
except ImportError:
|
|
|
|
print("PyQt5 fallback (ostools.py)")
|
|
|
|
from PyQt5.QtCore import QStandardPaths
|
2011-08-11 04:17:53 -04:00
|
|
|
|
|
|
|
def isOSX():
|
2011-08-23 05:28:58 -04:00
|
|
|
return sys.platform == "darwin"
|
2011-08-11 04:17:53 -04:00
|
|
|
|
|
|
|
def isWin32():
|
2011-08-23 05:28:58 -04:00
|
|
|
return sys.platform == "win32"
|
|
|
|
|
|
|
|
def isLinux():
|
|
|
|
return sys.platform.startswith("linux")
|
2011-08-11 04:17:53 -04:00
|
|
|
|
|
|
|
def isOSXBundle():
|
2011-08-23 05:28:58 -04:00
|
|
|
return isOSX() and (os.path.abspath('.').find(".app") != -1)
|
|
|
|
|
2011-09-22 06:23:33 -04:00
|
|
|
def isOSXLeopard():
|
|
|
|
return isOSX() and platform.mac_ver()[0].startswith("10.5")
|
|
|
|
|
2011-08-23 05:28:58 -04:00
|
|
|
def osVer():
|
|
|
|
if isWin32():
|
|
|
|
return " ".join(platform.win32_ver())
|
|
|
|
elif isOSX():
|
2011-09-22 06:23:33 -04:00
|
|
|
ver = platform.mac_ver();
|
|
|
|
return " ".join((ver[0], " (", ver[2], ")"))
|
2011-08-23 05:28:58 -04:00
|
|
|
elif isLinux():
|
|
|
|
return " ".join(platform.linux_distribution())
|
2011-08-11 04:17:53 -04:00
|
|
|
|
2022-09-06 07:26:14 -04:00
|
|
|
def validateDataDir():
|
|
|
|
"""Checks if data directory is present"""
|
|
|
|
# Define paths
|
|
|
|
datadir = getDataDir()
|
|
|
|
profile = os.path.join(datadir, "profiles")
|
|
|
|
quirks = os.path.join(datadir, "quirks")
|
|
|
|
logs = os.path.join(datadir, "logs")
|
|
|
|
errorlogs = os.path.join(datadir, "errorlogs")
|
|
|
|
backup = os.path.join(datadir, "backup")
|
|
|
|
js_pchum = os.path.join(datadir, "pesterchum.js")
|
|
|
|
|
|
|
|
dirs = [datadir, profile, quirks, logs, errorlogs, backup]
|
|
|
|
for d in dirs:
|
|
|
|
if (os.path.isdir(d) == False) or (os.path.exists(d) == False):
|
|
|
|
os.makedirs(d, exist_ok=True)
|
|
|
|
|
|
|
|
# pesterchum.js
|
|
|
|
if not os.path.exists(js_pchum):
|
|
|
|
with open(js_pchum, 'w') as f:
|
|
|
|
f.write("{}")
|
|
|
|
|
2011-08-11 04:17:53 -04:00
|
|
|
def getDataDir():
|
2012-02-16 01:29:57 -05:00
|
|
|
# Temporary fix for non-ascii usernames
|
|
|
|
# If username has non-ascii characters, just store userdata
|
|
|
|
# in the Pesterchum install directory (like before)
|
|
|
|
try:
|
|
|
|
if isOSX():
|
2022-06-28 20:40:30 -04:00
|
|
|
return os.path.join(QStandardPaths.writableLocation(QStandardPaths.StandardLocation.AppLocalDataLocation), "Pesterchum/")
|
2012-02-16 01:29:57 -05:00
|
|
|
elif isLinux():
|
2022-06-26 22:18:37 -04:00
|
|
|
return os.path.join(QStandardPaths.writableLocation(QStandardPaths.StandardLocation.HomeLocation), ".pesterchum/")
|
2012-02-16 01:29:57 -05:00
|
|
|
else:
|
2022-06-28 20:40:30 -04:00
|
|
|
return os.path.join(QStandardPaths.writableLocation(QStandardPaths.StandardLocation.AppLocalDataLocation), "pesterchum/")
|
2022-09-06 07:26:14 -04:00
|
|
|
except UnicodeDecodeError as e:
|
|
|
|
print(e)
|
2012-02-16 01:29:57 -05:00
|
|
|
return ''
|