[Settings]Fix backup and restore select folder when running as admin (#24164)

* Settings bkp and restore
Open foolder when elevated using shell32 api.

* increase the size of the alocated buffer for the path
based on https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry
This commit is contained in:
sosssego
2023-02-27 09:42:50 +00:00
committed by GitHub
parent eeca3014e7
commit 28144b6375
2 changed files with 78 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.ViewModels;
@@ -142,12 +143,12 @@ namespace Microsoft.PowerToys.Settings.UI.Views
private async Task<string> PickSingleFolderDialog()
{
var openPicker = new FolderPicker();
// This function was changed to use the shell32 API to open folder dialog
// as the old one (PickSingleFolderAsync) can't work when the process is elevated
// TODO: go back PickSingleFolderAsync when it's fixed
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(App.GetSettingsWindow());
WinRT.Interop.InitializeWithWindow.Initialize(openPicker, hwnd);
openPicker.FileTypeFilter.Add("*");
var folder = await openPicker.PickSingleFolderAsync();
return folder?.Path;
string r = await Task.FromResult<string>(ShellGetFolder.GetFolderDialog(hwnd));
return r;
}
}
}