-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
171 lines (133 loc) · 6.75 KB
/
main.py
File metadata and controls
171 lines (133 loc) · 6.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import customtkinter as ctk
import json
import os
from tkinter import filedialog
from back.steam_manager import SteamManager
from back.epic_manager import EpicManager
ctk.set_appearance_mode("System")
ctk.set_default_color_theme("blue")
CONFIG_FILE = "config.json"
class GameSyncApp(ctk.CTk):
def __init__(self):
super().__init__()
self.title("GameSync")
self.geometry("600x580")
self.resizable(False, False)
self.steam_manager = SteamManager()
self.epic_manager = EpicManager()
self.config_data = self.load_config()
self.steam_paths = self.config_data.get("steamapps_paths", [])
old_path = self.config_data.get("steamapps_path")
if isinstance(old_path, str) and old_path not in self.steam_paths:
self.steam_paths.append(old_path)
self.create_widgets()
def load_config(self):
if os.path.exists(CONFIG_FILE):
try:
with open(CONFIG_FILE, 'r', encoding='utf-8') as f:
return json.load(f)
except Exception as e:
print(f"Error leyendo el JSON: {e}")
return {"steamapps_paths": [], "shortcuts_path": "", "sync_epic": True}
def save_config(self):
data = {
"steamapps_paths": self.steam_paths,
"shortcuts_path": self.entry_dest.get(),
"sync_epic": self.sync_epic_var.get()
}
with open(CONFIG_FILE, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=4)
def create_widgets(self):
self.label_title = ctk.CTkLabel(self, text="Sincronizador de Juegos", font=ctk.CTkFont(size=24, weight="bold"))
self.label_title.pack(pady=(15, 10))
# --- Zona de Steam ---
self.frame_paths = ctk.CTkFrame(self)
self.frame_paths.pack(fill="x", padx=20, pady=10)
self.label_steam = ctk.CTkLabel(self.frame_paths, text="Rutas de librerías de Steam:", anchor="w", font=ctk.CTkFont(weight="bold"))
self.label_steam.pack(fill="x", padx=10, pady=(10, 0))
self.scroll_paths = ctk.CTkScrollableFrame(self.frame_paths, height=100)
self.scroll_paths.pack(fill="x", padx=10, pady=5)
self.btn_add_path = ctk.CTkButton(self.frame_paths, text="+ Añadir ruta", width=120, command=self.add_steam_path)
self.btn_add_path.pack(pady=(5, 10))
self.render_paths()
# --- Zona de Epic Games ---
self.sync_epic_var = ctk.BooleanVar(value=self.config_data.get("sync_epic", True))
self.switch_epic = ctk.CTkSwitch(
self.frame_paths,
text="Buscar también juegos de Epic Games automáticamente",
variable=self.sync_epic_var,
font=ctk.CTkFont(weight="bold"),
command=self.save_config
)
self.switch_epic.pack(pady=(10, 15), padx=15, anchor="w")
# --- Fila de Destino ---
self.frame_dest = ctk.CTkFrame(self, fg_color="transparent")
self.frame_dest.pack(fill="x", padx=20, pady=10)
self.label_dest = ctk.CTkLabel(self.frame_dest, text="Carpeta Accesos:", width=120, anchor="w")
self.label_dest.pack(side="left")
self.entry_dest = ctk.CTkEntry(self.frame_dest, width=320)
self.entry_dest.pack(side="left", padx=(0, 10))
self.entry_dest.insert(0, self.config_data.get("shortcuts_path", ""))
self.btn_dest = ctk.CTkButton(self.frame_dest, text="Buscar", width=80, command=self.browse_dest)
self.btn_dest.pack(side="left")
# --- Botón de Sincronizar ---
self.btn_sync = ctk.CTkButton(self, text="Sincronizar Todo", font=ctk.CTkFont(size=16, weight="bold"), height=40, command=self.sync_action)
self.btn_sync.pack(pady=(15, 10))
# --- Label de estado ---
self.label_status = ctk.CTkLabel(self, text="Esperando acción...", text_color="gray", justify="center")
self.label_status.pack()
def render_paths(self):
for widget in self.scroll_paths.winfo_children():
widget.destroy()
for path in self.steam_paths:
row = ctk.CTkFrame(self.scroll_paths, fg_color="transparent")
row.pack(fill="x", pady=2)
lbl = ctk.CTkLabel(row, text=path, anchor="w")
lbl.pack(side="left", fill="x", expand=True, padx=(0, 10))
btn_del = ctk.CTkButton(row, text="X", width=30, fg_color="#FF4A4A", hover_color="#CC0000",
command=lambda p=path: self.remove_steam_path(p))
btn_del.pack(side="right")
def add_steam_path(self):
folder = filedialog.askdirectory(title="Selecciona la carpeta steamapps")
if folder:
norm_folder = os.path.normpath(folder)
if norm_folder not in self.steam_paths:
self.steam_paths.append(norm_folder)
self.render_paths()
self.save_config()
def remove_steam_path(self, path):
if path in self.steam_paths:
self.steam_paths.remove(path)
self.render_paths()
self.save_config()
def browse_dest(self):
folder = filedialog.askdirectory(title="Selecciona donde guardar los accesos")
if folder:
self.entry_dest.delete(0, "end")
self.entry_dest.insert(0, os.path.normpath(folder))
self.save_config()
def sync_action(self):
dest_path = self.entry_dest.get()
if not dest_path:
self.label_status.configure(text="Error: Debes elegir una carpeta de destino.", text_color="#FF4A4A")
return
if not self.steam_paths and not self.sync_epic_var.get():
self.label_status.configure(text="Error: Agrega rutas de Steam o activa Epic Games.", text_color="#FF4A4A")
return
self.save_config()
self.label_status.configure(text="Procesando juegos...", text_color="#E5B513")
self.update()
try:
resumen = ""
if self.steam_paths:
res_steam = self.steam_manager.sync_shortcuts(self.steam_paths, dest_path)
resumen += f"Steam: +{len(res_steam['added'])} | -{len(res_steam['removed'])} | Total: {res_steam['total_installed']}\n"
if self.sync_epic_var.get():
res_epic = self.epic_manager.sync_shortcuts(dest_path)
resumen += f"Epic Games: +{len(res_epic['added'])} | -{len(res_epic['removed'])} | Total: {res_epic['total_installed']}"
self.label_status.configure(text=resumen.strip(), text_color="#2ECC71")
except Exception as e:
self.label_status.configure(text=f"Ocurrió un error: {e}", text_color="#FF4A4A")
if __name__ == "__main__":
app = GameSyncApp()
app.mainloop()