Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fixed a crash that would occur when opening file pickers and Files was running as admin #15386

Merged
merged 26 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/Files.App/Data/Contracts/ICommonDialogService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

namespace Files.App.Data.Contracts
{
/// <summary>
/// Provides service to launch common dialog through Win32API.
/// </summary>
public interface ICommonDialogService
{
/// <summary>
/// Opens a common dialog called FileOpenDialog through native Win32API.
/// </summary>
/// <param name="hWnd">The Window handle that the dialog launches based on.</param>
/// <param name="pickFoldersOnly">The value that indicates whether the picker is only for folders.</param>
/// <param name="filters">The extension filters that the dialog uses to exclude unnecessary files.<br/>The filter must have a pair:<code>[ "Application", ".exe" ]</code></param>
/// <param name="filePath">The file that that user chose.</param>
/// <remarks>
/// NOTE: There's a WinRT API to launch this dialog, but the API doesn't support windows that are launched by those who is in Administrators group or has broader privileges.
/// </remarks>
/// <returns>True if the 'Open' button was clicked; otherwise, false.</returns>
bool Open_FileOpenDialog(nint hWnd, bool pickFoldersOnly, string[] filters, Environment.SpecialFolder defaultFolder, out string filePath);

/// <summary>
/// Opens a common dialog called FileSaveDialog through native Win32API.
/// </summary>
/// <param name="hWnd">The Window handle that the dialog launches based on.</param>
/// <param name="pickFoldersOnly">The value that indicates whether the picker is only for folders.</param>
/// <param name="filters">The extension filters that the dialog uses to exclude unnecessary files.<br/>The filter must have a pair:<code>[ "Application", ".exe" ]</code></param>
/// <param name="filePath">The file that that user chose.</param>
/// <remarks>
/// NOTE: There's a WinRT API to launch this dialog, but the API doesn't support windows that are launched by those who is in Administrators group or has broader privileges.
/// </remarks>
/// <returns>True if the 'Open' button was clicked; otherwise, false.</returns>
bool Open_FileSaveDialog(nint hWnd, bool pickFoldersOnly, string[] filters, Environment.SpecialFolder defaultFolder, out string filePath);

/// <summary>
/// Opens a common dialog called NetworkConnectionDialog through native Win32API.
/// </summary>
/// <param name="hideRestoreConnectionCheckBox">The value indicating whether to hide the check box allowing the user to restore the connection at logon.</param>
/// <param name="persistConnectionAtLogon">The value indicating whether restore the connection at logon.</param>
/// <param name="readOnlyPath">The value indicating whether to display a read-only path instead of allowing the user to type in a path. This is only valid if <see cref="RemoteNetworkName"/> is not <see langword="null"/>.</param>
/// <param name="remoteNetworkName">The name of the remote network.</param>
/// <param name="useMostRecentPath">The value indicating whether to enter the most recently used paths into the combination box.</param>
/// <returns>True if the 'OK' button was clicked; otherwise, false.</returns>
bool Open_NetworkConnectionDialog(nint hWind, bool hideRestoreConnectionCheckBox = false, bool persistConnectionAtLogon = false, bool readOnlyPath = false, string? remoteNetworkName = null, bool useMostRecentPath = false);
}
}
15 changes: 0 additions & 15 deletions src/Files.App/Data/Contracts/IFileExplorerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,5 @@ public interface IFileExplorerService
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that cancels this action.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
Task OpenInFileExplorerAsync(ILocatableFolder folder, CancellationToken cancellationToken = default);

/// <summary>
/// Awaits the user input and picks single file from the file explorer dialog.
/// </summary>
/// <param name="filter">The filter to apply when picking files.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that cancels this action.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous operation. If successful and a file has been picked, returns <see cref="ILocatableFile"/>, otherwise null.</returns>
Task<ILocatableFile?> PickSingleFileAsync(IEnumerable<string>? filter, CancellationToken cancellationToken = default);

/// <summary>
/// Awaits the user input and picks single folder from the file explorer dialog.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that cancels this action.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous operation. If successful and a folder has been picked, returns <see cref="ILocatableFolder"/>, otherwise null.</returns>
Task<ILocatableFolder?> PickSingleFolderAsync(CancellationToken cancellationToken = default);
}
}
118 changes: 0 additions & 118 deletions src/Files.App/Data/Models/NetworkConnectionDialog.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/Files.App/Helpers/Application/AppLifecycleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public static IHost ConfigureHost()
// Services
.AddSingleton<IAppThemeModeService, AppThemeModeService>()
.AddSingleton<IDialogService, DialogService>()
.AddSingleton<ICommonDialogService, CommonDialogService>()
.AddSingleton<IImageService, ImagingService>()
.AddSingleton<IThreadingService, ThreadingService>()
.AddSingleton<ILocalizationService, LocalizationService>()
Expand Down
8 changes: 7 additions & 1 deletion src/Files.App/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ DeleteFileFromApp
RemoveDirectoryFromApp
GetKeyState
CreateDirectoryFromApp
CoCreateInstance
FileOpenDialog
IFileOpenDialog
SHCreateItemFromParsingName
FileSaveDialog
IFileSaveDialog
D3D_DRIVER_TYPE
D3D_FEATURE_LEVEL
ID3D11Device
ID3D11DeviceContext
D3D11CreateDevice
IDXGIDevice
DCompositionCreateDevice
IDCompositionDevice
IDCompositionDevice