From 6017c20aed97ce74e3ed913eebd0e0e00d0ca56f Mon Sep 17 00:00:00 2001 From: Faraphel Date: Tue, 30 Aug 2022 21:34:52 +0200 Subject: [PATCH] added a empty cache button in the advanced menu --- assets/language/en.json | 4 +++- assets/language/fr.json | 4 +++- source/gui/install.py | 9 +++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/assets/language/en.json b/assets/language/en.json index 13cdf37..29759e2 100644 --- a/assets/language/en.json +++ b/assets/language/en.json @@ -117,6 +117,8 @@ "PRE-PATCHS": "pre-patchs", "CALCULATING_HASH_FOR": "Calculating hash for", "WARNING_NOT_ROOT": "The application require root permission. You should start the application with 'sudo'. Continue anyway ?", - "WARNING_INSTALLER_PERMISSION": "The application need writing and execution permissions to its own files. You can use 'sudo chmod 777 -R ' to fix that. Continue anyway ?" + "WARNING_INSTALLER_PERMISSION": "The application need writing and execution permissions to its own files. You can use 'sudo chmod 777 -R ' to fix that. Continue anyway ?", + "WARNING_EMPTY_CACHE": "By emptying the cache, you will gain %.2fGB, but reinstalling a mod will be take way longer. Continue ?", + "EMPTY_CACHE": "Empty the cache" } } \ No newline at end of file diff --git a/assets/language/fr.json b/assets/language/fr.json index 78d61e9..9467e56 100644 --- a/assets/language/fr.json +++ b/assets/language/fr.json @@ -118,6 +118,8 @@ "PRE-PATCHS": "pre-patchs", "CALCULATING_HASH_FOR": "Calcule du hash pour", "WARNING_NOT_ROOT": "Cette application nécessite les permissions root. Vous devriez lancer l'application avec 'sudo'. Continuer quand même ?", - "WARNING_INSTALLER_PERMISSION": "Cette application nécessite les permissions d'écriture et d'exécution sur ses propres fichiers. Vous pouvez utiliser 'sudo chmod 777 -R ' pour corriger cela. Continuer quand même ?" + "WARNING_INSTALLER_PERMISSION": "Cette application nécessite les permissions d'écriture et d'exécution sur ses propres fichiers. Vous pouvez utiliser 'sudo chmod 777 -R ' pour corriger cela. Continuer quand même ?", + "WARNING_EMPTY_CACHE": "En vidant le cache, vous allez gagner %.2fGo, mais réinstaller un mod sera beaucoup plus long. Continuer ?", + "EMPTY_CACHE": "Vider le cache" } } \ No newline at end of file diff --git a/source/gui/install.py b/source/gui/install.py index ed37fcb..cc87e06 100644 --- a/source/gui/install.py +++ b/source/gui/install.py @@ -161,6 +161,7 @@ class Menu(tkinter.Menu): command=lambda: mystuff.Window(self.root.mod_config, self.root.options) ) self.threads_used = self.ThreadsUsed(self) + self.add_command(label=_("EMPTY_CACHE"), command=self.empty_cache) self.add_separator() @@ -171,6 +172,14 @@ class Menu(tkinter.Menu): command=lambda: self.root.options.developer_mode.set(self.variable_developer_mode.get()) ) + @staticmethod + def empty_cache(): + cache_path: Path = Path("./.cache/") + cache_size: int = sum(file.stat().st_size / Go for file in cache_path.rglob("*")) + + if messagebox.askokcancel(_("WARNING"), _("WARNING_EMPTY_CACHE") % cache_size): + shutil.rmtree("./.cache/", ignore_errors=True) + class ThreadsUsed(tkinter.Menu): def __init__(self, master: tkinter.Menu): super().__init__(master, tearoff=False)