import os import urllib.request import shutil from pymxs import runtime as rt # ========================================== # CONFIGURAÇÕES DO GITEA - IMMERSE GAMES # ========================================== GITEA_RAW_URL = "https://git.immersegame.com/vr4life_public/vr4life-3dmax-plugin/raw/branch/main/" GITEA_TOKEN = "3831a0da2f87e391f41f4649d48498136a1903c9" # Caminho onde os scripts são instalados (Documentos) user_scripts_dir = rt.getDir(rt.name("userScripts")) PLUGIN_DIR = os.path.join(user_scripts_dir, "VR4Life_Plugin").replace("\\", "/") FILES_TO_DOWNLOAD = [ "vr4life_ui.py", "vr4life_engine.py", "vr4life_cloud.py", "run_vr4life.py", "vr4life_updater.py", "install_vr4life.py", "vr4life.mnx", "version.txt" ] def install_from_cloud(): rt.clearListener() print("=== DEBUG DE CAMINHOS VR4LIFE ===") print(f"Diretório de destino dos Pythons: {PLUGIN_DIR}") if not os.path.exists(PLUGIN_DIR): os.makedirs(PLUGIN_DIR) try: for file_name in FILES_TO_DOWNLOAD: remote_url = f"{GITEA_RAW_URL}{file_name}?token={GITEA_TOKEN}" local_path = os.path.join(PLUGIN_DIR, file_name).replace("\\", "/") req = urllib.request.Request(remote_url) req.add_header("Authorization", "token " + GITEA_TOKEN) response = urllib.request.urlopen(req) if file_name.endswith(".mnx"): with open(local_path, "wb") as f: f.write(response.read()) print(f"MNX baixado para: {local_path}") else: remote_code = response.read().decode('utf-8') with open(local_path, "w", encoding="utf-8") as f: f.write(remote_code) print(f"Script baixado para: {local_path}") # --- INSTALAÇÃO DO MENU --- pasta_macros = rt.pathConfig.getDir(rt.name("userMacros")) pasta_enu = os.path.dirname(pasta_macros) pasta_ui_usuario = os.path.join(pasta_enu, "en-US", "UI") if not os.path.exists(pasta_ui_usuario): os.makedirs(pasta_ui_usuario) # AGORA GARANTIMOS QUE O PATH DE ORIGEM É O PLUGIN_DIR origem_mnx = os.path.join(PLUGIN_DIR, "vr4life.mnx") destino_mnx = os.path.join(pasta_ui_usuario, "vr4life.mnx") print(f"Tentando copiar MNX da origem: {origem_mnx}") print(f"Para o destino final: {destino_mnx}") if os.path.exists(origem_mnx): shutil.copy2(origem_mnx, destino_mnx) print(">>> Cópia do MNX realizada com sucesso!") else: print("!!! ERRO: O arquivo vr4life.mnx não foi encontrado na pasta PLUGIN_DIR após o download.") # Executa o instalador local install_script = os.path.join(PLUGIN_DIR, "install_vr4life.py").replace("\\", "/") if os.path.exists(install_script): print(f"Executando script de instalação: {install_script}") rt.python.ExecuteFile(install_script) rt.messageBox("Instalação Online concluída. Verifique o Listener para o log de caminhos.", title="VR4Life") except Exception as e: print(f"ERRO TÉCNICO: {str(e)}") rt.messageBox(f"Falha na instalação: {str(e)}", title="Erro") if __name__ == "__main__": install_from_cloud()