mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-17 05:35:07 +00:00
feat: Added program entry point to path utils
This commit is contained in:
committed by
Chris Cameron
parent
ca857a7aed
commit
6b28ae44d6
40
ICD.Common.Utils/AssemblyUtils.cs
Normal file
40
ICD.Common.Utils/AssemblyUtils.cs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -75,6 +75,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AnsiUtils.cs" />
|
<Compile Include="AnsiUtils.cs" />
|
||||||
|
<Compile Include="AssemblyUtils.cs" />
|
||||||
<Compile Include="Attributes\AbstractIcdAttribute.cs" />
|
<Compile Include="Attributes\AbstractIcdAttribute.cs" />
|
||||||
<Compile Include="Attributes\IIcdAttribute.cs" />
|
<Compile Include="Attributes\IIcdAttribute.cs" />
|
||||||
<Compile Include="Attributes\RangeAttribute.cs" />
|
<Compile Include="Attributes\RangeAttribute.cs" />
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
#if SIMPLSHARP
|
||||||
|
using Crestron.SimplSharp.Reflection;
|
||||||
|
#else
|
||||||
|
using System.Reflection;
|
||||||
|
#endif
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
using ICD.Common.Utils.Extensions;
|
using ICD.Common.Utils.Extensions;
|
||||||
using ICD.Common.Utils.IO;
|
using ICD.Common.Utils.IO;
|
||||||
@@ -34,6 +39,20 @@ namespace ICD.Common.Utils
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static string ProgramPath { get { return IcdDirectory.GetApplicationDirectory(); } }
|
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>
|
/// <summary>
|
||||||
/// Gets the path to the root config directory,
|
/// Gets the path to the root config directory,
|
||||||
/// which contains common and program-specific config directories.
|
/// which contains common and program-specific config directories.
|
||||||
|
|||||||
Reference in New Issue
Block a user