salida en app

This commit is contained in:
2026-01-20 14:07:50 +01:00
parent 6731121924
commit 59315129b7
+70 -24
View File
@@ -1,5 +1,6 @@
import os
import json
import threading
import subprocess
import tkinter as tk
from tkinter import filedialog, messagebox
@@ -7,11 +8,12 @@ from tkinter import filedialog, messagebox
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
CONFIG_FILE = os.path.join(BASE_DIR, "config.json")
class DirectorySelectorApp:
def __init__(self, root):
self.root = root
self.root.title("Selector de Directorios")
self.root.geometry("600x600")
self.root.title("Selector de Directorios ES-DE / ROMs")
self.root.geometry("700x650")
# Variables de rutas
self.path_esde_src = tk.StringVar()
@@ -47,7 +49,15 @@ class DirectorySelectorApp:
# BOTÓN ROBOCOPY
# ---------------------------
tk.Button(root, text="Robocopy", font=("Arial", 12, "bold"),
command=self.run_robocopy).pack(pady=15)
command=self.run_robocopy).pack(pady=10)
# ---------------------------
# PANEL DE LOG
# ---------------------------
tk.Label(root, text="Progreso:", font=("Arial", 11)).pack(pady=(5, 0))
self.log = tk.Text(root, height=10, state="disabled", bg="#111", fg="#0f0")
self.log.pack(fill="both", expand=False, padx=10, pady=5)
# Evento de cierre
self.root.protocol("WM_DELETE_WINDOW", self.on_close)
@@ -95,13 +105,27 @@ class DirectorySelectorApp:
messagebox.showerror("Error", f"No se pudo leer la ruta:\n{e}")
# ---------------------------------------------------------
# EJECUTAR ROBOCOPY
# LOG
# ---------------------------------------------------------
def append_log(self, text):
self.log.configure(state="normal")
self.log.insert(tk.END, text + "\n")
self.log.see(tk.END)
self.log.configure(state="disabled")
# ---------------------------------------------------------
# EJECUTAR ROBOCOPY (HILO)
# ---------------------------------------------------------
def run_robocopy(self):
thread = threading.Thread(target=self._run_robocopy_thread)
thread.daemon = True
thread.start()
def _run_robocopy_thread(self):
selected = [self.listbox.get(i) for i in self.listbox.curselection()]
if not selected:
messagebox.showwarning("Aviso", "No has seleccionado ningún sistema.")
self.append_log("No hay sistemas seleccionados.")
return
esde_src = self.path_esde_src.get()
@@ -110,37 +134,59 @@ class DirectorySelectorApp:
roms_dst = self.path_roms_dst.get()
if not all([esde_src, roms_src, esde_dst, roms_dst]):
messagebox.showerror("Error", "Debes configurar todas las rutas antes de continuar.")
self.append_log("ERROR: Debes configurar todas las rutas antes de continuar.")
return
self.append_log("=== INICIANDO ROBOCOPY ===")
for system in selected:
# --- ROMs ---
src = os.path.join(roms_src, system)
dst = os.path.join(roms_dst, system)
self.launch_robocopy(src, dst)
self.append_log(f"\n--- Sistema: {system} ---")
# --- ES-DE gamelists ---
src = os.path.join(esde_src, "gamelists", system)
dst = os.path.join(esde_dst, "gamelists", system)
self.launch_robocopy(src, dst)
# ROMs
self.launch_robocopy_with_log(
os.path.join(roms_src, system),
os.path.join(roms_dst, system)
)
# --- ES-DE downloaded_media ---
src = os.path.join(esde_src, "downloaded_media", system)
dst = os.path.join(esde_dst, "downloaded_media", system)
self.launch_robocopy(src, dst)
# ES-DE gamelists
self.launch_robocopy_with_log(
os.path.join(esde_src, "gamelists", system),
os.path.join(esde_dst, "gamelists", system)
)
messagebox.showinfo("Completado", "Robocopy finalizado.")
# ES-DE downloaded_media
self.launch_robocopy_with_log(
os.path.join(esde_src, "downloaded_media", system),
os.path.join(esde_dst, "downloaded_media", system)
)
def launch_robocopy(self, src, dst):
self.append_log("\n=== ROBOCOPY COMPLETADO ===")
def launch_robocopy_with_log(self, src, dst):
if not os.path.isdir(src):
return # No existe, se ignora
self.append_log(f"[IGNORADO] No existe: {src}")
return
os.makedirs(dst, exist_ok=True)
cmd = f'robocopy "{src}" "{dst}" /MIR'
cmd = ["robocopy", src, dst, "/MIR"]
# Abrir en consola visible
subprocess.Popen(["cmd", "/c", cmd])
self.append_log(f"Ejecutando: robocopy \"{src}\" \"{dst}\" /MIR")
process = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
universal_newlines=True
)
for line in process.stdout:
line = line.strip()
if line:
self.append_log(line)
process.wait()
# ---------------------------------------------------------
# PERSISTENCIA