From 5284cad0c7c8e41cfcf7a299437780e1eaa3619d Mon Sep 17 00:00:00 2001 From: Mauco03 <marco.gaibotti@skywarder.eu> Date: Thu, 14 Nov 2024 13:47:54 +0100 Subject: [PATCH] [design-updates] Added possibility of loading Settings from file --- classes/Settings.m | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/classes/Settings.m b/classes/Settings.m index 9afdc2c..47da9c6 100644 --- a/classes/Settings.m +++ b/classes/Settings.m @@ -8,8 +8,11 @@ classdef Settings < Config & dynamicprops % Loaded config: - % Loaded data: - % Arguments: -% - configNames: config file names. Accepts shortened version -% e.g: ode -> odeConfig.m +% - configNames: config file names or path. +% Accepts shortened version, e.g: ode -> odeConfig.m +% +% If config name is provided, Settings checks inside the settings +% folder or inside the caller's folder properties(Access = protected) configPath = '' @@ -22,7 +25,7 @@ classdef Settings < Config & dynamicprops arguments (Input, Repeating) configNames char end - + configNames = string(configNames); noConfig = ~endsWith(configNames, ["Config.m", "Config"]); @@ -51,7 +54,12 @@ classdef Settings < Config & dynamicprops outputVariables = struct(); for i = 1:length(configNames) fileName = configNames{i}; - filePath = fullfile(fileparts(mfilename("fullpath")), '..', 'settings'); + filePath = ''; + + if ~isfile(fileName) + filePath = trimPath( ... + fullfile(fileparts(mfilename("fullpath")), '..', 'settings')); + end if ~isfile(fullfile(filePath, fileName)) % Get caller function path callers = dbstack("-completenames"); @@ -61,9 +69,9 @@ classdef Settings < Config & dynamicprops end if ~isfile(fullfile(filePath, fileName)) - error(['File not found inside the settings folder, nor in local folder: %s\n' ... - 'Check that the correct mission is set in your component ' ... - 'and the config file exists'], fileName); + error(['File not found inside the target folder: %s, at\n' ... + '%s\n' ... + 'Check that the config file exists'], fileName, filePath); end variables = [who(); "variables"]; -- GitLab