Compare commits
2 commits
image-test
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 673b30c7be | |||
| b07ebd68ab |
1 changed files with 60 additions and 19 deletions
79
main.py
79
main.py
|
|
@ -11,11 +11,31 @@ import threading
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
|
|
||||||
APP_VERSION = "v1.1.6"
|
|
||||||
UPDATE_API_URL = "https://git.borderban.ru/api/v1/repos/BorderBan/client-py/releases/latest"
|
UPDATE_API_URL = "https://git.borderban.ru/api/v1/repos/BorderBan/client-py/releases/latest"
|
||||||
SERVER_URL = "https://server1.borderban.ru/mods/"
|
SERVER_URL = "https://server1.borderban.ru/mods/"
|
||||||
CONFIG_FILE = Path.home() / ".factorio_sync_config.json"
|
CONFIG_FILE = Path.home() / ".factorio_sync_config.json"
|
||||||
|
|
||||||
|
def load_app_config():
|
||||||
|
if CONFIG_FILE.exists():
|
||||||
|
try:
|
||||||
|
return json.loads(CONFIG_FILE.read_text())
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def save_app_config(new_data):
|
||||||
|
config = load_app_config()
|
||||||
|
config.update(new_data)
|
||||||
|
try:
|
||||||
|
CONFIG_FILE.write_text(json.dumps(config))
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Ошибка сохранения конфига: {e}")
|
||||||
|
|
||||||
|
if not getattr(sys, 'frozen', False):
|
||||||
|
APP_VERSION = "Dev"
|
||||||
|
else:
|
||||||
|
APP_VERSION = load_app_config().get("app_version", "Неизвестная версия")
|
||||||
|
|
||||||
def get_mod_base_name(filename):
|
def get_mod_base_name(filename):
|
||||||
# Пытаемся отсечь версию мода (обычно ИмяМода_1.0.0.zip)
|
# Пытаемся отсечь версию мода (обычно ИмяМода_1.0.0.zip)
|
||||||
match = re.match(r"^(.+)_(\d+\.\d+\.\d+)\.zip$", filename)
|
match = re.match(r"^(.+)_(\d+\.\d+\.\d+)\.zip$", filename)
|
||||||
|
|
@ -62,12 +82,10 @@ def check_and_update(root):
|
||||||
release_data = response.json()
|
release_data = response.json()
|
||||||
latest_version = release_data.get("tag_name")
|
latest_version = release_data.get("tag_name")
|
||||||
|
|
||||||
# Проверяем, нужна ли загрузка
|
if not latest_version:
|
||||||
if not latest_version or latest_version == APP_VERSION:
|
|
||||||
update_win.destroy()
|
update_win.destroy()
|
||||||
return
|
return
|
||||||
|
|
||||||
# Определяем имя нужного ассета в зависимости от ОС
|
|
||||||
system = platform.system().lower()
|
system = platform.system().lower()
|
||||||
asset_name = None
|
asset_name = None
|
||||||
if system == "windows":
|
if system == "windows":
|
||||||
|
|
@ -79,12 +97,34 @@ def check_and_update(root):
|
||||||
update_win.destroy()
|
update_win.destroy()
|
||||||
return
|
return
|
||||||
|
|
||||||
download_url = next((asset.get("browser_download_url") for asset in release_data.get("assets", []) if asset.get("name") == asset_name), None)
|
target_asset = next((asset for asset in release_data.get("assets", []) if asset.get("name") == asset_name), None)
|
||||||
|
if not target_asset:
|
||||||
|
update_win.destroy()
|
||||||
|
return
|
||||||
|
|
||||||
|
download_url = target_asset.get("browser_download_url")
|
||||||
|
|
||||||
if not download_url:
|
if not download_url:
|
||||||
update_win.destroy()
|
update_win.destroy()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
remote_size = target_asset.get("size", 0)
|
||||||
|
local_size = os.path.getsize(exe_path)
|
||||||
|
|
||||||
|
# Если размер файла совпадает с размером из релиза, считаем, что мы уже на этой версии
|
||||||
|
if remote_size and local_size == remote_size:
|
||||||
|
if load_app_config().get("app_version") != latest_version:
|
||||||
|
save_app_config({"app_version": latest_version})
|
||||||
|
global APP_VERSION
|
||||||
|
APP_VERSION = latest_version
|
||||||
|
update_win.destroy()
|
||||||
|
return
|
||||||
|
|
||||||
|
# На крайний случай проверяем сохраненную версию, если размер не удалось получить
|
||||||
|
if not remote_size and load_app_config().get("app_version") == latest_version:
|
||||||
|
update_win.destroy()
|
||||||
|
return
|
||||||
|
|
||||||
# Обновляем текст на окне, если обновление найдено
|
# Обновляем текст на окне, если обновление найдено
|
||||||
update_label.config(text=f"Обнаружена новая версия ({latest_version}).\nЗагрузка обновления...\nПожалуйста, подождите.")
|
update_label.config(text=f"Обнаружена новая версия ({latest_version}).\nЗагрузка обновления...\nПожалуйста, подождите.")
|
||||||
update_win.update()
|
update_win.update()
|
||||||
|
|
@ -104,6 +144,9 @@ def check_and_update(root):
|
||||||
os.replace(exe_path, old_exe_path)
|
os.replace(exe_path, old_exe_path)
|
||||||
os.replace(new_exe_path, exe_path)
|
os.replace(new_exe_path, exe_path)
|
||||||
|
|
||||||
|
# Сохраняем новую версию в конфиг перед перезапуском
|
||||||
|
save_app_config({"app_version": latest_version})
|
||||||
|
|
||||||
# Перезапускаем новую версию и выходим из текущей
|
# Перезапускаем новую версию и выходим из текущей
|
||||||
subprocess.Popen([exe_path] + sys.argv[1:])
|
subprocess.Popen([exe_path] + sys.argv[1:])
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
@ -119,25 +162,23 @@ class SyncApp:
|
||||||
self.root.title(f"Factorio Mod Sync {APP_VERSION}")
|
self.root.title(f"Factorio Mod Sync {APP_VERSION}")
|
||||||
self.root.geometry("500x350")
|
self.root.geometry("500x350")
|
||||||
|
|
||||||
self.config = self.load_config()
|
self.config = load_app_config()
|
||||||
|
if "mods_path" not in self.config:
|
||||||
|
self.config["mods_path"] = ""
|
||||||
|
if "game_path" not in self.config:
|
||||||
|
self.config["game_path"] = ""
|
||||||
|
|
||||||
self.setup_ui()
|
self.setup_ui()
|
||||||
|
|
||||||
def load_config(self):
|
|
||||||
if CONFIG_FILE.exists():
|
|
||||||
data = json.loads(CONFIG_FILE.read_text())
|
|
||||||
return {
|
|
||||||
"mods_path": data.get("mods_path", ""),
|
|
||||||
"game_path": data.get("game_path", "")
|
|
||||||
}
|
|
||||||
return {"mods_path": "", "game_path": ""}
|
|
||||||
|
|
||||||
def save_config(self, mods_path=None, game_path=None):
|
def save_config(self, mods_path=None, game_path=None):
|
||||||
config = self.load_config()
|
data_to_save = {}
|
||||||
if mods_path is not None:
|
if mods_path is not None:
|
||||||
config["mods_path"] = mods_path
|
data_to_save["mods_path"] = mods_path
|
||||||
|
self.config["mods_path"] = mods_path
|
||||||
if game_path is not None:
|
if game_path is not None:
|
||||||
config["game_path"] = game_path
|
data_to_save["game_path"] = game_path
|
||||||
CONFIG_FILE.write_text(json.dumps(config))
|
self.config["game_path"] = game_path
|
||||||
|
save_app_config(data_to_save)
|
||||||
|
|
||||||
def setup_ui(self):
|
def setup_ui(self):
|
||||||
# Выбор пути
|
# Выбор пути
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue