Repository navigation
Expand file tree
/
Copy pathlauncher.py
More file actions
104 lines (81 loc) · 3.97 KB
/
Copy pathlauncher.py
File metadata and controls
104 lines (81 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""Game launcher module for quick launch functionality."""
import logging
from pathlib import Path
from core import Config, StellaSoraModLoader, StellaSoraGame
from utils import get_exe_path
logger = logging.getLogger(__name__)
class GameLauncher:
"""Handles game launching with mod verification."""
def __init__(self, config: Config):
self.config = config
def quick_launch(self) -> tuple[bool, str | None]:
"""
Launch game immediately without UI.
Verifies mods are applied correctly before launching.
Returns:
(success, error_message) - If success is False, error_message explains why
"""
logger.info("Quick launch: starting")
# Validate game path
game_exe = self.config.GameExePath.get()
if not game_exe:
logger.warning("Quick launch: Game path not configured")
return False, "Game path not configured"
game_path = Path(game_exe)
if not game_path.exists():
logger.warning(f"Quick launch: Game not found at {game_path}")
return False, f"Game not found: {game_path}"
# Setup directories
mods_dir_str = self.config.ModsDir.get()
backups_dir_str = self.config.BackupsDir.get()
mods_dir = Path(mods_dir_str) if mods_dir_str else get_exe_path("Mods")
backups_dir = Path(backups_dir_str) if backups_dir_str else get_exe_path("Backups")
mod_ext = self.config.ModExtension.get() or ".unity3d"
# Create loader
loader = StellaSoraModLoader(
game_path.parent,
mods_dir,
backups_dir,
mod_ext
)
# Sync and check for problems
try:
logger.debug("Quick launch: syncing mods")
orphaned = loader.sync_mods()
if orphaned:
logger.warning(f"Quick launch: Found {len(orphaned)} orphaned mod(s)")
return False, f"Found {len(orphaned)} orphaned mod(s) that need attention"
# Check for conflicts in enabled mods
mods = loader.get_mods_list()
enabled_mods = [m for m in mods if not loader.is_disabled(m)]
for mod in enabled_mods:
conflicts = loader.check_duplicate_conflict(mod)
if conflicts:
conflict_names = [c["path"] for c in conflicts]
logger.warning(f"Quick launch: Mod conflict detected - {mod.name}")
return False, f"Mod conflict detected: {mod.name} conflicts with {conflict_names}"
# Verify enabled mods are applied
logger.debug("Quick launch: verifying enabled mods")
loader.verify_enabled_mods()
except Exception as e:
logger.error(f"Quick launch: Error during mod verification - {e}", exc_info=True)
return False, f"Error during mod verification: {e}"
# Launch game
try:
logger.info("Quick launch: launching game")
game = StellaSoraGame(game_path)
game.start()
# If non-permanent mode, wait for game to close and restore
non_permanent = self.config.NonPermanentMode.get() or False
if non_permanent:
logger.info("Quick launch: waiting for game to close (non-permanent mode)")
closed = game.wait_for_game_closed()
if closed:
logger.info("Quick launch: game closed, restoring original files")
loader.restore_all()
logger.info("Quick launch: original files restored")
except Exception as e:
logger.error(f"Quick launch: Failed to launch game - {e}", exc_info=True)
return False, f"Failed to launch game: {e}"
logger.info("Quick launch: success")
return True, None