-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmain.py
More file actions
256 lines (183 loc) · 7.9 KB
/
main.py
File metadata and controls
256 lines (183 loc) · 7.9 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import json
import os
import shutil
import subprocess
import tkinter
import winreg
from pathlib import Path
from tkinter import Frame, Tk, NW, DISABLED, NORMAL, Toplevel, CENTER, messagebox
from tkinter.ttk import Combobox, Label, Entry, Button
def close_egs():
try:
return subprocess.check_call("taskkill /f /im EpicGamesLauncher.exe", shell=True)
except subprocess.CalledProcessError:
return 1
def get_egs_manifest_directory():
target_key = r"\SOFTWARE\Epic Games\EOS"
users = winreg.QueryInfoKey(winreg.HKEY_USERS)
for i in range(0, users[0]):
user = winreg.EnumKey(winreg.HKEY_USERS, i)
try:
registry = winreg.OpenKey(winreg.HKEY_USERS, user + target_key, 0, winreg.KEY_READ)
data_tuple = winreg.QueryValueEx(registry, "ModSdkMetadataDir")
if data_tuple and data_tuple[0] != "":
return os.path.normpath(data_tuple[0])
except FileNotFoundError:
continue
except PermissionError:
continue
return None
def get_egs_items():
manifest_directory = get_egs_manifest_directory()
items = []
for item in os.listdir(manifest_directory):
if item.endswith(".item"):
items.append(os.path.join(manifest_directory, item))
return items
def get_unreal_items():
ue_items = {}
unreal_binary_names = ("UnrealEditor", "UE4Editor")
for item in get_egs_items():
try:
with open(item, "r", encoding="utf-8") as f:
if os.path.getsize(item) == 0:
continue # Saltar archivos vacíos
data = json.load(f)
if any(binary in data.get("LaunchExecutable", "") for binary in unreal_binary_names):
ue_items[item] = data
except (json.JSONDecodeError, KeyError):
continue # Ignora archivos malformados o sin los datos necesarios
return ue_items
def get_unreal_manifest(ue_item: dict):
manifest_location = os.path.normpath(ue_item["ManifestLocation"])
installation_guid = ue_item["InstallationGuid"] + ".mancpn"
return os.path.join(manifest_location, installation_guid)
def get_unreal_version(ue_item: dict):
return ue_item["AppName"][3:]
def create_backup(path: str, backup_root_dir: str):
backup_dir = os.path.join(backup_root_dir, Path(path).stem)
backup_path = os.path.join(backup_dir, os.path.basename(path))
if not os.path.exists(backup_dir):
os.makedirs(backup_dir)
shutil.copy(path, backup_path)
def restore_backup(path: str, backup_dir: str):
backup_path = os.path.join(backup_dir, Path(path).stem, os.path.basename(path))
shutil.copy(backup_path, path)
def change_item_version(path: str, ue_item: dict, version: str):
original_version = get_unreal_version(ue_item)
ue_item["AppName"] = "UE_" + version
ue_item["MainGameAppName"] = "UE_" + version
# Make it clear what version has what installed
ue_item["AppVersionString"] = ue_item["AppVersionString"].replace(original_version, version)
with open(path, "w") as f:
json.dump(ue_item, f, indent=4)
def change_manifest_version(ue_item: dict, version: str):
manifest = get_unreal_manifest(ue_item)
with open(manifest, "r") as f:
data = json.load(f)
data["AppName"] = "UE_" + version
with open(manifest, "w") as f:
json.dump(data, f, indent=4)
def change_version(path: str, ue_item: dict, version: str):
change_item_version(path, ue_item, version)
change_manifest_version(ue_item, version)
def show_egs_closing_message():
message_window = Toplevel()
message_window.geometry("250x100")
message_window.title("")
message_window.after(5000, message_window.destroy)
frame = Frame(message_window, width=250, height=100)
frame.grid(row=0, column=0, sticky="NW")
message_label = tkinter.Label(frame, text="Closing Epic Games Launcher... Please wait.")
message_label.place(relx=0.5, rely=0.5, anchor=CENTER)
message_window.grab_set()
def main():
backup_dir = os.path.join(os.path.dirname(__file__), "EpicGamesBackup")
unreal_items = get_unreal_items()
unreal_versions = [get_unreal_version(data) for path, data in unreal_items.items()]
root = Tk()
root.geometry("250x100")
root.title("")
root.wm_resizable(False, False)
frame = Frame(root, bd=8)
frame.pack(fill="both")
# Top
top_frame = Frame(frame, padx=4, pady=4)
top_frame.grid(row=0, column=0, sticky=NW)
label = Label(top_frame, text="UE version")
label.grid(row=0, column=0, sticky=NW)
unreal_combobox = Combobox(top_frame, values=unreal_versions)
unreal_combobox.current(0)
unreal_combobox.grid(row=0, column=1, sticky=NW, padx=8)
# Middle
middle_frame = Frame(frame, padx=4, pady=4)
middle_frame.grid(row=1, column=0, sticky=NW)
label = Label(middle_frame, text="New UE version")
label.grid(row=0, column=0, sticky=NW)
version_entry = Entry(middle_frame)
version_entry.insert(0, "5.0")
version_entry.grid(row=0, column=1, sticky=NW, padx=8)
# Bottom
bottom_frame = Frame(frame, padx=4, pady=4)
bottom_frame.grid(row=2, column=0, sticky=NW)
restore_needed = False
def on_change_version():
nonlocal restore_needed
close_egs()
unreal_combobox["state"] = DISABLED
version_entry["state"] = DISABLED
button_change["state"] = DISABLED
button_engine["state"] = DISABLED
button_restore["state"] = NORMAL
restore_needed = True
for path, data in unreal_items.items():
create_backup(path, backup_dir)
create_backup(get_unreal_manifest(data), backup_dir)
unreal_version = unreal_combobox.get()
version = version_entry.get()
for path, data in unreal_items.items():
if get_unreal_version(data) == unreal_version:
change_version(path, data, version)
def on_restore_version():
nonlocal restore_needed
close_egs()
unreal_combobox["state"] = NORMAL
version_entry["state"] = NORMAL
button_change["state"] = NORMAL
button_engine["state"] = NORMAL
button_restore["state"] = DISABLED
restore_needed = False
for path, data in unreal_items.items():
unreal_version = version_entry.get()
if get_unreal_version(data) == unreal_version:
restore_backup(path, backup_dir)
restore_backup(get_unreal_manifest(data), backup_dir)
with open(path, "r") as f:
unreal_items[path] = json.load(f)
def on_open_engine_dir():
unreal_version = unreal_combobox.get()
for path, data in unreal_items.items():
if get_unreal_version(data) == unreal_version:
plugins_location = os.path.join(data["InstallLocation"], "Engine", "Plugins")
marketplace_location = os.path.join(plugins_location, "Marketplace")
if os.path.exists(marketplace_location):
os.startfile(marketplace_location)
else:
messagebox.showerror("Error", f"Directory doesn't exist: {marketplace_location}")
if os.path.exists(plugins_location):
os.startfile(plugins_location)
button_change = Button(bottom_frame, text="Change", command=on_change_version)
button_change.grid(row=0, column=0, sticky=NW)
button_restore = Button(bottom_frame, text="Restore", command=on_restore_version, state=DISABLED)
button_restore.grid(row=0, column=1, sticky=NW)
button_engine = Button(bottom_frame, text="Open", command=on_open_engine_dir)
button_engine.grid(row=0, column=3, sticky=NW)
def on_close():
nonlocal restore_needed
if restore_needed:
on_restore_version()
root.destroy()
root.protocol("WM_DELETE_WINDOW", on_close)
root.mainloop()
if __name__ == '__main__':
main()