add GetExecutablePath()
This commit is contained in:
26
Pilz.IO/Extensions.cs
Normal file
26
Pilz.IO/Extensions.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using Pilz.Runtime;
|
||||||
|
using Pilz.Win32.Native;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Pilz.IO
|
||||||
|
{
|
||||||
|
public static class Extensions
|
||||||
|
{
|
||||||
|
static readonly int MAX_PATH = 255;
|
||||||
|
|
||||||
|
public static string GetExecutablePath(bool checkRealOS = false)
|
||||||
|
{
|
||||||
|
if (RuntimeInformationsEx.IsOSPlatform(OSType.Windows, checkRealOS))
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder(MAX_PATH);
|
||||||
|
Kernel32.GetModuleFileName(IntPtr.Zero, sb, MAX_PATH);
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return Process.GetCurrentProcess().MainModule.FileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -86,4 +86,8 @@
|
|||||||
<LastGenOutput>Application.Designer.cs</LastGenOutput>
|
<LastGenOutput>Application.Designer.cs</LastGenOutput>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Pilz.Win32\Pilz.Win32.vbproj" />
|
||||||
|
<ProjectReference Include="..\Pilz\Pilz.vbproj" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
16
Pilz.Win32/Native/Kernel32.vb
Normal file
16
Pilz.Win32/Native/Kernel32.vb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
Imports System.Runtime.InteropServices
|
||||||
|
Imports System.Text
|
||||||
|
|
||||||
|
Namespace Native
|
||||||
|
|
||||||
|
Public Class Kernel32
|
||||||
|
|
||||||
|
Private Const LIB_KERNEL32 As String = "kernel32.dll"
|
||||||
|
|
||||||
|
<DllImport(LIB_KERNEL32)>
|
||||||
|
Public Shared Function GetModuleFileName(hModule As IntPtr, lpFilename As StringBuilder, nSize As Integer) As UInteger
|
||||||
|
End Function
|
||||||
|
|
||||||
|
End Class
|
||||||
|
|
||||||
|
End Namespace
|
||||||
@@ -4,11 +4,13 @@ Namespace Native
|
|||||||
|
|
||||||
Public Class User32
|
Public Class User32
|
||||||
|
|
||||||
<DllImport("user32")>
|
Private Const LIB_USER32 As String = "user32.dll"
|
||||||
|
|
||||||
|
<DllImport(LIB_USER32)>
|
||||||
Public Shared Function GetWindowRect(ByVal hWnd As IntPtr, ByRef r As RECT) As Boolean
|
Public Shared Function GetWindowRect(ByVal hWnd As IntPtr, ByRef r As RECT) As Boolean
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
<DllImport("user32.dll")>
|
<DllImport(LIB_USER32)>
|
||||||
Public Shared Function ChildWindowFromPointEx(ByVal hWndParent As IntPtr, ByVal pt As POINT, ByVal uFlags As UInteger) As IntPtr
|
Public Shared Function ChildWindowFromPointEx(ByVal hWndParent As IntPtr, ByVal pt As POINT, ByVal uFlags As UInteger) As IntPtr
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ Namespace Runtime
|
|||||||
End Get
|
End Get
|
||||||
End Property
|
End Property
|
||||||
|
|
||||||
Public ReadOnly Property RealOSType As OSType
|
Public ReadOnly Property RealOSType As OSType
|
||||||
Get
|
Get
|
||||||
Static t As OSType? = Nothing
|
Static t As OSType? = Nothing
|
||||||
|
|
||||||
If t Is Nothing Then
|
If t Is Nothing Then
|
||||||
|
|
||||||
@@ -69,9 +69,13 @@ Namespace Runtime
|
|||||||
End If
|
End If
|
||||||
|
|
||||||
Return t
|
Return t
|
||||||
End Get
|
End Get
|
||||||
End Property
|
End Property
|
||||||
|
|
||||||
End Module
|
Public Function IsOSPlatform(os As OSType, checkRealOS As Boolean) As Boolean
|
||||||
|
Return If(checkRealOS, RealOSType, OSType) = os
|
||||||
|
End Function
|
||||||
|
|
||||||
|
End Module
|
||||||
|
|
||||||
End Namespace
|
End Namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user