forked from microsoft/PowerToys
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Registry Preview] Moving to a different API to call the File Picker (m…
…icrosoft#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
- Loading branch information
1 parent
d0a1e40
commit 1dc013f
Showing
6 changed files
with
146 additions
and
30 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,39 @@ | ||
// 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; | ||
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 | ||
[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
36 changes: 36 additions & 0 deletions
36
src/modules/registrypreview/RegistryPreviewUI/OpenFileName.cs
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,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; | ||
} | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
src/modules/registrypreview/RegistryPreviewUI/SaveFileName.cs
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,38 @@ | ||
// 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 SaveFilePicker | ||
{ | ||
[DllImport("comdlg32.dll", SetLastError = true, CharSet = CharSet.Auto)] | ||
private static extern bool GetSaveFileName(ref FileName saveFileName); | ||
|
||
public static string ShowDialog(string suggestedFilename, string filter, string dialogTitle) | ||
{ | ||
FileName saveFileName = default(FileName); | ||
saveFileName.StructSize = Marshal.SizeOf(saveFileName); | ||
|
||
saveFileName.Filter = filter; | ||
saveFileName.File = new string(new char[256]); | ||
saveFileName.MaxFile = saveFileName.File.Length; | ||
saveFileName.File = string.Concat(suggestedFilename, saveFileName.File); | ||
saveFileName.FileTitle = new string(new char[64]); | ||
saveFileName.MaxFileTitle = saveFileName.FileTitle.Length; | ||
saveFileName.Title = dialogTitle; | ||
saveFileName.DefExt = "reg"; | ||
|
||
if (GetSaveFileName(ref saveFileName)) | ||
{ | ||
return saveFileName.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