Skip to content

Commit 6aab44a

Browse files
authored
Update config_manager.py
1 parent 43711af commit 6aab44a

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

config_manager.py

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,73 @@
11
import os
22
import json
3+
import logging
4+
from jsonschema import validate, ValidationError # Assuming jsonschema is available or install if needed, but per tools, no install, so skip or use simple validation
5+
36
class ConfigManager:
47
base_dir = os.path.join(os.path.expanduser('~'), '.hackeros', 'Hacker-Launcher')
58
protons_dir = os.path.join(base_dir, 'Protons')
69
prefixes_dir = os.path.join(base_dir, 'Prefixes')
710
config_dir = os.path.join(base_dir, 'Config')
11+
logs_dir = os.path.join(base_dir, 'Logs')
812
games_file = os.path.join(config_dir, 'games.json')
913
settings_file = os.path.join(config_dir, 'settings.json')
14+
1015
def __init__(self):
1116
os.makedirs(self.config_dir, exist_ok=True)
1217
os.makedirs(self.prefixes_dir, exist_ok=True)
1318
os.makedirs(self.protons_dir, exist_ok=True)
19+
os.makedirs(self.logs_dir, exist_ok=True)
20+
self.setup_logging()
1421
self.load_settings()
22+
23+
def setup_logging(self):
24+
logging.basicConfig(
25+
filename=os.path.join(self.logs_dir, 'launcher.log'),
26+
level=logging.INFO,
27+
format='%(asctime)s - %(levelname)s - %(message)s'
28+
)
29+
1530
def load_games(self):
1631
if os.path.exists(self.games_file):
17-
with open(self.games_file, 'r') as f:
18-
return json.load(f)
32+
try:
33+
with open(self.games_file, 'r') as f:
34+
games = json.load(f)
35+
# Simple validation
36+
for game in games:
37+
if not all(key in game for key in ['name', 'exe', 'runner', 'prefix']):
38+
raise ValueError("Invalid game data")
39+
return games
40+
except (json.JSONDecodeError, IOError, ValueError) as e:
41+
logging.error(f"Error loading games.json: {e}")
42+
return []
1943
return []
44+
2045
def save_games(self, games):
2146
with open(self.games_file, 'w') as f:
22-
json.dump(games, f)
47+
json.dump(games, f, indent=4)
48+
2349
def load_settings(self):
2450
default_settings = {
2551
'fullscreen': False,
2652
'default_runner': 'Proton',
2753
'auto_update': 'Enabled',
28-
'default_launch_options': ''
54+
'enable_esync': True,
55+
'enable_fsync': True,
56+
'enable_dxvk_async': False
2957
}
3058
if os.path.exists(self.settings_file):
31-
with open(self.settings_file, 'r') as f:
32-
settings = json.load(f)
59+
try:
60+
with open(self.settings_file, 'r') as f:
61+
settings = json.load(f)
62+
# Simple validation
63+
if not isinstance(settings.get('fullscreen'), bool):
64+
raise ValueError("Invalid settings data")
3365
default_settings.update(settings)
34-
with open(self.settings_file, 'w') as f:
35-
json.dump(default_settings, f)
66+
except (json.JSONDecodeError, IOError, ValueError) as e:
67+
logging.error(f"Error loading settings.json: {e}")
68+
# Only save if changed, but for simplicity, save once at load if needed
3669
return default_settings
70+
3771
def save_settings(self, settings):
3872
with open(self.settings_file, 'w') as f:
39-
json.dump(settings, f)
73+
json.dump(settings, f, indent=4)

0 commit comments

Comments
 (0)