Files
Pilz/Pilz/EnvironmentEx.cs
2025-11-10 15:57:51 +01:00

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;
}
}