Compare commits

..

5 commits
v1.1.5 ... main

Author SHA1 Message Date
673b30c7be update fix
All checks were successful
Build and Publish Release / Build Linux (release) Successful in 2m11s
Build and Publish Release / Build Windows (release) Successful in 4m49s
Build and Publish Release / Upload Assets to Release (release) Successful in 11s
2026-05-05 15:20:16 +05:00
b07ebd68ab microfix 2026-05-05 15:15:29 +05:00
0c47d8c0a9 action update
All checks were successful
Build and Publish Release / Build Windows (release) Successful in 5m25s
Build and Publish Release / Build Linux (release) Successful in 18m56s
Build and Publish Release / Upload Assets to Release (release) Successful in 11s
2026-05-04 19:18:42 +05:00
b040f207c8 update visible + failproof action
Some checks failed
Build and Publish Release / Build Linux (release) Failing after 17s
Build and Publish Release / Build Windows (release) Failing after 25s
Build and Publish Release / Upload Assets to Release (release) Has been cancelled
2026-05-04 19:00:37 +05:00
9155d1e50a автообновление
All checks were successful
Build and Publish Release / Build Linux (release) Successful in 2m5s
Build and Publish Release / Build Windows (release) Successful in 6m56s
Build and Publish Release / Upload Assets to Release (release) Successful in 15s
2026-05-03 22:45:06 +05:00
2 changed files with 146 additions and 16 deletions

View file

@ -66,6 +66,7 @@ jobs:
name: Upload Assets to Release name: Upload Assets to Release
needs: [build-linux, build-windows] needs: [build-linux, build-windows]
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: always() && (needs.build-linux.result == 'success' || needs.build-windows.result == 'success')
steps: steps:
- name: Download all artifacts - name: Download all artifacts
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
@ -75,6 +76,7 @@ jobs:
- name: Add files to Forgejo Release - name: Add files to Forgejo Release
uses: https://github.com/softprops/action-gh-release@v2 uses: https://github.com/softprops/action-gh-release@v2
with: with:
fail_on_unmatched_files: false
files: | files: |
artifacts/linux-build/factorio-mod-sync-linux artifacts/linux-build/factorio-mod-sync-linux
artifacts/windows-build/factorio-mod-sync-windows.exe artifacts/windows-build/factorio-mod-sync-windows.exe

160
main.py
View file

@ -1,4 +1,6 @@
import os import os
import sys
import platform
import hashlib import hashlib
import json import json
import requests import requests
@ -9,10 +11,31 @@ import threading
import subprocess import subprocess
import re import re
# --- КОНФИГУРАЦИЯ --- 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)
@ -29,31 +52,133 @@ def get_file_hash(filepath):
sha256_hash.update(byte_block) sha256_hash.update(byte_block)
return sha256_hash.hexdigest() return sha256_hash.hexdigest()
def check_and_update(root):
# Выполняем автообновление только если программа запущена как скомпилированный бинарник
if not getattr(sys, 'frozen', False):
return
exe_path = sys.executable
old_exe_path = exe_path + ".old"
# Очистка мусора: удаляем старый файл, оставшийся от предыдущего обновления
if os.path.exists(old_exe_path):
try:
os.remove(old_exe_path)
except Exception:
pass
# Показываем окно сразу во время проверки
update_win = tk.Toplevel(root)
update_win.title("Обновление")
update_win.geometry("350x100")
update_label = tk.Label(update_win, text="Проверка наличия обновлений...")
update_label.pack(expand=True)
update_win.update()
try:
# Получаем данные о последнем релизе
response = requests.get(UPDATE_API_URL, timeout=5)
response.raise_for_status()
release_data = response.json()
latest_version = release_data.get("tag_name")
if not latest_version:
update_win.destroy()
return
system = platform.system().lower()
asset_name = None
if system == "windows":
asset_name = "factorio-mod-sync-windows.exe"
elif system == "linux":
asset_name = "factorio-mod-sync-linux"
if not asset_name:
update_win.destroy()
return
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:
update_win.destroy()
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_win.update()
new_exe_path = exe_path + ".new"
with requests.get(download_url, stream=True, timeout=60) as r:
r.raise_for_status()
with open(new_exe_path, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
update_win.update() # Обновляем окно, чтобы оно не "зависало" во время скачивания
if system == "linux":
os.chmod(new_exe_path, 0o755)
# Подменяем исполняемый файл (Windows позволяет переименовать запущенный файл)
os.replace(exe_path, old_exe_path)
os.replace(new_exe_path, exe_path)
# Сохраняем новую версию в конфиг перед перезапуском
save_app_config({"app_version": latest_version})
# Перезапускаем новую версию и выходим из текущей
subprocess.Popen([exe_path] + sys.argv[1:])
sys.exit(0)
except Exception as e:
print(f"Ошибка проверки или установки обновления: {e}")
update_win.destroy()
# При ошибке просто продолжаем обычный запуск
class SyncApp: class SyncApp:
def __init__(self, root): def __init__(self, root):
self.root = root self.root = root
self.root.title("Factorio Mod Sync") 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):
# Выбор пути # Выбор пути
@ -240,5 +365,8 @@ class SyncApp:
if __name__ == "__main__": if __name__ == "__main__":
root = tk.Tk() root = tk.Tk()
root.withdraw() # Скрываем основное окно на время проверки обновления
check_and_update(root)
root.deiconify() # Показываем основное окно
app = SyncApp(root) app = SyncApp(root)
root.mainloop() root.mainloop()