Skip to content

Commit c2e775c

Browse files
committed
Add linux/windows detection
1 parent 0327c09 commit c2e775c

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

backend.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@
44

55
rootDir = os.path.dirname(os.path.abspath(__file__))
66
initDir = os.path.dirname(os.path.abspath(sys.argv[0]))
7-
appdataDir = os.path.join(os.getenv('APPDATA'), "Furglitch", "MO2SE")
8-
logDir = os.path.join(appdataDir, 'logs', f'{dt.now().strftime('%Y-%m-%d %H%M%S')}.log')
7+
if os.name == 'nt':
8+
configDir = os.path.join(os.getenv('APPDATA'), "Furglitch", "MO2SG")
9+
log.info("Windows OS detected")
10+
log.info(f"Config Directory: {configDir}")
11+
elif os.name == 'posix':
12+
configDir = os.path.join(os.path.expanduser('~'), ".config", "Furglitch", "MO2SG")
13+
log.info("Linux OS detected")
14+
log.info(f"Config Directory: {configDir}")
15+
else:
16+
msg.showwarning("Warning","Unsupported OS")
17+
log.warning("Unsupported OS")
18+
sys.exit(1)
19+
logDir = os.path.join(configDir, 'logs', f'{dt.now().strftime('%Y-%m-%d %H%M%S')}.log')
920
resourceDir = os.path.join(rootDir, "resources")
1021
iconDir = os.path.join(resourceDir, "icon.ico")
1122

@@ -22,15 +33,15 @@
2233
subCasing = 'Unchanged'
2334

2435
# Logging
25-
if not os.path.exists(os.path.join(appdataDir, 'logs')): os.makedirs(os.path.join(appdataDir, 'logs'))
36+
if not os.path.exists(os.path.join(configDir, 'logs')): os.makedirs(os.path.join(configDir, 'logs'))
2637
open(logDir, "w").close()
2738
log.basicConfig(
2839
filename=logDir,
2940
level=log.DEBUG,
3041
format='%(asctime)s - %(levelname)s - %(message)s',
3142
datefmt='%Y-%m-%d %H:%M:%S'
3243
)
33-
log.info("MO2SE Started")
44+
log.info("MO2SG Started")
3445

3546
# Menu Functions
3647
def fileNew():
@@ -216,14 +227,14 @@ def casingSet(type, case):
216227

217228
def settingsGet():
218229
global theme, themeAccent, header, catCasing, subCasing
219-
if not os.path.exists(os.path.join(appdataDir, 'MO2SE.json')):
230+
if not os.path.exists(os.path.join(configDir, 'MO2SG.json')):
220231
data = {"theme": {"name": theme, "accent": themeAccent}, "header": header, "casing": {"cat": catCasing, "sub": subCasing}}
221-
f = open(os.path.join(appdataDir, 'MO2SE.json'), "w")
232+
f = open(os.path.join(configDir, 'MO2SG.json'), "w")
222233
json.dump(data, f, indent=4)
223234
f.close()
224235
log.info("Default Settings File Created")
225236
else:
226-
with open(os.path.join(appdataDir, 'MO2SE.json'), "r") as f:
237+
with open(os.path.join(configDir, 'MO2SG.json'), "r") as f:
227238
data = json.load(f)
228239
if data["theme"]["name"] in themeGet("name"): theme = data["theme"]["name"]
229240
else: theme = "Nord"
@@ -239,7 +250,7 @@ def settingsGet():
239250

240251
def settingsCheck():
241252
global theme, themeAccent, header, catCasing, subCasing
242-
with open(os.path.join(appdataDir, 'MO2SE.json'), "r") as f:
253+
with open(os.path.join(configDir, 'MO2SG.json'), "r") as f:
243254
data = json.load(f)
244255
if theme == data["theme"]["name"] and themeAccent == data["theme"]["accent"] and header == data["header"] and catCasing == data["casing"]["cat"] and subCasing == data["casing"]["sub"]:
245256
log.info("Settings match saved settings")
@@ -250,7 +261,7 @@ def settingsCheck():
250261

251262
def settingsSave():
252263
global theme, header, themeAccent, casing
253-
with open(os.path.join(appdataDir + '/MO2SE.json'), "w") as f:
264+
with open(os.path.join(configDir + '/MO2SG.json'), "w") as f:
254265
data = {"theme": {"name": theme, "accent": themeAccent}, "header": header, "casing": {"cat": catCasing, "sub": subCasing}}
255266
json.dump(data, f, sort_keys=True, indent=4)
256267
log.info(f"Settings Saved: Theme {theme}, Theme Accent {themeAccent}, Header {header}, Category Casing {catCasing}, Subcategory Casing {subCasing}")

0 commit comments

Comments
 (0)