Skip to content

Commit fe69cc6

Browse files
authored
Update and rename utils.py to config_manager.py
1 parent 844827f commit fe69cc6

File tree

2 files changed

+74
-160
lines changed

2 files changed

+74
-160
lines changed

config_manager.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import os
2+
import json
3+
import logging
4+
5+
class ConfigManager:
6+
base_dir = os.path.join(os.path.expanduser('~'), '.hackeros', 'Hacker-Launcher')
7+
protons_dir = os.path.join(base_dir, 'Protons')
8+
prefixes_dir = os.path.join(base_dir, 'Prefixes')
9+
config_dir = os.path.join(base_dir, 'Config')
10+
logs_dir = os.path.join(base_dir, 'Logs')
11+
games_file = os.path.join(config_dir, 'games.json')
12+
settings_file = os.path.join(config_dir, 'settings.json')
13+
14+
def __init__(self):
15+
os.makedirs(self.config_dir, exist_ok=True)
16+
os.makedirs(self.prefixes_dir, exist_ok=True)
17+
os.makedirs(self.protons_dir, exist_ok=True)
18+
os.makedirs(self.logs_dir, exist_ok=True)
19+
self.setup_logging()
20+
self.settings = self.load_settings()
21+
22+
def setup_logging(self):
23+
logging.basicConfig(
24+
filename=os.path.join(self.logs_dir, 'launcher.log'),
25+
level=logging.DEBUG,
26+
format='%(asctime)s [%(levelname)s] %(message)s'
27+
)
28+
29+
def load_games(self):
30+
if os.path.exists(self.games_file):
31+
try:
32+
with open(self.games_file, 'r') as f:
33+
games = json.load(f)
34+
# Simple validation
35+
for game in games:
36+
if not all(key in game for key in ['name', 'exe', 'runner', 'prefix']):
37+
raise ValueError("Invalid game data")
38+
return games
39+
except (json.JSONDecodeError, IOError, ValueError) as e:
40+
logging.error(f"Error loading games.json: {e}")
41+
print(f"Error loading games.json: {e}")
42+
return []
43+
return []
44+
45+
def save_games(self, games):
46+
with open(self.games_file, 'w') as f:
47+
json.dump(games, f, indent=4)
48+
49+
def load_settings(self):
50+
default_settings = {
51+
'fullscreen': True,
52+
'default_runner': 'Proton',
53+
'auto_update': 'Enabled',
54+
'enable_esync': True,
55+
'enable_fsync': True,
56+
'enable_dxvk_async': False
57+
}
58+
if os.path.exists(self.settings_file):
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")
65+
default_settings.update(settings)
66+
except (json.JSONDecodeError, IOError, ValueError) as e:
67+
logging.error(f"Error loading settings.json: {e}")
68+
print(f"Error loading settings.json: {e}")
69+
return default_settings
70+
71+
def save_settings(self, settings):
72+
with open(self.settings_file, 'w') as f:
73+
json.dump(settings, f, indent=4)
74+

utils.py

Lines changed: 0 additions & 160 deletions
This file was deleted.

0 commit comments

Comments
 (0)