From 0da8428eef82d0030c4ec7fd3d2db079a77f752d Mon Sep 17 00:00:00 2001 From: James David Clarke Date: Wed, 10 Jan 2024 08:36:48 +0000 Subject: [PATCH] Made minetest directory handling, platform indiependent --- tools/libtextureconverter/config.py | 23 ++++++++++++++++++++++- tools/libtextureconverter/gui.py | 2 +- tools/libtextureconverter/utils.py | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/tools/libtextureconverter/config.py b/tools/libtextureconverter/config.py index 25b6c1be8..dbba6b3df 100644 --- a/tools/libtextureconverter/config.py +++ b/tools/libtextureconverter/config.py @@ -1,9 +1,30 @@ import os +import platform + +def get_minetest_directory(): + system = platform.system() + + # Windows + if system == 'Windows': + return os.environ.get('MINETEST_USER_PATH', os.path.expandvars('%APPDATA%\\Minetest')) + + # Linux + elif system == 'Linux': + return os.environ.get('MINETEST_USER_PATH', os.path.expanduser('~/.minetest')) + + # macOS + elif system == 'Darwin': # Darwin is the system name for macOS + return os.environ.get('MINETEST_USER_PATH', os.path.expanduser('~/Library/Application Support/minetest')) + + # Unsupported system + else: + return None + # Constants SUPPORTED_MINECRAFT_VERSION = "1.20" # Helper vars home = os.environ["HOME"] -mineclone2_path = home + "/.minetest/games/mineclone2" +mineclone2_path = os.path.join(get_minetest_directory(),"games","mineclone2") working_dir = os.getcwd() appname = "Texture_Converter.py" diff --git a/tools/libtextureconverter/gui.py b/tools/libtextureconverter/gui.py index 9afa15667..6c2a0ed6b 100644 --- a/tools/libtextureconverter/gui.py +++ b/tools/libtextureconverter/gui.py @@ -130,7 +130,7 @@ class TextureConverterGUI: pixelsize = None dry_run = False verbose = False - output_dir = os.path.join(home, ".minetest", "textures") + output_dir = os.path.join(get_minetest_directory(), "textures") make_texture_pack = True # Determine the resource packs to convert based on the option diff --git a/tools/libtextureconverter/utils.py b/tools/libtextureconverter/utils.py index 7f9bdb390..7d9cce7f1 100644 --- a/tools/libtextureconverter/utils.py +++ b/tools/libtextureconverter/utils.py @@ -10,7 +10,7 @@ import zipfile from .config import SUPPORTED_MINECRAFT_VERSION, home from PIL import Image from collections import Counter - +import platform def detect_pixel_size(directory): sizes = []