From b09b22266b2c0035b898b866fa92452dda779d0e Mon Sep 17 00:00:00 2001 From: Drew Tingen Date: Wed, 30 Nov 2022 12:08:10 -0500 Subject: [PATCH] fix: Fixed CrestronRuntimeEnvironment uses in utils --- CHANGELOG.md | 1 + ICD.Common.Utils/IcdConsole.cs | 20 +++++++++++++------ ICD.Common.Utils/PathUtils.cs | 34 +++++++++++++++++--------------- ICD.Common.Utils/ProgramUtils.cs | 11 ++++++----- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc609aa..d878dcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Changed - IcdEnvironment - Added CrestronDevicePlatform, removed from CrestronRuntimeEnvironment, to support SimplWindows on VC-4 + - Fixed IcdEnvironment CrestronRuntimeEnvironment uses in IcdConsole, PathUtils, and ProgramUtils ## [16.0.5] 2022-07-11 ### Changed diff --git a/ICD.Common.Utils/IcdConsole.cs b/ICD.Common.Utils/IcdConsole.cs index 3e9d3f2..a3a6c06 100644 --- a/ICD.Common.Utils/IcdConsole.cs +++ b/ICD.Common.Utils/IcdConsole.cs @@ -94,13 +94,17 @@ namespace ICD.Common.Utils [PublicAPI] public static void ConsoleCommandResponse(string message, params object[] args) { + // No console in Server + if (IcdEnvironment.CrestronDevicePlatform == IcdEnvironment.eCrestronDevicePlatform.Server) + return; + if (args != null && args.Any()) message = string.Format(message, args); message = FixLineEndings(message); #if !NETSTANDARD - if (IcdEnvironment.CrestronRuntimeEnvironment == IcdEnvironment.eCrestronRuntimeEnvironment.Appliance) + if (IcdEnvironment.CrestronRuntimeEnvironment == IcdEnvironment.eCrestronRuntimeEnvironment.SimplSharpPro) { try { @@ -125,7 +129,7 @@ namespace ICD.Common.Utils try { #if !NETSTANDARD - if (IcdEnvironment.CrestronRuntimeEnvironment != IcdEnvironment.eCrestronRuntimeEnvironment.Server) + if (IcdEnvironment.CrestronDevicePlatform != IcdEnvironment.eCrestronDevicePlatform.Server) CrestronConsole.PrintLine(fixedMessage); #else Trace.WriteLine(AnsiUtils.StripAnsi(fixedMessage)); @@ -169,7 +173,7 @@ namespace ICD.Common.Utils try { #if !NETSTANDARD - if (IcdEnvironment.CrestronRuntimeEnvironment != IcdEnvironment.eCrestronRuntimeEnvironment.Server) + if (IcdEnvironment.CrestronDevicePlatform != IcdEnvironment.eCrestronDevicePlatform.Server) CrestronConsole.Print(fixedMessage); #else Trace.Write(AnsiUtils.StripAnsi(fixedMessage)); @@ -207,8 +211,8 @@ namespace ICD.Common.Utils public static bool SendControlSystemCommand(string command, ref string result) { #if !NETSTANDARD - // No console on VC4 - if (IcdEnvironment.CrestronRuntimeEnvironment == IcdEnvironment.eCrestronRuntimeEnvironment.Server) + // No console on Crestron Server + if (IcdEnvironment.CrestronDevicePlatform == IcdEnvironment.eCrestronDevicePlatform.Server) return false; return CrestronConsole.SendControlSystemCommand(command, ref result); @@ -221,7 +225,11 @@ namespace ICD.Common.Utils { #if !NETSTANDARD // Avoid crashing Simpl applications - if (IcdEnvironment.CrestronRuntimeEnvironment != IcdEnvironment.eCrestronRuntimeEnvironment.Appliance) + if (IcdEnvironment.CrestronRuntimeEnvironment != IcdEnvironment.eCrestronRuntimeEnvironment.SimplSharpPro) + return false; + + // No console in Crestron Server + if (IcdEnvironment.CrestronDevicePlatform == IcdEnvironment.eCrestronDevicePlatform.Server) return false; if (CrestronConsole.ConsoleRegistered) diff --git a/ICD.Common.Utils/PathUtils.cs b/ICD.Common.Utils/PathUtils.cs index 14efba4..cabc105 100644 --- a/ICD.Common.Utils/PathUtils.cs +++ b/ICD.Common.Utils/PathUtils.cs @@ -26,7 +26,7 @@ namespace ICD.Common.Utils public static string RootPath { get { - if (IcdEnvironment.CrestronRuntimeEnvironment == IcdEnvironment.eCrestronRuntimeEnvironment.Server) + if (IcdEnvironment.CrestronDevicePlatform == IcdEnvironment.eCrestronDevicePlatform.Server) return IcdDirectory.GetApplicationRootDirectory(); return IcdDirectory.GetDirectoryRoot(IcdPath.DirectorySeparatorChar.ToString()); @@ -63,13 +63,14 @@ namespace ICD.Common.Utils get { #if !NETSTANDARD - switch (IcdEnvironment.CrestronSeries) - { - case IcdEnvironment.eCrestronSeries.FourSeries: - return Join(RootPath, "user"); - default: - return Join(RootPath, "User"); - } + + // Server uses "User" and rest of the e-seres uses "user" :facepalm: + if (IcdEnvironment.CrestronDevicePlatform == IcdEnvironment.eCrestronDevicePlatform.Server) + return Join(RootPath, "User"); + + // Rest of processors + // 3-series traditionally used "User", but isn't case sensitive + return Join(RootPath, "user"); #elif LINUX return Join(RootPath, "opt", "ICD.Connect"); #else @@ -94,7 +95,7 @@ namespace ICD.Common.Utils get { // Crestron Server doesn't have meaningful program number - if (IcdEnvironment.CrestronRuntimeEnvironment == IcdEnvironment.eCrestronRuntimeEnvironment.Server) + if (IcdEnvironment.CrestronDevicePlatform == IcdEnvironment.eCrestronDevicePlatform.Server) return "ProgramConfig"; return string.Format("Program{0:D2}Config", ProgramUtils.ProgramNumber); @@ -117,7 +118,7 @@ namespace ICD.Common.Utils get { // Crestron Server doesn't have meaningful program number - if (IcdEnvironment.CrestronRuntimeEnvironment == IcdEnvironment.eCrestronRuntimeEnvironment.Server) + if (IcdEnvironment.CrestronDevicePlatform == IcdEnvironment.eCrestronDevicePlatform.Server) return "ProgramData"; return string.Format("Program{0:D2}Data", ProgramUtils.ProgramNumber); @@ -157,7 +158,7 @@ namespace ICD.Common.Utils string directoryName; // Crestron Server doesn't have meaningful program number - if (IcdEnvironment.CrestronRuntimeEnvironment == IcdEnvironment.eCrestronRuntimeEnvironment.Server) + if (IcdEnvironment.CrestronDevicePlatform == IcdEnvironment.eCrestronDevicePlatform.Server) directoryName = "ProgramLogs"; else directoryName = string.Format("Program{0:D2}Logs", ProgramUtils.ProgramNumber); @@ -181,12 +182,13 @@ namespace ICD.Common.Utils if (IcdEnvironment.CrestronSeries == IcdEnvironment.eCrestronSeries.ThreeSeries) return Join(RootPath, "HTML"); - // 4-series non-server (because Crestron) - if (IcdEnvironment.CrestronRuntimeEnvironment == IcdEnvironment.eCrestronRuntimeEnvironment.Appliance) - return Join(RootPath, "html"); - // 4-series server (because Crestron) - return Join(RootPath, "Html"); + if (IcdEnvironment.CrestronDevicePlatform == IcdEnvironment.eCrestronDevicePlatform.Server) + return Join(RootPath, "Html"); + + + // 4-series non-server (because Crestron) + return Join(RootPath, "html"); } #if LINUX diff --git a/ICD.Common.Utils/ProgramUtils.cs b/ICD.Common.Utils/ProgramUtils.cs index cb06b14..90f5644 100644 --- a/ICD.Common.Utils/ProgramUtils.cs +++ b/ICD.Common.Utils/ProgramUtils.cs @@ -24,19 +24,20 @@ namespace ICD.Common.Utils switch (IcdEnvironment.Framework) { case IcdEnvironment.eFramework.Crestron: + // No console in servers + if (IcdEnvironment.CrestronDevicePlatform == IcdEnvironment.eCrestronDevicePlatform.Server) + return; + switch (IcdEnvironment.CrestronRuntimeEnvironment) { - case IcdEnvironment.eCrestronRuntimeEnvironment.Simpl: + case IcdEnvironment.eCrestronRuntimeEnvironment.SimplPlus: int length = Math.Min(13, name.Length); name = name.Substring(0, length).PadRight(13); break; - case IcdEnvironment.eCrestronRuntimeEnvironment.Appliance: + case IcdEnvironment.eCrestronRuntimeEnvironment.SimplSharpPro: int proLength = Math.Min(26 - 1, name.Length); name = name.Substring(0, proLength).PadRight(26); break; - case IcdEnvironment.eCrestronRuntimeEnvironment.Server: - // No console - return; default: throw new ArgumentOutOfRangeException(); }