From ff2296c7865d25e71965d9baab2b9b474c8a5784 Mon Sep 17 00:00:00 2001 From: netkas Date: Fri, 27 Sep 2024 13:18:53 -0400 Subject: [PATCH] Fix configuration path resolution and add setup script --- CHANGELOG.md | 9 +++++ project.json | 16 ++++++++- setup | 14 ++++++++ src/ConfigLib/Configuration.php | 58 ++++++++++++++++++++++++++++++++- 4 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 setup diff --git a/CHANGELOG.md b/CHANGELOG.md index dd8cb07..02d7f1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.1.2] - 2024-09-27 + +This update fixes a critical bug where configuration files may not be found when using different user accounts, +especially when the configuration file is located in a directory that is not accessible by the user account running the +application. This was fixed by changing the way the configuration file path is resolved including by adding a setup +execution unit that will be executed post-installation to ensure that the configuration file is accessible by the user +account running the application. + + ## [1.1.1] - 2024-09-26 This update introduces a minor bug fix diff --git a/project.json b/project.json index 5424afe..c1797c0 100644 --- a/project.json +++ b/project.json @@ -27,15 +27,29 @@ "working_directory": "%CWD%", "tty": true } + }, + { + "name": "setup", + "runner": "php", + "execute": { + "target": "setup", + "working_directory": "%CWD%", + "tty": true + } } ], + "installer": { + "post_install": [ + "setup" + ] + }, "assembly": { "name": "ConfigLib", "package": "net.nosial.configlib", "company": "Nosial", "copyright": "Copyright (c) 2022-2023 Nosial", "description": "ConfigLib is a library for reading and writing configuration files via the NCC Runtime API", - "version": "1.1.1", + "version": "1.1.2", "uuid": "9347259e-8e4d-11ed-85a7-fd07cf28ef35" }, "build": { diff --git a/setup b/setup new file mode 100644 index 0000000..7c6b690 --- /dev/null +++ b/setup @@ -0,0 +1,14 @@ +path = $globalDir . DIRECTORY_SEPARATOR . $name . '.conf'; + } + if ($this->path === null) { - $filePath = $name . '.conf'; if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $configDir = getenv('APPDATA') ?: getenv('LOCALAPPDATA'); @@ -514,4 +520,54 @@ $fs->dumpFile($path, $this->toYaml()); $fs->chmod($path, 0777); } + + /** + * Retrieves the global directory path for configuration files. + * + * @return string The global directory path for configuration files. + */ + public static function getGlobalDirectory(): string + { + $path = DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'configlib'; + + if(file_exists($path) && is_writable($path)) + { + return $path; + } + + if((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')) + { + $variables = [ + 'SYSTEMDRIVE', + 'CSIDL_APPDATA', + 'CSIDL_PROGRAM_FILES' + ]; + + foreach($variables as $variable) + { + $environment_variable = getenv($variable); + if($environment_variable) + { + return $environment_variable . DIRECTORY_SEPARATOR . 'configlib'; + } + } + } + else + { + $variables = [ + 'HOME', + 'XDG_CONFIG_HOME', + 'XDG_DATA_HOME' + ]; + + foreach($variables as $variable) + { + $environment_variable = getenv($variable); + if($environment_variable) + { + return $environment_variable . DIRECTORY_SEPARATOR . 'configlib'; + } + } + } + } } \ No newline at end of file