You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
4.1 KiB
Python

import os
import urllib.request
from pymxs import runtime as rt
try: from PySide6 import QtWidgets
except ImportError: from PySide2 import QtWidgets
# URL Oficial do repositório da Immerse Games (Lendo a branch 'main')
# Obs: Se o seu Gitea estiver usando 'master' em vez de 'main', basta trocar a última palavra.
GITEA_RAW_URL = "https://git.immersegame.com/immersegame/vr4life-3dmax-plugin/raw/branch/main/"
# Token de Leitura do Gitea
GITEA_TOKEN = "efebcde14ce96a2b80d0b3f207991bc155018ab8"
FILES_TO_UPDATE = [
"vr4life_ui.py",
"vr4life_engine.py",
"vr4life_cloud.py",
"run_vr4life.py",
"vr4life_updater.py"
]
def check_and_update(ui_parent=None):
script_dir = os.path.dirname(os.path.realpath(__file__))
local_version_file = os.path.join(script_dir, "version.txt").replace("\\", "/")
if ui_parent:
ui_parent.pb.setFormat("Autenticando e checando versão no Gitea..."); QtWidgets.QApplication.processEvents()
try:
# 1. Lê a versão local (Se não existir, assume 0.0)
local_version = "0.0"
if os.path.exists(local_version_file):
with open(local_version_file, "r") as f:
local_version = f.read().strip()
# 2. Bate na Nuvem com o Token para ler o version.txt
remote_version_url = GITEA_RAW_URL + "version.txt"
req_version = urllib.request.Request(remote_version_url)
req_version.add_header("Authorization", f"token {GITEA_TOKEN}")
response_version = urllib.request.urlopen(req_version)
remote_version = response_version.read().decode('utf-8').strip()
# 3. Compara as versões: Só baixa se a do Gitea for mais nova
if remote_version == local_version:
if ui_parent:
ui_parent.pb.setFormat("Sistema já está atualizado!"); ui_parent.pb.setValue(100)
QtWidgets.QMessageBox.information(ui_parent, "Atualizador", f"Você já está usando a versão mais recente ({local_version}).")
return
# 4. Inicia o Download Seguro dos Arquivos
if ui_parent:
ui_parent.pb.setFormat(f"Nova versão {remote_version} encontrada! Baixando..."); QtWidgets.QApplication.processEvents()
updated_count = 0
for file_name in FILES_TO_UPDATE:
remote_url = GITEA_RAW_URL + file_name
local_path = os.path.join(script_dir, file_name).replace("\\", "/")
if ui_parent:
ui_parent.pb.setFormat(f"Baixando {file_name}..."); QtWidgets.QApplication.processEvents()
# Puxa o código com o Token
req = urllib.request.Request(remote_url)
req.add_header("Authorization", f"token {GITEA_TOKEN}")
response = urllib.request.urlopen(req)
remote_code = response.read().decode('utf-8')
# Sobrescreve na máquina local
with open(local_path, "w", encoding="utf-8") as f:
f.write(remote_code)
updated_count += 1
# 5. Salva a nova versão local para a próxima checagem
with open(local_version_file, "w") as f:
f.write(remote_version)
msg = f"Sucesso! Plugin atualizado para a versão {remote_version} ({updated_count} arquivos).\n\nPor favor, feche esta janela e abra o plugin novamente pelo menu superior."
if ui_parent:
ui_parent.pb.setFormat("Atualização Concluída!"); ui_parent.pb.setValue(100)
QtWidgets.QMessageBox.information(ui_parent, "Update VR4Life", msg)
else:
rt.messageBox(msg, title="Update VR4Life")
except Exception as e:
erro_msg = f"Falha de Autenticação ou Download.\nVerifique seu Token e URL do Gitea.\n\nDetalhe técnico: {str(e)}"
if ui_parent:
QtWidgets.QMessageBox.critical(ui_parent, "Erro de Update", erro_msg)
ui_parent.pb.setFormat("Pronto"); ui_parent.pb.setValue(0)
else:
rt.messageBox(erro_msg, title="Erro de Update")