mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
[Registry Preview] Moving to a different API to call the File Picker (#25260)
* Moving from FileOpenPicker Moving from FileOpenPicker to a Win32/PInvoke version, so it can be opened while running as Admin. * Update Resources.resw Replacing a lost string. * Save file picker also crashed Switched to Win32-based SafeFilePicker Cleaned up some of the code which should now pass spell checking and removed pragmas
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RegistryPreview
|
||||
{
|
||||
// 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 filter, string dialogTitle)
|
||||
{
|
||||
FileName openFileName = default(FileName);
|
||||
openFileName.StructSize = Marshal.SizeOf(openFileName);
|
||||
|
||||
openFileName.Filter = filter;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user