feat: Added program entry point to path utils

This commit is contained in:
Chris Cameron
2020-10-24 19:49:30 -04:00
committed by Chris Cameron
parent ca857a7aed
commit 6b28ae44d6
3 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
using System.Linq;
using System.Text;
using ICD.Common.Properties;
using ICD.Common.Utils.IO;
#if SIMPLSHARP
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronXmlLinq;
using Crestron.SimplSharp.Reflection;
#else
using System.Reflection;
#endif
namespace ICD.Common.Utils
{
public static class AssemblyUtils
{
/// <summary>
/// Gets the process executable in the default application domain. In other application domains,
/// this is the first executable that was executed by ExecuteAssembly(String).
/// </summary>
/// <returns></returns>
[CanBeNull]
public static Assembly GetEntryAssembly()
{
#if SIMPLSHARP
string appDir = InitialParametersClass.ProgramDirectory.ToString();
if (CrestronEnvironment.RuntimeEnvironment == eRuntimeEnvironment.SIMPL)
return null;
string proginfo = IcdFile.ReadToEnd(IcdPath.Combine(appDir, "ProgramInfo.config"), Encoding.UTF8);
XDocument doc = XDocument.Parse("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n" + proginfo);
XElement entry = doc.Descendants("EntryPoint").FirstOrDefault();
return entry == null ? null : Assembly.Load(entry.Value);
#else
return Assembly.GetEntryAssembly();
#endif
}
}
}

View File

@@ -75,6 +75,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AnsiUtils.cs" />
<Compile Include="AssemblyUtils.cs" />
<Compile Include="Attributes\AbstractIcdAttribute.cs" />
<Compile Include="Attributes\IIcdAttribute.cs" />
<Compile Include="Attributes\RangeAttribute.cs" />

View File

@@ -1,6 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
#if SIMPLSHARP
using Crestron.SimplSharp.Reflection;
#else
using System.Reflection;
#endif
using ICD.Common.Properties;
using ICD.Common.Utils.Extensions;
using ICD.Common.Utils.IO;
@@ -34,6 +39,20 @@ namespace ICD.Common.Utils
[PublicAPI]
public static string ProgramPath { get { return IcdDirectory.GetApplicationDirectory(); } }
/// <summary>
/// Gets the path to the program entry point assembly (i.e. ICD.Connect.Core_SimplSharp.dll)
/// </summary>
[PublicAPI]
[CanBeNull]
public static string ProgramFilePath
{
get
{
Assembly entry = AssemblyUtils.GetEntryAssembly();
return entry == null ? null : entry.GetPath();
}
}
/// <summary>
/// Gets the path to the root config directory,
/// which contains common and program-specific config directories.