12
from ctypes import wintypes
14
config = configparser.ConfigParser()
15
ini_path = os.path.join(os.path.dirname(__file__), 'launcher_real.ini')
18
except Exception as e:
19
logging.error(f"Error reading configuration: {e}")
22
CONFIG_DIR = config.get('Paths', 'config_dir')
23
LOG_FILE = config.get('Paths', 'log_file')
25
raw_excl = config.get('Settings', 'exclude_keywords').strip()
26
if raw_excl.startswith('[') and raw_excl.endswith(']'):
27
raw_excl = raw_excl[1:-1]
28
EXCLUDE_KEYWORDS = [kw.strip().lower() for kw in raw_excl.split(',') if kw.strip()]
30
PYTHON = sys.executable
33
SPI_GETWORKAREA = 0x0030
34
rect = wintypes.RECT()
35
ctypes.windll.user32.SystemParametersInfoW(SPI_GETWORKAREA, 0, ctypes.byref(rect), 0)
36
return rect.right - rect.left, rect.bottom - rect.top
38
screen_w, screen_h = get_work_area()
39
half_w, half_h = screen_w // 2, screen_h // 2
44
f'cmd.exe /C start "" cmd /K "title arma_terminal && python \"{os.path.join(CONFIG_DIR, "arma_terminal", "arma_terminal.py")}\""',
50
f'cmd.exe /C start "" cmd /K "title game_manager && python \"{os.path.join(CONFIG_DIR, "game_manager", "game_manager.py")}\""',
56
f'cmd.exe /C start "" cmd /K "title ollama_chat && python \"{os.path.join(CONFIG_DIR, "ollama_chat", "ollama_chat.py")}\""',
64
f'cmd.exe /C start "" cmd /K "title game_updater && '
65
f'cd /d \"{os.path.join(CONFIG_DIR, "game_updater")}\" && '
66
f'python game_updater.py"',
74
if win32gui.IsWindowVisible(hwnd):
75
title = win32gui.GetWindowText(hwnd)
77
wins.append((hwnd, title))
79
win32gui.EnumWindows(cb, None)
82
def normalize(s: str) -> str:
83
return re.sub(r'\s+', ' ', s.strip().lower())
85
def find_window(alias_list):
86
norm_aliases = [normalize(a) for a in alias_list]
87
for hwnd, title in enum_windows():
89
if any(excl in n for excl in EXCLUDE_KEYWORDS):
91
if any(alias in n for alias in norm_aliases):
92
print(f"[DEBUG] Matched: {title!r} ← for {alias_list}")
95
if alias_list == ["game_manager"]:
96
for hwnd, title in enum_windows():
98
if n.startswith("[c:\\users\\itsne\\desktop\\arma_chatbot_config\\vpn\\ovpn") and "openvpn" in n:
99
print(f"[DEBUG] Matched OpenVPN: {title!r}")
102
print(f"[DEBUG] No match for: {alias_list}")
103
print("[DEBUG] Open windows:")
104
for _, t in enum_windows():
108
def launch_and_position(aliases, cmd, pos, minimize):
110
hwnd = find_window(aliases)
112
print(f"[REPOSITION] {aliases[0]}; moving to {x},{y}")
113
win32gui.MoveWindow(hwnd, x, y, half_w, half_h, True)
115
win32gui.ShowWindow(hwnd, win32con.SW_MINIMIZE)
118
print(f"[LAUNCH] {aliases[0]} …")
119
subprocess.Popen(cmd, shell=True)
123
hwnd = find_window(aliases)
128
print(f"[WARN] couldn’t find window “{aliases[0]}” after launch.")
131
print(f"[POSITION] {aliases[0]}; moving to {x},{y}")
132
win32gui.MoveWindow(hwnd, x, y, half_w, half_h, True)
134
win32gui.ShowWindow(hwnd, win32con.SW_MINIMIZE)
137
for aliases, cmd, pos, mini in WINDOWS:
138
launch_and_position(aliases, cmd, pos, mini)
140
aliases, cmd, pos, mini = UPDATER
141
launch_and_position(aliases, cmd, pos, mini)
143
if __name__ == "__main__":