Compare commits
No commits in common. "main" and "v1.1.6" have entirely different histories.
2 changed files with 25 additions and 77 deletions
|
|
@ -66,7 +66,6 @@ jobs:
|
|||
name: Upload Assets to Release
|
||||
needs: [build-linux, build-windows]
|
||||
runs-on: ubuntu-latest
|
||||
if: always() && (needs.build-linux.result == 'success' || needs.build-windows.result == 'success')
|
||||
steps:
|
||||
- name: Download all artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
|
|
@ -76,7 +75,6 @@ jobs:
|
|||
- name: Add files to Forgejo Release
|
||||
uses: https://github.com/softprops/action-gh-release@v2
|
||||
with:
|
||||
fail_on_unmatched_files: false
|
||||
files: |
|
||||
artifacts/linux-build/factorio-mod-sync-linux
|
||||
artifacts/windows-build/factorio-mod-sync-windows.exe
|
||||
|
|
|
|||
100
main.py
100
main.py
|
|
@ -11,31 +11,12 @@ import threading
|
|||
import subprocess
|
||||
import re
|
||||
|
||||
# --- КОНФИГУРАЦИЯ ---
|
||||
APP_VERSION = "v1.1.6" # Укажите здесь вашу текущую версию
|
||||
UPDATE_API_URL = "https://git.borderban.ru/api/v1/repos/BorderBan/client-py/releases/latest"
|
||||
SERVER_URL = "https://server1.borderban.ru/mods/"
|
||||
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):
|
||||
# Пытаемся отсечь версию мода (обычно ИмяМода_1.0.0.zip)
|
||||
match = re.match(r"^(.+)_(\d+\.\d+\.\d+)\.zip$", filename)
|
||||
|
|
@ -67,14 +48,6 @@ def check_and_update(root):
|
|||
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)
|
||||
|
|
@ -82,10 +55,11 @@ def check_and_update(root):
|
|||
release_data = response.json()
|
||||
latest_version = release_data.get("tag_name")
|
||||
|
||||
if not latest_version:
|
||||
update_win.destroy()
|
||||
# Проверяем, нужна ли загрузка
|
||||
if not latest_version or latest_version == APP_VERSION:
|
||||
return
|
||||
|
||||
# Определяем имя нужного ассета в зависимости от ОС
|
||||
system = platform.system().lower()
|
||||
asset_name = None
|
||||
if system == "windows":
|
||||
|
|
@ -94,39 +68,18 @@ def check_and_update(root):
|
|||
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")
|
||||
download_url = next((asset.get("browser_download_url") for asset in release_data.get("assets", []) if asset.get("name") == asset_name), None)
|
||||
|
||||
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 = tk.Toplevel(root)
|
||||
update_win.title("Обновление")
|
||||
update_win.geometry("350x100")
|
||||
tk.Label(update_win, text=f"Обнаружена новая версия ({latest_version}).\nЗагрузка обновления...\nПожалуйста, подождите.").pack(expand=True)
|
||||
update_win.update()
|
||||
|
||||
new_exe_path = exe_path + ".new"
|
||||
|
|
@ -135,7 +88,6 @@ def check_and_update(root):
|
|||
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)
|
||||
|
|
@ -144,16 +96,12 @@ def check_and_update(root):
|
|||
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:
|
||||
|
|
@ -162,23 +110,25 @@ class SyncApp:
|
|||
self.root.title(f"Factorio Mod Sync {APP_VERSION}")
|
||||
self.root.geometry("500x350")
|
||||
|
||||
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.config = self.load_config()
|
||||
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):
|
||||
data_to_save = {}
|
||||
config = self.load_config()
|
||||
if mods_path is not None:
|
||||
data_to_save["mods_path"] = mods_path
|
||||
self.config["mods_path"] = mods_path
|
||||
config["mods_path"] = mods_path
|
||||
if game_path is not None:
|
||||
data_to_save["game_path"] = game_path
|
||||
self.config["game_path"] = game_path
|
||||
save_app_config(data_to_save)
|
||||
config["game_path"] = game_path
|
||||
CONFIG_FILE.write_text(json.dumps(config))
|
||||
|
||||
def setup_ui(self):
|
||||
# Выбор пути
|
||||
|
|
|
|||
Loading…
Reference in a new issue