fix: update debug file paths to use Unix-style separators and improve logger initialization error handling

This commit is contained in:
jtalborough
2025-02-26 11:28:00 -05:00
parent 3160969786
commit ae47edcab6
2 changed files with 31 additions and 15 deletions

View File

@@ -64,13 +64,13 @@ namespace PepperDash.Core
/// Describes the folder location where a given program stores it's debug level memory. By default, the /// Describes the folder location where a given program stores it's debug level memory. By default, the
/// file written will be named appNdebug where N is 1-10. /// file written will be named appNdebug where N is 1-10.
/// </summary> /// </summary>
public static string OldFilePathPrefix = @"\nvram\debug\"; public static string OldFilePathPrefix = "/nvram/debug/";
/// <summary> /// <summary>
/// Describes the new folder location where a given program stores it's debug level memory. By default, the /// Describes the new folder location where a given program stores it's debug level memory. By default, the
/// file written will be named appNdebug where N is 1-10. /// file written will be named appNdebug where N is 1-10.
/// </summary> /// </summary>
public static string NewFilePathPrefix = @"\user\debug\"; public static string NewFilePathPrefix = "/user/debug/";
/// <summary> /// <summary>
/// The name of the file containing the current debug settings. /// The name of the file containing the current debug settings.
@@ -823,8 +823,7 @@ namespace PepperDash.Core
{ {
if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance) if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance)
{ {
// Make sure the path starts with a slash to make it absolute return "/user/debugSettings/program" + InitialParametersClass.ApplicationNumber;
return String.Format("/user/debugSettings/program{0}", InitialParametersClass.ApplicationNumber);
} }
return string.Format("{0}{1}user{1}debugSettings{1}{2}.json", return string.Format("{0}{1}user{1}debugSettings{1}{2}.json",
@@ -833,41 +832,42 @@ namespace PepperDash.Core
private static void CheckForMigration() private static void CheckForMigration()
{ {
var oldFilePath = String.Format(@"\nvram\debugSettings\program{0}", InitialParametersClass.ApplicationNumber); var oldFilePath = String.Format("/nvram/debugSettings/program{0}", InitialParametersClass.ApplicationNumber);
var newFilePath = String.Format(@"\user\debugSettings\program{0}", InitialParametersClass.ApplicationNumber); var newFilePath = String.Format("/user/debugSettings/program{0}", InitialParametersClass.ApplicationNumber);
//check for file at old path //check for file at old path
if (!File.Exists(oldFilePath)) if (!File.Exists(oldFilePath))
{ {
Console(0, ErrorLogLevel.Notice, Console(0, ErrorLogLevel.Notice,
String.Format( String.Format(
@"Debug settings file migration not necessary. Using file at \user\debugSettings\program{0}", "Debug settings file migration not necessary. Using file at /user/debugSettings/program{0}",
InitialParametersClass.ApplicationNumber)); InitialParametersClass.ApplicationNumber));
return; return;
} }
//create the new directory if it doesn't already exist //create the new directory if it doesn't already exist
if (!Directory.Exists(@"\user\debugSettings")) if (!Directory.Exists("/user/debugSettings"))
{ {
Directory.CreateDirectory(@"\user\debugSettings"); Directory.CreateDirectory("/user/debugSettings");
} }
Console(0, ErrorLogLevel.Notice, Console(0, ErrorLogLevel.Notice,
String.Format( String.Format(
@"File found at \nvram\debugSettings\program{0}. Migrating to \user\debugSettings\program{0}", InitialParametersClass.ApplicationNumber)); "File found at /nvram/debugSettings/program{0}. Migrating to /user/debugSettings/program{0}",
InitialParametersClass.ApplicationNumber));
//Copy file from old path to new path, then delete it. This will overwrite the existing file //Copy file from old path to new path, then delete it. This will overwrite the existing file
File.Copy(oldFilePath, newFilePath, true); File.Copy(oldFilePath, newFilePath, true);
File.Delete(oldFilePath); File.Delete(oldFilePath);
//Check if the old directory is empty, then delete it if it is //Check if the old directory is empty, then delete it if it is
if (Directory.GetFiles(@"\nvram\debugSettings").Length > 0) if (Directory.GetFiles("/nvram/debugSettings").Length > 0)
{ {
return; return;
} }
Directory.Delete(@"\nvram\debugSettings"); Directory.Delete("/nvram/debugSettings");
} }
/// <summary> /// <summary>

View File

@@ -2,6 +2,7 @@
using Crestron.SimplSharp.CrestronLogger; using Crestron.SimplSharp.CrestronLogger;
using Serilog.Core; using Serilog.Core;
using Serilog.Events; using Serilog.Events;
using System; // Add this for Exception class
namespace PepperDash.Core.Logging namespace PepperDash.Core.Logging
{ {
@@ -23,7 +24,22 @@ namespace PepperDash.Core.Logging
public DebugCrestronLoggerSink() public DebugCrestronLoggerSink()
{ {
CrestronLogger.Initialize(1, LoggerModeEnum.RM); try
{
// The Crestron SDK appears to be using Windows-style paths internally
// We'll wrap this in a try/catch to handle path errors
CrestronLogger.Initialize(1, LoggerModeEnum.DEFAULT);
}
catch (Crestron.SimplSharp.CrestronIO.InvalidDirectoryLocationException ex)
{
// Log the error but allow the application to continue without the RM logger
CrestronConsole.PrintLine("Error initializing CrestronLogger in RM mode: {0}", ex.Message);
// Just report the error and continue - don't try to use other logger modes
// since LoggerModeEnum doesn't have a Default value
CrestronConsole.PrintLine("CrestronLogger will not be available");
}
} }
} }
} }