TRX/tools/installer/TRX_InstallerLib/Utils/AssemblyUtils.cs
lahm86 e16fcda94b tools/installer: create common installer library
This creates a generic common installer WPF library for both games.
2025-03-30 12:34:54 +01:00

35 lines
1.1 KiB
C#

using System.IO;
using System.Reflection;
namespace TRX_InstallerLib.Utils;
public static class AssemblyUtils
{
public static readonly string _resourcePathFormat = "pack://application:,,,/{0};component/Resources/{1}";
private static Assembly? GetReferencedAssembly(bool local)
{
return local ? Assembly.GetExecutingAssembly() : Assembly.GetEntryAssembly();
}
public static Stream GetResourceStream(string relativePath, bool local)
{
return GetReferencedAssembly(local)?.GetManifestResourceStream(GetAbsolutePath(relativePath, local))!;
}
public static bool ResourceExists(string relativePath, bool local)
{
return GetReferencedAssembly(local)?.GetManifestResourceNames()
.Contains(GetAbsolutePath(relativePath, local)) ?? false;
}
public static string GetAbsolutePath(string relativePath, bool local)
{
return $"{GetReferencedAssembly(local)!.GetName().Name}.{relativePath}";
}
public static string GetEmbeddedResourcePath(string resource)
{
return string.Format(_resourcePathFormat, Assembly.GetEntryAssembly()!.GetName().Name, resource);
}
}