-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround IL2CPP limitation (no Process.Start)
- Loading branch information
Showing
3 changed files
with
107 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace StlVault.ViewModels | ||
{ | ||
[SuppressMessage("ReSharper", "FieldCanBeMadeReadOnly.Local")] | ||
[SuppressMessage("ReSharper", "BuiltInTypeReferenceStyle")] | ||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Local")] | ||
[SuppressMessage("ReSharper", "InconsistentNaming")] | ||
[SuppressMessage("ReSharper", "IdentifierTypo")] | ||
internal static class NativeMethods | ||
{ | ||
public static void BrowseTo(string filePath) | ||
{ | ||
const uint normalPriorityClass = 0x0020; | ||
|
||
var application = Environment.GetEnvironmentVariable("windir") + @"\explorer.exe"; | ||
var commandLine = $"/e, /select, \"{filePath}\""; | ||
var sInfo = new STARTUPINFO(); | ||
var pSec = new SECURITY_ATTRIBUTES(); | ||
var tSec = new SECURITY_ATTRIBUTES(); | ||
pSec.nLength = Marshal.SizeOf(pSec); | ||
tSec.nLength = Marshal.SizeOf(tSec); | ||
|
||
//Open Explorer at location | ||
CreateProcess(application, commandLine, | ||
ref pSec, ref tSec, false, normalPriorityClass, | ||
IntPtr.Zero, null, ref sInfo, out _); | ||
} | ||
|
||
[DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Auto)] | ||
static extern bool CreateProcess( | ||
string lpApplicationName, | ||
string lpCommandLine, | ||
ref SECURITY_ATTRIBUTES lpProcessAttributes, | ||
ref SECURITY_ATTRIBUTES lpThreadAttributes, | ||
bool bInheritHandles, | ||
uint dwCreationFlags, | ||
IntPtr lpEnvironment, | ||
string lpCurrentDirectory, | ||
[In] ref STARTUPINFO lpStartupInfo, | ||
out PROCESS_INFORMATION lpProcessInformation); | ||
|
||
// This also works with CharSet.Ansi as long as the calling function uses the same character set. | ||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | ||
private struct STARTUPINFO | ||
{ | ||
public Int32 cb; | ||
public string lpReserved; | ||
public string lpDesktop; | ||
public string lpTitle; | ||
public Int32 dwX; | ||
public Int32 dwY; | ||
public Int32 dwXSize; | ||
public Int32 dwYSize; | ||
public Int32 dwXCountChars; | ||
public Int32 dwYCountChars; | ||
public Int32 dwFillAttribute; | ||
public Int32 dwFlags; | ||
public Int16 wShowWindow; | ||
public Int16 cbReserved2; | ||
public IntPtr lpReserved2; | ||
public IntPtr hStdInput; | ||
public IntPtr hStdOutput; | ||
public IntPtr hStdError; | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
private struct PROCESS_INFORMATION | ||
{ | ||
public IntPtr hProcess; | ||
public IntPtr hThread; | ||
public int dwProcessId; | ||
public int dwThreadId; | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
private struct SECURITY_ATTRIBUTES | ||
{ | ||
public int nLength; | ||
public unsafe byte* lpSecurityDescriptor; | ||
public int bInheritHandle; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters