27 lines
776 B
C#
27 lines
776 B
C#
using System.Diagnostics;
|
|
using Pilz.Runtime;
|
|
|
|
namespace Pilz;
|
|
|
|
public static class EnvironmentEx
|
|
{
|
|
private static string? processPath = null;
|
|
|
|
public static string? ProcessPath => processPath ??= GetProcessPath();
|
|
|
|
private static string? GetProcessPath()
|
|
{
|
|
if (RuntimeInformationsEx.IsOSPlatform(OSType.Linux, false)
|
|
&& Environment.GetEnvironmentVariable("APPIMAGE") is { } appImagePath
|
|
&& !string.IsNullOrWhiteSpace(appImagePath))
|
|
return appImagePath;
|
|
|
|
#if NET8_0_OR_GREATER
|
|
if (Environment.ProcessPath is { } processPath
|
|
&& !string.IsNullOrWhiteSpace(processPath))
|
|
return processPath;
|
|
#endif
|
|
|
|
return Process.GetCurrentProcess().MainModule?.FileName;
|
|
}
|
|
} |