Skip to content

Commit ccea2fe

Browse files
committed
some more 1.2 stuff, im going to sleep
1 parent 6c2096a commit ccea2fe

File tree

3 files changed

+51
-102
lines changed

3 files changed

+51
-102
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
building_scripts/build_both.bat
21
building_scripts/pyinstaller
32
building_scripts/nuitka

building_scripts/build_both.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
start "Nuitka Build" build_with_nuitka.bat
3+
start "PyInstaller Build" build_with_pyinstaller.bat

sasm.pyw

Lines changed: 48 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -10,62 +10,73 @@ import time
1010
import vdf
1111
import sys
1212
import os
13-
import winreg
1413

1514
# Application version
1615
VERSION = "1.2"
1716

1817
# Enable verbose logging if -v or --verbose flag is present
1918
VERBOSE = "-v" in sys.argv or "--verbose" in sys.argv
2019

21-
# Define paths for application data and Steam configuration
20+
# Constants for file paths and keys
2221
APPDATA_PATH = os.path.join(os.getenv('APPDATA'), "KRWCLASSIC", "steamaccountswitchermanager")
23-
os.makedirs(APPDATA_PATH, exist_ok=True)
2422
DISABLED_ACCOUNTS_FILE = os.path.join(APPDATA_PATH, "disabled_accounts.json")
25-
SETTINGS_FILE = os.path.join(APPDATA_PATH, "settings.json") # New settings file
23+
SETTINGS_FILE = os.path.join(APPDATA_PATH, "settings.json")
2624
BACKUP_PATH = os.path.join(APPDATA_PATH, "backups")
27-
os.makedirs(BACKUP_PATH, exist_ok=True) # Create backups directory
25+
DEFAULT_VDF_PATH = os.path.join(os.getenv('ProgramFiles(x86)'), "Steam", "config", "loginusers.vdf")
2826

2927
# Initialize VDF_PATH
30-
DEFAULT_VDF_PATH = os.getenv('ProgramFiles(x86)') + "\\Steam\\config\\loginusers.vdf"
3128
VDF_PATH = DEFAULT_VDF_PATH if os.path.exists(DEFAULT_VDF_PATH) else None
3229

30+
# Ensure directories exist
31+
os.makedirs(APPDATA_PATH, exist_ok=True)
32+
os.makedirs(BACKUP_PATH, exist_ok=True)
33+
3334
# Debug print function that only prints when verbose mode is enabled
3435
def debug_print(*args, **kwargs):
3536
if VERBOSE:
3637
print("[DEBUG]", *args, **kwargs)
3738

38-
# Function to save settings to JSON file
39-
def save_settings(settings):
40-
with open(SETTINGS_FILE, 'w') as f:
41-
json.dump(settings, f, indent=4)
39+
# Function to load JSON data from a file
40+
def load_json_file(filepath, default=None):
41+
if not os.path.exists(filepath):
42+
debug_print(f"{filepath} not found, returning default settings.")
43+
return default
44+
try:
45+
with open(filepath, 'r') as f:
46+
return json.load(f)
47+
except Exception as e:
48+
debug_print(f"Error loading {filepath}: {str(e)}")
49+
return default
50+
51+
# Function to save JSON data to a file
52+
def save_json_file(filepath, data):
53+
with open(filepath, 'w') as f:
54+
json.dump(data, f, indent=4)
4255

43-
# Function to load settings from JSON file
56+
# Load settings with defaults
4457
def load_settings():
4558
default_settings = {
4659
"auto_backup": True,
47-
"vdf_path": None # Add a key for the VDF path
60+
"vdf_path": None
4861
}
49-
50-
# If the settings file doesn't exist, create it with default settings
51-
if not os.path.exists(SETTINGS_FILE):
52-
debug_print("Settings file not found, creating with default settings")
53-
save_settings(default_settings)
54-
return default_settings
55-
56-
try:
57-
with open(SETTINGS_FILE, 'r') as f:
58-
user_settings = json.load(f)
59-
# Merge with default settings
60-
return {**default_settings, **user_settings}
61-
except Exception as e:
62-
debug_print(f"Error loading settings: {str(e)}")
63-
return default_settings
62+
return load_json_file(SETTINGS_FILE, default_settings)
6463

65-
# Load settings to check for a saved path
66-
settings = load_settings()
67-
if settings.get("vdf_path"):
68-
VDF_PATH = settings["vdf_path"] # Load path from settings if available
64+
# Save settings
65+
def save_settings(settings):
66+
save_json_file(SETTINGS_FILE, settings)
67+
68+
# Load disabled accounts
69+
def load_disabled_accounts():
70+
data = load_json_file(DISABLED_ACCOUNTS_FILE, {})
71+
if isinstance(data, list):
72+
debug_print("Converting disabled accounts from list to dictionary format")
73+
return {steam_id: {"AccountName": f"Account_{steam_id[-4:]}", "PersonaName": f"User_{steam_id[-4:]}"}
74+
for steam_id in data}
75+
return data
76+
77+
# Save disabled accounts
78+
def save_disabled_accounts(accounts):
79+
save_json_file(DISABLED_ACCOUNTS_FILE, accounts)
6980

7081
# Function to create an icon from SVG string
7182
def svg_to_icon(svg_string, size=24, color=None):
@@ -148,63 +159,6 @@ class FloatingActionButton(QPushButton):
148159
# Set the cursor to a pointing hand
149160
self.setCursor(Qt.CursorShape.PointingHandCursor)
150161

151-
# Load disabled accounts from JSON file
152-
def load_disabled_accounts():
153-
if os.path.exists(DISABLED_ACCOUNTS_FILE):
154-
try:
155-
with open(DISABLED_ACCOUNTS_FILE, 'r') as f:
156-
data = json.load(f)
157-
# Convert list to dict if needed (for backward compatibility)
158-
if isinstance(data, list):
159-
debug_print("Converting disabled accounts from list to dictionary format")
160-
# Try to load the VDF file to get actual account data for disabled accounts
161-
try:
162-
vdf_data = parse_vdf(VDF_PATH)
163-
new_data = {}
164-
for steam_id in data:
165-
# If the account exists in the VDF file, use that data
166-
if steam_id in vdf_data:
167-
new_data[steam_id] = vdf_data[steam_id]
168-
else:
169-
# Otherwise use placeholder data
170-
new_data[steam_id] = {
171-
"AccountName": f"Account_{steam_id[-4:]}",
172-
"PersonaName": f"User_{steam_id[-4:]}",
173-
"RememberPassword": "1",
174-
"WantsOfflineMode": "0",
175-
"SkipOfflineModeWarning": "0",
176-
"AllowAutoLogin": "1",
177-
"MostRecent": "0",
178-
"Timestamp": "0"
179-
}
180-
return new_data
181-
except Exception as e:
182-
debug_print(f"Error loading VDF data for disabled accounts: {str(e)}")
183-
# Fallback to basic conversion
184-
new_data = {}
185-
for steam_id in data:
186-
new_data[steam_id] = {
187-
"AccountName": f"Account_{steam_id[-4:]}",
188-
"PersonaName": f"User_{steam_id[-4:]}",
189-
"RememberPassword": "1",
190-
"WantsOfflineMode": "0",
191-
"SkipOfflineModeWarning": "0",
192-
"AllowAutoLogin": "1",
193-
"MostRecent": "0",
194-
"Timestamp": "0"
195-
}
196-
return new_data
197-
return data
198-
except Exception as e:
199-
debug_print(f"Error loading disabled accounts: {str(e)}")
200-
return {}
201-
return {} # Return empty dict if no disabled accounts file exists
202-
203-
# Save disabled accounts to JSON file
204-
def save_disabled_accounts(accounts):
205-
with open(DISABLED_ACCOUNTS_FILE, 'w') as f:
206-
json.dump(accounts, f, indent=4)
207-
208162
# Parse Steam's VDF configuration file
209163
def parse_vdf(filepath):
210164
if not filepath or not os.path.exists(filepath):
@@ -307,19 +261,12 @@ class PathSelectionWindow(QWidget):
307261
class SteamAccountManager(QMainWindow):
308262
def __init__(self):
309263
super().__init__()
310-
self.settings = load_settings() # Load settings
311-
self.auto_backup = self.settings.get("auto_backup", True) # Get auto_backup setting
312-
self.radio_button_group = QButtonGroup(self) # Create a button group for radio buttons
313-
self.radio_button_group.setExclusive(True) # Ensure only one can be selected
314-
315-
# Initialize the UI
316-
self.initUI() # Ensure UI is initialized first
317-
318-
# Check if VDF file exists
319-
if not VDF_PATH or not os.path.exists(VDF_PATH):
320-
self.show_path_selection()
321-
else:
322-
self.load_data()
264+
self.settings = load_settings()
265+
self.auto_backup = self.settings.get("auto_backup", True)
266+
self.radio_button_group = QButtonGroup(self)
267+
self.radio_button_group.setExclusive(True)
268+
self.initUI()
269+
self.load_data()
323270

324271
# Initialize the user interface
325272
def initUI(self):

0 commit comments

Comments
 (0)