mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 11:18:26 +02:00
Added a Progressbar, and removed lag while patching the game.
This commit is contained in:
parent
22f007fc13
commit
0a5a15d64b
1 changed files with 183 additions and 75 deletions
258
main.pyw
258
main.pyw
|
@ -1,5 +1,6 @@
|
||||||
from tkinter import *
|
from tkinter import *
|
||||||
from tkinter import messagebox, filedialog, ttk
|
from tkinter import messagebox, filedialog, ttk
|
||||||
|
from threading import Thread
|
||||||
import subprocess
|
import subprocess
|
||||||
import shutil
|
import shutil
|
||||||
import json
|
import json
|
||||||
|
@ -12,8 +13,9 @@ def filecopy(src, dst):
|
||||||
f2.write(f1.read()) # could be buffered
|
f2.write(f1.read()) # could be buffered
|
||||||
|
|
||||||
get_filename = lambda file: ".".join(file.split(".")[:-1])
|
get_filename = lambda file: ".".join(file.split(".")[:-1])
|
||||||
if not(os.path.exists("./file/Track/")):
|
get_nodir = lambda file: file.split("/")[-1].split("\\")[-1]
|
||||||
os.makedirs("./file/Track/")
|
get_extension = lambda file: file.split(".")[-1]
|
||||||
|
if not(os.path.exists("./file/Track/")): os.makedirs("./file/Track/")
|
||||||
|
|
||||||
class ClassApp():
|
class ClassApp():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -37,107 +39,213 @@ class ClassApp():
|
||||||
Button(self.frame_game_path, text="...", relief=RIDGE, command=select_path).grid(row=1,column=2,sticky="NEWS")
|
Button(self.frame_game_path, text="...", relief=RIDGE, command=select_path).grid(row=1,column=2,sticky="NEWS")
|
||||||
|
|
||||||
def use_path():
|
def use_path():
|
||||||
self.frame_action.grid_forget()
|
def func():
|
||||||
path = entry_game_path.get()
|
self.frame_action.grid_forget()
|
||||||
if not(os.path.exists(path)): return messagebox.showerror("Erreur", "Le chemin de fichier est invalide")
|
path = entry_game_path.get()
|
||||||
extension = path.split(".")[-1]
|
if not(os.path.exists(path)):
|
||||||
if extension.upper() == "DOL":
|
messagebox.showerror("Erreur", "Le chemin de fichier est invalide")
|
||||||
if messagebox.askyesno("Attention", "Ce dossier sera écrasé si vous installer le mod !\n" +\
|
return
|
||||||
"Êtes-vous sûr de vouloir l'utiliser ?"):
|
|
||||||
self.path_mkwf = os.path.realpath(path + "/../../")
|
|
||||||
elif extension.upper() in ["ISO", "WBFS", "WIA", "CSIO"]:
|
|
||||||
self.path_mkwf, i = os.path.realpath(path + "/../MKWiiFaraphel"), 1
|
|
||||||
|
|
||||||
while True:
|
extension = get_extension(path)
|
||||||
if not(os.path.exists(self.path_mkwf)): break
|
if extension.upper() == "DOL":
|
||||||
self.path_mkwf, i = os.path.realpath(path + f"/../MKWiiFaraphel ({i})"), i+1
|
if messagebox.askyesno("Attention", "Ce dossier sera écrasé si vous installer le mod !\n" +\
|
||||||
subprocess.call(["./tools/wit/wit", "EXTRACT", path, "-d", self.path_mkwf])
|
"Êtes-vous sûr de vouloir l'utiliser ?"):
|
||||||
|
self.path_mkwf = os.path.realpath(path + "/../../")
|
||||||
|
elif extension.upper() in ["ISO", "WBFS", "WIA", "CSIO"]:
|
||||||
|
self.path_mkwf, i = os.path.realpath(path + "/../MKWiiFaraphel"), 1
|
||||||
|
|
||||||
else: return messagebox.showerror("Erreur", "Le type de fichier n'est pas reconnu")
|
while True:
|
||||||
|
if not(os.path.exists(self.path_mkwf)): break
|
||||||
|
self.path_mkwf, i = os.path.realpath(path + f"/../MKWiiFaraphel ({i})"), i+1
|
||||||
|
|
||||||
if os.path.exists(self.path_mkwf + "/files/rel/lecode-PAL.bin"):
|
self.Progress(show=True, indeter=True, statut="Extraction du jeu...")
|
||||||
messagebox.showwarning("Attention", "Cette ROM est déjà moddé,"+\
|
subprocess.call(["./tools/wit/wit", "EXTRACT", path, "-d", self.path_mkwf])
|
||||||
"il est déconseillé de l'utiliser pour installer le mod")
|
self.Progress(show=False)
|
||||||
|
|
||||||
self.frame_action.grid(row=2, column=1,sticky="NEWS")
|
else:
|
||||||
|
messagebox.showerror("Erreur", "Le type de fichier n'est pas reconnu")
|
||||||
|
self.Progress(show=False)
|
||||||
|
return
|
||||||
|
|
||||||
Button(self.frame_game_path, text="Extraire le fichier", relief=RIDGE, command=use_path)\
|
if os.path.exists(self.path_mkwf + "/files/rel/lecode-PAL.bin"):
|
||||||
.grid(row=2,column=1,columnspan=2,sticky="NEWS")
|
messagebox.showwarning("Attention", "Cette ROM est déjà moddé,"+\
|
||||||
|
"il est déconseillé de l'utiliser pour installer le mod")
|
||||||
|
|
||||||
|
self.frame_action.grid(row=2, column=1,sticky="NEWS")
|
||||||
|
self.Progress(show=False)
|
||||||
|
|
||||||
|
|
||||||
|
t=Thread(target=func)
|
||||||
|
t.setDaemon(True)
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
|
||||||
|
self.button_game_extract = Button(self.frame_game_path, text="Extraire le fichier", relief=RIDGE, command=use_path)
|
||||||
|
self.button_game_extract.grid(row=2,column=1,columnspan=2,sticky="NEWS")
|
||||||
|
|
||||||
self.frame_action = LabelFrame(self.root, text="Action")
|
self.frame_action = LabelFrame(self.root, text="Action")
|
||||||
|
|
||||||
Button(self.frame_action, text="Installer le mod", relief=RIDGE, command=self.install_mod, width=45
|
self.button_prepare_file = Button(self.frame_action, text="Preparer les fichiers", relief=RIDGE, command=self.patch_file, width=45)
|
||||||
).grid(row=1,column=1,sticky="NEWS")
|
self.button_prepare_file.grid(row=1, column=1, sticky="NEWS")
|
||||||
|
self.button_install_mod = Button(self.frame_action, text="Installer le mod", relief=RIDGE, command=self.install_mod, width=45)
|
||||||
|
# Le boutton d'installation du mod n'est affiché qu'après avoir préparer les fichiers
|
||||||
|
|
||||||
|
self.progressbar = ttk.Progressbar(self.root)
|
||||||
|
self.progresslabel = Label(self.root)
|
||||||
|
|
||||||
|
|
||||||
|
def Progress(self, show=None, indeter=None, step=None, statut=None, max=None, add=None):
|
||||||
|
if indeter == True:
|
||||||
|
self.progressbar.config(mode="indeterminate")
|
||||||
|
self.progressbar.start(50)
|
||||||
|
elif indeter == False: self.progressbar.config(mode="determinate")
|
||||||
|
if show == True:
|
||||||
|
self.StateButton(enable=False)
|
||||||
|
self.progressbar.grid(row=100, column=1, sticky="NEWS")
|
||||||
|
self.progresslabel.grid(row=101, column=1, sticky="NEWS")
|
||||||
|
|
||||||
|
elif show == False:
|
||||||
|
self.StateButton(enable=True)
|
||||||
|
self.progressbar.grid_forget()
|
||||||
|
self.progresslabel.grid_forget()
|
||||||
|
|
||||||
|
if statut: self.progresslabel.config(text=statut)
|
||||||
|
if step: self.progressbar["value"] = step
|
||||||
|
if max:
|
||||||
|
self.progressbar["maximum"] = max
|
||||||
|
self.progressbar["value"] = 0
|
||||||
|
if add: self.progressbar.step(add)
|
||||||
|
|
||||||
|
|
||||||
|
def StateButton(self, enable=True):
|
||||||
|
button = [
|
||||||
|
self.button_game_extract,
|
||||||
|
self.button_install_mod,
|
||||||
|
self.button_prepare_file
|
||||||
|
]
|
||||||
|
for widget in button:
|
||||||
|
if enable: widget.config(state=NORMAL)
|
||||||
|
else: widget.config(state=DISABLED)
|
||||||
|
|
||||||
|
|
||||||
def patch_file(self):
|
def patch_file(self):
|
||||||
with open("./convert_file.json") as f: fc = json.load(f)
|
def func():
|
||||||
for file in fc["img"]:
|
if os.path.exists("./file/Track-WU8/"): total_track = len(os.listdir("./file/Track-WU8/"))
|
||||||
print(get_filename(file))
|
else: total_track = 0
|
||||||
if not(os.path.exists("./file/"+get_filename(file))):
|
with open("./convert_file.json") as f: fc = json.load(f)
|
||||||
subprocess.call(["./tools/szs/wimgt", "ENCODE", "./file/"+file, "-x", fc["img"][file]])
|
max_step = len(fc["img"])+len(fc["bmg"])+total_track
|
||||||
|
self.Progress(show=True, indeter=False, statut="Conversion des fichiers", max=max_step, step=0)
|
||||||
|
|
||||||
for file in fc["bmg"]:
|
for i, file in enumerate(fc["img"]):
|
||||||
if not(os.path.exists("./file/"+get_filename(file)+".bmg")):
|
self.Progress(statut=f"Conversion des images\n({i+1}/{len(fc['img'])}) {file}", add=1)
|
||||||
subprocess.call(["./tools/szs/wbmgt", "ENCODE", "./file/"+file])
|
if not(os.path.exists("./file/"+get_filename(file))):
|
||||||
|
subprocess.call(["./tools/szs/wimgt", "ENCODE", "./file/"+file, "-x", fc["img"][file]])
|
||||||
|
|
||||||
if os.path.exists("./file/Track-WU8/"):
|
for i, file in enumerate(fc["bmg"]):
|
||||||
subprocess.call(["./tools/szs/wszst", "NORMALIZE", "./file/Track-WU8/*.wu8", "-d", "./file/Track/%N.szs", "--szs",
|
self.Progress(statut=f"Conversion des textes\n({i+1}/{len(fc['bmg'])}) {file}", add=1)
|
||||||
"--overwrite", "--autoadd-path", self.path_mkwf+"/files/Race/Course/"])
|
if not(os.path.exists("./file/"+get_filename(file)+".bmg")):
|
||||||
shutil.rmtree("./file/Track-WU8/")
|
subprocess.call(["./tools/szs/wbmgt", "ENCODE", "./file/"+file])
|
||||||
|
|
||||||
|
if os.path.exists("./file/Track-WU8/"):
|
||||||
|
for i, file in enumerate(os.listdir("./file/Track-WU8/")):
|
||||||
|
self.Progress(statut=f"Conversion des textes\n({i+1}/{total_track}) {file}", add=1)
|
||||||
|
subprocess.call(["./tools/szs/wszst", "NORMALIZE", "./file/Track-WU8/"+file, "-d", "./file/Track/%N.szs",
|
||||||
|
"--szs", "--overwrite"])
|
||||||
|
shutil.rmtree("./file/Track-WU8/")
|
||||||
|
|
||||||
|
self.Progress(show=False)
|
||||||
|
self.button_install_mod.grid(row=2,column=1,sticky="NEWS")
|
||||||
|
|
||||||
|
t=Thread(target=func)
|
||||||
|
t.setDaemon(True)
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
|
||||||
def install_mod(self):
|
def install_mod(self):
|
||||||
self.patch_file()
|
def func():
|
||||||
|
with open("./fs.json") as f: fs = json.load(f)
|
||||||
|
|
||||||
with open("./fs.json") as f: fs = json.load(f)
|
### This part is used to estimate the max_step
|
||||||
extracted_file = []
|
extracted_file = []
|
||||||
|
max_step, step = 0, 0
|
||||||
|
|
||||||
def replace_file(path, file, subpath="/"):
|
def count_rf(path, file, subpath="/"):
|
||||||
print(path, subpath, file)
|
max_step += 1
|
||||||
extension = path.split(".")[-1]
|
extension = get_extension(path)
|
||||||
|
if extension == "szs":
|
||||||
|
if not(os.path.realpath(path) in extracted_file):
|
||||||
|
extracted_file.append(os.path.realpath(path))
|
||||||
|
max_step += 1
|
||||||
|
|
||||||
if extension == "szs":
|
for fp in fs:
|
||||||
if not(os.path.realpath(path) in extracted_file):
|
for f in glob.glob(self.path_mkwf + "/files/" + fp, recursive=True):
|
||||||
subprocess.call(["./tools/szs/wszst", "EXTRACT", path, "-d", path+".d", "--overwrite"])
|
if type(fs[fp]) == str: count_rf(path=f, file=fs[fp])
|
||||||
extracted_file.append(os.path.realpath(path))
|
elif type(fs[fp]) == dict:
|
||||||
|
for nf in fs[fp]:
|
||||||
szs_extract_path = path+".d"
|
if type(fs[fp][nf]) == str: count_rf(path=f, subpath=nf, file=fs[fp][nf])
|
||||||
if os.path.exists(szs_extract_path+subpath):
|
elif type(fs[fp][nf]) == list:
|
||||||
if subpath[-1] == "/": filecopy(f"./file/{file}", szs_extract_path+subpath+file)
|
for ffp in fs[fp][nf]: count_rf(path=f, subpath=nf, file=ffp)
|
||||||
else: filecopy(f"./file/{file}", szs_extract_path+subpath)
|
###
|
||||||
|
extracted_file = []
|
||||||
elif path[-1] == "/": filecopy(f"./file/{file}", path+file)
|
max_step += 2 # PATCH main.dol et PATCH lecode.bin
|
||||||
else: filecopy(f"./file/{file}", path)
|
self.Progress(show=True, indeter=False, statut="Installation du mod", max=max_step, step=0)
|
||||||
|
|
||||||
for fp in fs:
|
|
||||||
for f in glob.glob(self.path_mkwf + "/files/" + fp, recursive=True):
|
|
||||||
if type(fs[fp]) == str: replace_file(path=f, file=fs[fp])
|
|
||||||
elif type(fs[fp]) == dict:
|
|
||||||
for nf in fs[fp]:
|
|
||||||
if type(fs[fp][nf]) == str: replace_file(path=f, subpath=nf, file=fs[fp][nf])
|
|
||||||
elif type(fs[fp][nf]) == list:
|
|
||||||
for ffp in fs[fp][nf]: replace_file(path=f, subpath=nf, file=ffp)
|
|
||||||
|
|
||||||
|
|
||||||
print(extracted_file)
|
|
||||||
for file in extracted_file:
|
|
||||||
subprocess.call(["./tools/szs/wszst", "CREATE", file+".d", "-d", file, "--overwrite"])
|
|
||||||
if os.path.exists(file+".d"): shutil.rmtree(file+".d")
|
|
||||||
|
|
||||||
subprocess.call(["./tools/szs/wstrt", "patch", self.path_mkwf+"/sys/main.dol", "--clean-dol", "--add-lecode"])
|
def replace_file(path, file, subpath="/"):
|
||||||
subprocess.call(
|
self.Progress(statut=f"Modification de {get_nodir(path)+subpath+file}", add=1)
|
||||||
["./tools/szs/wlect", "patch", "./file/lecode-PAL.bin", "-od", self.path_mkwf+"/files/rel/lecode-PAL.bin",
|
print(path, subpath, file)
|
||||||
"--track-dir", self.path_mkwf+"/files/Race/Course/", "--copy-tracks", "./file/Track/",
|
extension = get_extension(path)
|
||||||
"--move-tracks", self.path_mkwf+"/files/Race/Course/", "--le-define",
|
|
||||||
"./file/CTFILE.txt", "--lpar", "./file/lpar-default.txt", "--overwrite"])
|
|
||||||
|
|
||||||
messagebox.showinfo("", "L'installation est terminé !")
|
if extension == "szs":
|
||||||
|
if not(os.path.realpath(path) in extracted_file):
|
||||||
|
subprocess.call(["./tools/szs/wszst", "EXTRACT", path, "-d", path+".d", "--overwrite"])
|
||||||
|
extracted_file.append(os.path.realpath(path))
|
||||||
|
|
||||||
|
szs_extract_path = path+".d"
|
||||||
|
if os.path.exists(szs_extract_path+subpath):
|
||||||
|
if subpath[-1] == "/": filecopy(f"./file/{file}", szs_extract_path+subpath+file)
|
||||||
|
else: filecopy(f"./file/{file}", szs_extract_path+subpath)
|
||||||
|
|
||||||
|
elif path[-1] == "/": filecopy(f"./file/{file}", path+file)
|
||||||
|
else: filecopy(f"./file/{file}", path)
|
||||||
|
|
||||||
|
for fp in fs:
|
||||||
|
for f in glob.glob(self.path_mkwf + "/files/" + fp, recursive=True):
|
||||||
|
if type(fs[fp]) == str: replace_file(path=f, file=fs[fp])
|
||||||
|
elif type(fs[fp]) == dict:
|
||||||
|
for nf in fs[fp]:
|
||||||
|
if type(fs[fp][nf]) == str: replace_file(path=f, subpath=nf, file=fs[fp][nf])
|
||||||
|
elif type(fs[fp][nf]) == list:
|
||||||
|
for ffp in fs[fp][nf]: replace_file(path=f, subpath=nf, file=ffp)
|
||||||
|
|
||||||
|
|
||||||
|
for file in extracted_file:
|
||||||
|
self.Progress(statut=f"Recompilation de {file}", add=1)
|
||||||
|
subprocess.call(["./tools/szs/wszst", "CREATE", file+".d", "-d", file, "--overwrite"])
|
||||||
|
if os.path.exists(file+".d"): shutil.rmtree(file+".d")
|
||||||
|
|
||||||
|
self.Progress(statut=f"Patch main.dol", add=1)
|
||||||
|
subprocess.call(["./tools/szs/wstrt", "patch", self.path_mkwf+"/sys/main.dol", "--clean-dol", "--add-lecode"])
|
||||||
|
self.Progress(statut=f"Patch lecode-PAL.bin", add=1)
|
||||||
|
subprocess.call(
|
||||||
|
["./tools/szs/wlect", "patch", "./file/lecode-PAL.bin", "-od", self.path_mkwf+"/files/rel/lecode-PAL.bin",
|
||||||
|
"--track-dir", self.path_mkwf+"/files/Race/Course/", "--copy-tracks", "./file/Track/",
|
||||||
|
"--move-tracks", self.path_mkwf+"/files/Race/Course/", "--le-define",
|
||||||
|
"./file/CTFILE.txt", "--lpar", "./file/lpar-default.txt", "--overwrite"])
|
||||||
|
|
||||||
|
self.Progress(show=False)
|
||||||
|
messagebox.showinfo("", "L'installation est terminé !")
|
||||||
|
|
||||||
|
t = Thread(target=func)
|
||||||
|
t.setDaemon(True)
|
||||||
|
t.start()
|
||||||
|
|
||||||
# TODO: Langue
|
# TODO: Langue
|
||||||
# TODO: Icones
|
# TODO: Icones
|
||||||
# TODO: Update
|
# TODO: Update
|
||||||
# TODO: Progress bar
|
# TODO: Progress bar
|
||||||
# TODO: Changer l'ID
|
# TODO: Changer l'ID
|
||||||
|
# TODO: Convertir en ISO / WBFS... après l'installation
|
||||||
App = ClassApp()
|
App = ClassApp()
|
||||||
mainloop()
|
mainloop()
|
Loading…
Reference in a new issue