From 4a19aff2060a79b9de30c1125b13064bf394ef55 Mon Sep 17 00:00:00 2001 From: Faraphel Date: Tue, 30 Aug 2022 15:30:38 +0200 Subject: [PATCH] added linux only check for sudo usage and write / execution permissions for the installer folder itself --- assets/language/en.json | 4 +++- assets/language/fr.json | 4 +++- source/__init__.py | 3 +++ source/gui/install.py | 10 ++++++++++ source/wt/__init__.py | 3 +-- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/assets/language/en.json b/assets/language/en.json index 302c452..13cdf37 100644 --- a/assets/language/en.json +++ b/assets/language/en.json @@ -115,6 +115,8 @@ "CONVERTING_TO_RIIVOLUTION": "Converting to Riivolution patch", "PATCHS": "patchs", "PRE-PATCHS": "pre-patchs", - "CALCULATING_HASH_FOR": "Calculating hash for" + "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 ?" } } \ No newline at end of file diff --git a/assets/language/fr.json b/assets/language/fr.json index 021655f..78d61e9 100644 --- a/assets/language/fr.json +++ b/assets/language/fr.json @@ -116,6 +116,8 @@ "CONVERTING_TO_RIIVOLUTION": "Conversion en patch Riivolution", "PATCHS": "patchs", "PRE-PATCHS": "pre-patchs", - "CALCULATING_HASH_FOR": "Calcule du hash pour" + "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 ?" } } \ No newline at end of file diff --git a/source/__init__.py b/source/__init__.py index b8e063e..60d2c36 100644 --- a/source/__init__.py +++ b/source/__init__.py @@ -4,6 +4,8 @@ __author__ = 'Faraphel' # external links +import os + discord_url = "https://discord.gg/HEYW5v8ZCd" github_wiki_url = "https://github.com/Faraphel/MKWF-Install/wiki/help" readthedocs_url = "https://mkwf-install.readthedocs.io/" @@ -17,6 +19,7 @@ Go: int = 1_000 * Mo minimum_space_available: int = 15*Go file_block_size: int = 128*Ko +system = "win64" if os.name == "nt" else "lin64" # global type hint TemplateSafeEval: str diff --git a/source/gui/install.py b/source/gui/install.py index 6fd5dee..ed37fcb 100644 --- a/source/gui/install.py +++ b/source/gui/install.py @@ -379,6 +379,16 @@ class ButtonInstall(ttk.Button): if not messagebox.askokcancel(_("WARNING"), _("WARNING_LOW_SPACE_CONTINUE")): return + if system == "lin64": # if linux + if os.getuid() != 0: # if the user is not root + if not messagebox.askokcancel(_("WARNING"), _("WARNING_NOT_ROOT")): + return + + if not os.access("./", os.W_OK | os.X_OK): + # check if writing (for the /.cache/) and execution (for /tools/) are allowed + if not messagebox.askokcancel(_("WARNING"), _("WARNING_INSTALLER_PERMISSION")): + return + game = Game(source_path) output_type = Extension[self.root.options.extension.get()] diff --git a/source/wt/__init__.py b/source/wt/__init__.py index 215c460..2d749b7 100644 --- a/source/wt/__init__.py +++ b/source/wt/__init__.py @@ -1,13 +1,12 @@ import subprocess from pathlib import Path -import os from typing import Callable +from source import system from source.translation import translate as _ tools_dir: Path = Path("./tools/") -system = "win64" if os.name == "nt" else "lin64" subprocess_kwargs = {"creationflags": subprocess.CREATE_NO_WINDOW} if system == "win64" else {} # creationflags are Windows specific. Linux don't show any subprocess window per default.