diff --git a/PepperDashEssentials/Config/ConfigReader.cs b/PepperDashEssentials/Config/ConfigReader.cs index 5c517a13..158bd679 100644 --- a/PepperDashEssentials/Config/ConfigReader.cs +++ b/PepperDashEssentials/Config/ConfigReader.cs @@ -22,38 +22,73 @@ namespace PepperDash.Essentials Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loading unmerged system/template portal configuration file."); try { - var filePath = Global.FilePathPrefix + "configurationFile.json"; + // Check for local config file first + var filePath = Global.FilePathPrefix + ConfigWriter.LocalConfigFolder + Global.DirectorySeparator + "configurationFile.json"; + + bool localConfigFound = false; - Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to load config file: '{0}'", filePath); + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to load Local config file: '{0}'", filePath); + + // Check for local config directory first + if (Directory.Exists(Global.FilePathPrefix + ConfigWriter.LocalConfigFolder)) + { + if (!File.Exists(filePath)) + { + Debug.Console(0, Debug.ErrorLogLevel.Notice, + "Local Configuration file not present.", filePath); + } + else + localConfigFound = true; + } + + // Check for Portal Config + if(!localConfigFound) + { + filePath = Global.FilePathPrefix + "configurationFile.json"; + + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to load Portal config file: '{0}'", filePath); + + if (!File.Exists(filePath)) + { + Debug.Console(0, Debug.ErrorLogLevel.Notice, + "ERROR: Local Configuration file not present. Please load file to {0} and reset program", filePath); + return false; + } + } - if (!File.Exists(filePath)) - { - Debug.Console(0, Debug.ErrorLogLevel.Error, - "ERROR: Configuration file not present. Please load file to {0} and reset program", filePath); - return false; - } - - using (StreamReader fs = new StreamReader(filePath)) - { - var doubleObj = JObject.Parse(fs.ReadToEnd()); - ConfigObject = MergeConfigs(doubleObj).ToObject(); - - // Extract SystemUrl and TemplateUrl into final config output - - if (doubleObj["system_url"] != null) - { - ConfigObject.SystemUrl = doubleObj["system_url"].Value(); - } - - if (doubleObj["template_url"] != null) - { - ConfigObject.TemplateUrl= doubleObj["template_url"].Value(); - } - } - - Debug.Console(0, Debug.ErrorLogLevel.Notice, "Successfully Loaded Merged Config"); - - return true; + // Read the file + using (StreamReader fs = new StreamReader(filePath)) + { + if (localConfigFound) + { + ConfigObject = JObject.Parse(fs.ReadToEnd()).ToObject(); + + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Successfully Loaded Local Config"); + + return true; + } + else + { + var doubleObj = JObject.Parse(fs.ReadToEnd()); + ConfigObject = MergeConfigs(doubleObj).ToObject(); + + // Extract SystemUrl and TemplateUrl into final config output + + if (doubleObj["system_url"] != null) + { + ConfigObject.SystemUrl = doubleObj["system_url"].Value(); + } + + if (doubleObj["template_url"] != null) + { + ConfigObject.TemplateUrl = doubleObj["template_url"].Value(); + } + } + + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Successfully Loaded Merged Config"); + + return true; + } } catch (Exception e) { diff --git a/PepperDashEssentials/Config/ConfigWriter.cs b/PepperDashEssentials/Config/ConfigWriter.cs index 243bafce..f9830f8b 100644 --- a/PepperDashEssentials/Config/ConfigWriter.cs +++ b/PepperDashEssentials/Config/ConfigWriter.cs @@ -14,6 +14,7 @@ namespace PepperDash.Essentials { public class ConfigWriter { + public const string LocalConfigFolder = "LocalConfig"; public static bool WriteConfig() { @@ -24,7 +25,7 @@ namespace PepperDash.Essentials var fileLock = new CCriticalSection(); - var filePath = Global.FilePathPrefix + "LocalConfig" + Global.DirectorySeparator + "configurationFile.json"; + var filePath = Global.FilePathPrefix + LocalConfigFolder + Global.DirectorySeparator + "configurationFile.json"; Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to write config file: '{0}'", filePath); diff --git a/PepperDashEssentials/Room/Behaviours/RoomOnToDefaultSourceWhenOccupied.cs b/PepperDashEssentials/Room/Behaviours/RoomOnToDefaultSourceWhenOccupied.cs index e50309c2..05213622 100644 --- a/PepperDashEssentials/Room/Behaviours/RoomOnToDefaultSourceWhenOccupied.cs +++ b/PepperDashEssentials/Room/Behaviours/RoomOnToDefaultSourceWhenOccupied.cs @@ -169,7 +169,9 @@ namespace PepperDash.Essentials.Room.Behaviours if(Config.EnableRoomOnWhenOccupied) { - if (DateTime.Now.CompareTo(FeatureEnabledTime) > 0 && FeatureDisabledTime.CompareTo(DateTime.Now) >= 0) + Debug.Console(1, this, "Current Time: {0} \n FeatureEnabledTime: {1} \n FeatureDisabledTime: {2}", DateTime.Now, FeatureEnabledTime, FeatureDisabledTime); + + if (DateTime.Now.TimeOfDay.CompareTo(FeatureEnabledTime.TimeOfDay) >= 0 && FeatureDisabledTime.TimeOfDay.CompareTo(DateTime.Now.TimeOfDay) > 0) { if (SchedulerUtilities.CheckIfDayOfWeekMatchesRecurrenceDays(DateTime.Now, FeatureEnableEvent.Recurrence.RecurrenceDays)) {