Extensions.cs 772 B

123456789101112131415161718192021222324252627
  1. using System;
  2. using System.Diagnostics;
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5. namespace PixiEditor.UpdateInstaller
  6. {
  7. public static class Extensions
  8. {
  9. private const int MaxPath = 255;
  10. public static string GetExecutablePath()
  11. {
  12. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  13. {
  14. StringBuilder sb = new StringBuilder(MaxPath);
  15. GetModuleFileName(IntPtr.Zero, sb, MaxPath);
  16. return sb.ToString();
  17. }
  18. return Process.GetCurrentProcess().MainModule?.FileName;
  19. }
  20. [DllImport("kernel32.dll")]
  21. private static extern uint GetModuleFileName(IntPtr hModule, StringBuilder lpFilename, int nSize);
  22. }
  23. }