Extensions.cs 714 B

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