Update
This commit is contained in:
parent
2e32ffa9e8
commit
e28d11a84f
@ -1,5 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
from subprocess import Popen, PIPE
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import logging
|
import logging
|
||||||
import platform
|
import platform
|
||||||
@ -13,6 +13,13 @@ class GameLauncher:
|
|||||||
self.platform = platform.system().lower()
|
self.platform = platform.system().lower()
|
||||||
self.account_username = None
|
self.account_username = None
|
||||||
self.account_id = None
|
self.account_id = None
|
||||||
|
# Кэшируем пути к файлам
|
||||||
|
self.game_path = Path(settings.get('game', {}).get('path', ''))
|
||||||
|
self.config_path = self.game_path / 'WTF' / 'Config.wtf'
|
||||||
|
self.realmlist_paths = [
|
||||||
|
self.game_path / 'Data' / 'ruRU' / 'realmlist.wtf',
|
||||||
|
self.game_path / 'Data' / 'realmlist.wtf'
|
||||||
|
]
|
||||||
|
|
||||||
def validate_game_path(self, path: str) -> bool:
|
def validate_game_path(self, path: str) -> bool:
|
||||||
"""Проверяет корректность пути к игре"""
|
"""Проверяет корректность пути к игре"""
|
||||||
@ -21,20 +28,17 @@ class GameLauncher:
|
|||||||
|
|
||||||
game_path = Path(path)
|
game_path = Path(path)
|
||||||
|
|
||||||
# На всех платформах ищем Wow.exe
|
|
||||||
exe_name = 'Wow.exe'
|
|
||||||
|
|
||||||
required_files = [
|
required_files = [
|
||||||
exe_name,
|
game_path / 'Wow.exe',
|
||||||
'Data/common.MPQ',
|
game_path / 'Data/common.MPQ',
|
||||||
'Data/common-2.MPQ'
|
game_path / 'Data/common-2.MPQ'
|
||||||
]
|
]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for file in required_files:
|
# Проверяем каждый файл
|
||||||
file_path = game_path / file
|
for required_file in required_files:
|
||||||
if not file_path.exists():
|
if not required_file.exists():
|
||||||
self.logger.error(f"Missing required file: {file}")
|
self.logger.error(f"Missing required file: {required_file}")
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -44,12 +48,24 @@ class GameLauncher:
|
|||||||
def update_realmlist(self, path: str, realmlist: str) -> bool:
|
def update_realmlist(self, path: str, realmlist: str) -> bool:
|
||||||
"""Обновляет файл realmlist.wtf"""
|
"""Обновляет файл realmlist.wtf"""
|
||||||
try:
|
try:
|
||||||
data_path = Path(path) / 'Data' / 'realmlist.wtf'
|
# Проверяем оба возможных пути
|
||||||
data_path.parent.mkdir(parents=True, exist_ok=True)
|
data_paths = [
|
||||||
|
Path(path) / 'Data' / 'ruRU' / 'realmlist.wtf', # Путь для русской локализации
|
||||||
|
Path(path) / 'Data' / 'realmlist.wtf' # Стандартный путь
|
||||||
|
]
|
||||||
|
|
||||||
|
# Обновляем существующие файлы или создаем новые
|
||||||
|
updated = False
|
||||||
|
for data_path in data_paths:
|
||||||
|
try:
|
||||||
|
data_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
with open(data_path, 'w', encoding='utf-8') as f:
|
with open(data_path, 'w', encoding='utf-8') as f:
|
||||||
f.write(f'set realmlist {realmlist}\n')
|
f.write(f'set realmlist {realmlist}\n')
|
||||||
return True
|
updated = True
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.warning(f"Could not update {data_path}: {e}")
|
||||||
|
|
||||||
|
return updated
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Error updating realmlist: {e}")
|
self.logger.error(f"Error updating realmlist: {e}")
|
||||||
return False
|
return False
|
||||||
@ -57,6 +73,9 @@ class GameLauncher:
|
|||||||
def update_config_wtf(self, path: str) -> bool:
|
def update_config_wtf(self, path: str) -> bool:
|
||||||
"""Обновляет файл Config.wtf для автологина"""
|
"""Обновляет файл Config.wtf для автологина"""
|
||||||
try:
|
try:
|
||||||
|
# Получаем realmlist из настроек
|
||||||
|
realmlist = self.settings.get('game', {}).get('realmlist', 'logon.server.com')
|
||||||
|
|
||||||
config_path = Path(path) / 'WTF' / 'Config.wtf'
|
config_path = Path(path) / 'WTF' / 'Config.wtf'
|
||||||
|
|
||||||
# Создаем директорию WTF если её нет
|
# Создаем директорию WTF если её нет
|
||||||
@ -73,7 +92,16 @@ class GameLauncher:
|
|||||||
|
|
||||||
# Обновляем настройки
|
# Обновляем настройки
|
||||||
if self.account_username:
|
if self.account_username:
|
||||||
config['accountName'] = self.account_username
|
# Настройки для автологина
|
||||||
|
config['accountName'] = self.account_username.upper() # Имя должно быть в верхнем регистре
|
||||||
|
config['accountList'] = self.account_username.upper() # Список аккаунтов
|
||||||
|
config['lastAccountName'] = self.account_username.upper() # Последний использованный аккаунт
|
||||||
|
# Дополнительные настройки для списка аккаунтов
|
||||||
|
config['portal'] = self.account_username.upper() # Текущий аккаунт в портале
|
||||||
|
config['lastCharacterIndex'] = "0" # Индекс последнего персонажа
|
||||||
|
config['realmName'] = "WoW Server" # Имя реалма
|
||||||
|
config['savedAccountList'] = f"{self.account_username.upper()}|{realmlist}" # Сохраненный список
|
||||||
|
config['lastSelectedAccount'] = self.account_username.upper() # Последний выбранный аккаунт
|
||||||
|
|
||||||
# Добавляем другие важные настройки если их нет
|
# Добавляем другие важные настройки если их нет
|
||||||
defaults = {
|
defaults = {
|
||||||
@ -81,7 +109,13 @@ class GameLauncher:
|
|||||||
'readTOS': '1',
|
'readTOS': '1',
|
||||||
'readEULA': '1',
|
'readEULA': '1',
|
||||||
'readTerminationWithoutNotice': '1',
|
'readTerminationWithoutNotice': '1',
|
||||||
'accounttype': 'LK'
|
'accounttype': 'LK',
|
||||||
|
'lastSelectedRealm': '1', # Индекс последнего выбранного реалма
|
||||||
|
'realmList': realmlist, # Адрес сервера
|
||||||
|
'patchlist': f"'{realmlist}'", # Адрес сервера для патчей
|
||||||
|
'accountListType': "1", # Тип списка аккаунтов
|
||||||
|
'autoSelect': "1", # Автовыбор аккаунта
|
||||||
|
'autoConnect': "1" # Автоподключение
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value in defaults.items():
|
for key, value in defaults.items():
|
||||||
@ -131,13 +165,6 @@ class GameLauncher:
|
|||||||
# Формируем параметры запуска
|
# Формируем параметры запуска
|
||||||
launch_options = self.settings.get('game', {}).get('launch_options', '').split()
|
launch_options = self.settings.get('game', {}).get('launch_options', '').split()
|
||||||
|
|
||||||
# Добавляем параметры автологина если есть данные аккаунта
|
|
||||||
if self.account_username and self.account_id:
|
|
||||||
launch_options.extend([
|
|
||||||
'-login', self.account_username,
|
|
||||||
'-accountid', str(self.account_id)
|
|
||||||
])
|
|
||||||
|
|
||||||
# Добавляем параметры графики
|
# Добавляем параметры графики
|
||||||
graphics = self.settings.get('graphics', {})
|
graphics = self.settings.get('graphics', {})
|
||||||
if graphics.get('windowed', False):
|
if graphics.get('windowed', False):
|
||||||
@ -153,14 +180,14 @@ class GameLauncher:
|
|||||||
try:
|
try:
|
||||||
runner = self.settings.get('game', {}).get('runner', 'wine')
|
runner = self.settings.get('game', {}).get('runner', 'wine')
|
||||||
|
|
||||||
if runner == 'wine':
|
if runner == 'portproton':
|
||||||
|
cmd = ['portproton', exe_path] + launch_options
|
||||||
|
elif runner == 'wine':
|
||||||
cmd = ['wine', exe_path] + launch_options
|
cmd = ['wine', exe_path] + launch_options
|
||||||
elif runner == 'lutris':
|
elif runner == 'lutris':
|
||||||
cmd = ['lutris', 'rungame', exe_path] + launch_options
|
cmd = ['lutris', 'rungame', exe_path] + launch_options
|
||||||
elif runner == 'proton':
|
elif runner == 'proton':
|
||||||
cmd = ['proton', 'run', exe_path] + launch_options
|
cmd = ['proton', 'run', exe_path] + launch_options
|
||||||
elif runner == 'portproton':
|
|
||||||
cmd = ['portproton', 'run', exe_path] + launch_options
|
|
||||||
elif runner == 'crossover':
|
elif runner == 'crossover':
|
||||||
cmd = ['crossover', exe_path] + launch_options
|
cmd = ['crossover', exe_path] + launch_options
|
||||||
else:
|
else:
|
||||||
@ -172,15 +199,17 @@ class GameLauncher:
|
|||||||
env['WINEPREFIX'] = self.settings['game']['wineprefix']
|
env['WINEPREFIX'] = self.settings['game']['wineprefix']
|
||||||
env['WINEARCH'] = 'win32'
|
env['WINEARCH'] = 'win32'
|
||||||
|
|
||||||
subprocess.Popen(cmd, env=env)
|
# Запускаем процесс
|
||||||
|
Popen(cmd, env=env)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Error launching with Wine: {e}")
|
self.logger.error(f"Error launching with Wine: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
elif self.platform == 'darwin':
|
elif self.platform == 'darwin':
|
||||||
subprocess.Popen(['open', exe_path, '--args'] + launch_options)
|
Popen(['open', exe_path, '--args'] + launch_options)
|
||||||
else:
|
else:
|
||||||
subprocess.Popen([exe_path] + launch_options)
|
Popen([exe_path] + launch_options)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user