diff --git a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj index 23bf212..52ea880 100644 --- a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj +++ b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj @@ -85,6 +85,8 @@ + + diff --git a/ICD.Common.Utils/IO/IcdFile.cs b/ICD.Common.Utils/IO/IcdFile.cs index 11830a9..1e091f3 100644 --- a/ICD.Common.Utils/IO/IcdFile.cs +++ b/ICD.Common.Utils/IO/IcdFile.cs @@ -27,6 +27,15 @@ namespace ICD.Common.Utils.IO #endif } + [PublicAPI] + public static DateTime GetLastWriteTime(string path) + { + if (path == null) + throw new ArgumentNullException("path"); + + return File.GetLastWriteTime(path); + } + [PublicAPI] public static bool Exists(string path) { diff --git a/ICD.Common.Utils/ProgramUtils.SimplSharp.cs b/ICD.Common.Utils/ProgramUtils.SimplSharp.cs new file mode 100644 index 0000000..48bf278 --- /dev/null +++ b/ICD.Common.Utils/ProgramUtils.SimplSharp.cs @@ -0,0 +1,134 @@ +#if SIMPLSHARP +using Crestron.SimplSharp; +using ICD.Common.Properties; +using ICD.Common.Services; +using ICD.Common.Services.Logging; +using ICD.Common.Utils.Extensions; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace ICD.Common.Utils +{ + public static partial class ProgramUtils + { + private const string APPLICATION_NAME_KEY = "Application Name"; + private const string APPLICATION_NAME_SIMPL_KEY = "System Name"; + private const string PROGRAM_FILE_KEY = "Program File"; + + private const string COMPILED_ON_KEY = "Compiled On"; + private const string COMPILER_REVISION_KEY = "Compiler Revision"; + private const string COMPILER_REVISION_SIMPL_KEY = "Compiler Rev"; + + private static Dictionary s_ProgComments; + + /// + /// Lazy-load the prog-comments map. + /// + private static Dictionary ProgComments + { + get { return s_ProgComments ?? (s_ProgComments = ParseProgComments()); } + } + + /// + /// Gets the program number. + /// + [PublicAPI] + public static uint ProgramNumber + { + get + { + return InitialParametersClass.ApplicationNumber; + } + } + + /// + /// Gets the compile date of the program. + /// + [PublicAPI] + public static string CompiledDate { get { return ProgComments.GetDefault(COMPILED_ON_KEY, null); } } + + /// + /// Gets the compiler revision version. + /// + [PublicAPI] + public static Version CompilerRevision + { + get + { + string output; + + if (ProgComments.TryGetValue(COMPILER_REVISION_KEY, out output)) + return new Version(output); + + if (ProgComments.TryGetValue(COMPILER_REVISION_SIMPL_KEY, out output)) + return new Version(output); + + return new Version(0, 0); + } + } + + /// + /// Gets the name of the program dll. + /// + [PublicAPI] + public static string ProgramFile { get { return ProgComments.GetDefault(PROGRAM_FILE_KEY, null); } } + + /// + /// Gets the name of the application. + /// + [PublicAPI] + public static string ApplicationName + { + get + { + string output; + + if (ProgComments.TryGetValue(APPLICATION_NAME_KEY, out output)) + return output; + + ProgComments.TryGetValue(APPLICATION_NAME_SIMPL_KEY, out output); + return output; + } + } + + /// + /// Parses the prog comments and pulls program information. + /// + private static Dictionary ParseProgComments() + { + Dictionary output = new Dictionary(); + + string progInfo = string.Empty; + string command = string.Format("progcomments:{0}", ProgramNumber); + + if (!IcdConsole.SendControlSystemCommand(command, ref progInfo)) + { + ServiceProvider.GetService().AddEntry(eSeverity.Warning, "Failed to parse prog comments"); + return output; + } + + foreach (string line in progInfo.Split(new[] { "\n\r", "\r\n", "\n", "\r" })) + { + if (string.IsNullOrEmpty(line)) + continue; + + string[] pair = line.Split(':', 2).ToArray(); + + if (pair.Length < 2) + { + ServiceProvider.GetService() + .AddEntry(eSeverity.Warning, "Failed to parse prog comments line - {0}", line); + continue; + } + + string key = pair[0].Trim(); + string value = pair[1].Trim(); + output[key] = value; + } + + return output; + } + } +} +#endif diff --git a/ICD.Common.Utils/ProgramUtils.Standard.cs b/ICD.Common.Utils/ProgramUtils.Standard.cs new file mode 100644 index 0000000..70a009c --- /dev/null +++ b/ICD.Common.Utils/ProgramUtils.Standard.cs @@ -0,0 +1,66 @@ +#if !SIMPLSHARP +using ICD.Common.Properties; +using ICD.Common.Utils.IO; +using System; +using System.Reflection; + +namespace ICD.Common.Utils +{ + public static partial class ProgramUtils + { + /// + /// Gets the program number. + /// + [PublicAPI] + public static uint ProgramNumber + { + get + { + return 1; + } + } + + /// + /// Gets the compile date of the program. + /// + [PublicAPI] + public static string CompiledDate + { + get + { + return IcdFile.GetLastWriteTime(Assembly.GetEntryAssembly().Location).ToString(); + } + } + + /// + /// Gets the compiler revision version. + /// + [PublicAPI] + public static Version CompilerRevision + { + get + { + return Assembly.GetEntryAssembly().GetName().Version; + } + } + + /// + /// Gets the name of the program dll. + /// + [PublicAPI] + public static string ProgramFile { get { return IcdPath.GetFileName(Assembly.GetEntryAssembly().Location); } } + + /// + /// Gets the name of the application. + /// + [PublicAPI] + public static string ApplicationName + { + get + { + return Assembly.GetEntryAssembly().GetName().Name; + } + } + } +} +#endif diff --git a/ICD.Common.Utils/ProgramUtils.cs b/ICD.Common.Utils/ProgramUtils.cs index f314aa0..d291371 100644 --- a/ICD.Common.Utils/ProgramUtils.cs +++ b/ICD.Common.Utils/ProgramUtils.cs @@ -1,112 +1,16 @@ using System; -using System.Collections.Generic; -using System.Linq; using ICD.Common.Properties; -using ICD.Common.Services; -using ICD.Common.Services.Logging; -using ICD.Common.Utils.Extensions; -#if SIMPLSHARP -using Crestron.SimplSharp; -#endif namespace ICD.Common.Utils { - public static class ProgramUtils + public static partial class ProgramUtils { - private const string APPLICATION_NAME_KEY = "Application Name"; - private const string APPLICATION_NAME_SIMPL_KEY = "System Name"; - private const string PROGRAM_FILE_KEY = "Program File"; - - private const string COMPILED_ON_KEY = "Compiled On"; - private const string COMPILER_REVISION_KEY = "Compiler Revision"; - private const string COMPILER_REVISION_SIMPL_KEY = "Compiler Rev"; - - private static Dictionary s_ProgComments; - - #region Properties - - /// - /// Lazy-load the prog-comments map. - /// - private static Dictionary ProgComments - { - get { return s_ProgComments ?? (s_ProgComments = ParseProgComments()); } - } - - /// - /// Gets the program number. - /// - [PublicAPI] - public static uint ProgramNumber - { - get - { -#if SIMPLSHARP - return InitialParametersClass.ApplicationNumber; -#else - return 1; -#endif - } - } - /// /// Gets the program number in the format XX, eg slot 1 is 01. /// [PublicAPI] public static string ProgramNumberFormatted { get { return string.Format("{0:D2}", ProgramNumber); } } - /// - /// Gets the compile date of the program. - /// - [PublicAPI] - public static string CompiledDate { get { return ProgComments.GetDefault(COMPILED_ON_KEY, null); } } - - /// - /// Gets the compiler revision version. - /// - [PublicAPI] - public static Version CompilerRevision - { - get - { - string output; - - if (ProgComments.TryGetValue(COMPILER_REVISION_KEY, out output)) - return new Version(output); - - if (ProgComments.TryGetValue(COMPILER_REVISION_SIMPL_KEY, out output)) - return new Version(output); - - return new Version(0, 0); - } - } - - /// - /// Gets the name of the program dll. - /// - [PublicAPI] - public static string ProgramFile { get { return ProgComments.GetDefault(PROGRAM_FILE_KEY, null); } } - - /// - /// Gets the name of the application. - /// - [PublicAPI] - public static string ApplicationName - { - get - { - string output; - - if (ProgComments.TryGetValue(APPLICATION_NAME_KEY, out output)) - return output; - - ProgComments.TryGetValue(APPLICATION_NAME_SIMPL_KEY, out output); - return output; - } - } - - #endregion - /// /// Fakes program info, e.g. "Min Firmware Version : 1.009.0029" /// @@ -139,43 +43,5 @@ namespace ICD.Common.Utils IcdConsole.PrintLine("{0}: {1}", name, value); } - - /// - /// Parses the prog comments and pulls program information. - /// - private static Dictionary ParseProgComments() - { - Dictionary output = new Dictionary(); - - string progInfo = string.Empty; - string command = string.Format("progcomments:{0}", ProgramNumber); - - if (!IcdConsole.SendControlSystemCommand(command, ref progInfo)) - { - ServiceProvider.GetService().AddEntry(eSeverity.Warning, "Failed to parse prog comments"); - return output; - } - - foreach (string line in progInfo.Split(new[] {"\n\r", "\r\n", "\n", "\r"})) - { - if (string.IsNullOrEmpty(line)) - continue; - - string[] pair = line.Split(':', 2).ToArray(); - - if (pair.Length < 2) - { - ServiceProvider.GetService() - .AddEntry(eSeverity.Warning, "Failed to parse prog comments line - {0}", line); - continue; - } - - string key = pair[0].Trim(); - string value = pair[1].Trim(); - output[key] = value; - } - - return output; - } } }