-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement workaround for filepicker while running as admin
- Loading branch information
1 parent
fd34a23
commit e070544
Showing
4 changed files
with
77 additions
and
21 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,34 @@ | ||
using System.Runtime.InteropServices; | ||
using System; | ||
|
||
namespace MalwareToolbox.DesktopApp.Core.Utils; | ||
|
||
// Workaround for File Pickers that don't work while running as admin, per: | ||
// https://github.com/microsoft/WindowsAppSDK/issues/2504 | ||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] | ||
public struct FileName | ||
{ | ||
public int StructSize; | ||
public IntPtr HwndOwner; | ||
public IntPtr Instance; | ||
public string Filter; | ||
public string CustomFilter; | ||
public int MaxCustFilter; | ||
public int FilterIndex; | ||
public string File; | ||
public int MaxFile; | ||
public string FileTitle; | ||
public int MaxFileTitle; | ||
public string InitialDir; | ||
public string Title; | ||
public int Flags; | ||
public short FileOffset; | ||
public short FileExtension; | ||
public string DefExt; | ||
public IntPtr CustData; | ||
public IntPtr Hook; | ||
public string TemplateName; | ||
public IntPtr PtrReserved; | ||
public int Reserved; | ||
public int FlagsEx; | ||
} |
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,34 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace MalwareToolbox.DesktopApp.Core.Utils; | ||
|
||
// Workaround for File Pickers that don't work while running as admin, per: | ||
// https://github.com/microsoft/WindowsAppSDK/issues/2504 | ||
public static partial class OpenFilePicker | ||
{ | ||
[DllImport("comdlg32.dll", SetLastError = true, CharSet = CharSet.Auto)] | ||
private static extern bool GetOpenFileName(ref FileName openFileName); | ||
|
||
public static string ShowDialog(string[] filters, string dialogTitle) | ||
{ | ||
FileName openFileName = default(FileName); | ||
openFileName.StructSize = Marshal.SizeOf(openFileName); | ||
|
||
var filterstr = string.Join("\0", filters) + "\0\0"; | ||
|
||
openFileName.Filter = filterstr; | ||
openFileName.File = new string(new char[256]); | ||
openFileName.MaxFile = openFileName.File.Length; | ||
openFileName.FileTitle = new string(new char[64]); | ||
openFileName.MaxFileTitle = openFileName.FileTitle.Length; | ||
openFileName.Title = dialogTitle; | ||
|
||
if (GetOpenFileName(ref openFileName)) | ||
{ | ||
return openFileName.File; | ||
} | ||
|
||
return string.Empty; | ||
} | ||
} |
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
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