diff --git a/src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs b/src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs index 14443b5824d2..b160212f8411 100644 --- a/src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs +++ b/src/Files.App/Actions/Content/ImageManipulation/BaseRotateAction.cs @@ -33,8 +33,7 @@ public BaseRotateAction() public async Task ExecuteAsync() { - foreach (var image in context.SelectedItems) - await BitmapHelper.RotateAsync(PathNormalization.NormalizePath(image.ItemPath), Rotation); + await Task.WhenAll(context.SelectedItems.Select(image => BitmapHelper.RotateAsync(PathNormalization.NormalizePath(image.ItemPath), Rotation))); context.ShellPage?.SlimContentPage?.ItemManipulationModel?.RefreshItemsThumbnail(); diff --git a/src/Files.App/Actions/Content/Install/InstallInfDriverAction.cs b/src/Files.App/Actions/Content/Install/InstallInfDriverAction.cs index d2bbe004b551..3912c230fc76 100644 --- a/src/Files.App/Actions/Content/Install/InstallInfDriverAction.cs +++ b/src/Files.App/Actions/Content/Install/InstallInfDriverAction.cs @@ -33,8 +33,7 @@ public InstallInfDriverAction() public async Task ExecuteAsync() { - foreach (ListedItem selectedItem in context.SelectedItems) - await Win32API.InstallInf(selectedItem.ItemPath); + await Task.WhenAll(context.SelectedItems.Select(selectedItem => Win32API.InstallInf(selectedItem.ItemPath))); } public void Context_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) diff --git a/src/Files.App/Data/Factories/ShellContextFlyoutHelper.cs b/src/Files.App/Data/Factories/ShellContextFlyoutHelper.cs index 1013c6dd71a3..e8cb98f9796f 100644 --- a/src/Files.App/Data/Factories/ShellContextFlyoutHelper.cs +++ b/src/Files.App/Data/Factories/ShellContextFlyoutHelper.cs @@ -12,6 +12,7 @@ using Vanara.PInvoke; using Windows.System; using Windows.UI.Core; +using static Vanara.PInvoke.Kernel32; namespace Files.App.Helpers { @@ -180,17 +181,11 @@ async Task InvokeShellMenuItemAsync(ContextMenu contextMenu, object? tag) switch (verb) { case "install" when isFont: - { - foreach (string path in contextMenu.ItemsPath) - await Win32API.InstallFont(path, false); - } + await Win32API.InstallFontsAsync(contextMenu.ItemsPath.ToArray(), false); break; case "installAllUsers" when isFont: - { - foreach (string path in contextMenu.ItemsPath) - await Win32API.InstallFont(path, true); - } + await Win32API.InstallFontsAsync(contextMenu.ItemsPath.ToArray(), true); break; case "mount": diff --git a/src/Files.App/Utils/Shell/Win32API.cs b/src/Files.App/Utils/Shell/Win32API.cs index 44d692215b02..56e4dee45018 100644 --- a/src/Files.App/Utils/Shell/Win32API.cs +++ b/src/Files.App/Utils/Shell/Win32API.cs @@ -850,21 +850,6 @@ public static async Task InstallInf(string filePath) } } - public static Task InstallFont(string fontFilePath, bool forAllUsers) - { - string fontDirectory = forAllUsers - ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Fonts") - : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft", "Windows", "Fonts"); - - string registryKey = forAllUsers - ? "HKLM:\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts" - : "HKCU:\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"; - - var destinationPath = Path.Combine(fontDirectory, Path.GetFileName(fontFilePath)); - - return RunPowershellCommandAsync($"-command \"Copy-Item '{fontFilePath}' '{fontDirectory}'; New-ItemProperty -Name '{Path.GetFileNameWithoutExtension(fontFilePath)}' -Path '{registryKey}' -PropertyType string -Value '{destinationPath}'\"", forAllUsers); - } - public static async Task InstallFontsAsync(string[] fontFilePaths, bool forAllUsers) { string fontDirectory = forAllUsers @@ -885,7 +870,7 @@ public static async Task InstallFontsAsync(string[] fontFilePaths, bool forAllUs if (psCommand.Length + appendCommand.Length > 32766) { // The command is too long to run at once, so run the command once up to this point. - await RunPowershellCommandAsync(psCommand.Append("\"").ToString(), forAllUsers); + await RunPowershellCommandAsync(psCommand.Append("\"").ToString(), true); psCommand.Clear().Append("-command \""); } diff --git a/src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs b/src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs index 35c94039109e..19d4ae9fbc3d 100644 --- a/src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs +++ b/src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs @@ -431,12 +431,15 @@ private async Task ReloadItemIconsAsync() ParentShellPageInstance.FilesystemViewModel.CancelExtendedPropertiesLoading(); var filesAndFolders = ParentShellPageInstance.FilesystemViewModel.FilesAndFolders.ToList(); - foreach (ListedItem listedItem in filesAndFolders) + + await Task.WhenAll(filesAndFolders.Select(listedItem => { listedItem.ItemPropertiesInitialized = false; if (FileList.ContainerFromItem(listedItem) is not null) - await ParentShellPageInstance.FilesystemViewModel.LoadExtendedItemPropertiesAsync(listedItem, currentIconSize); - } + return ParentShellPageInstance.FilesystemViewModel.LoadExtendedItemPropertiesAsync(listedItem, currentIconSize); + else + return Task.CompletedTask; + })); if (ParentShellPageInstance.FilesystemViewModel.EnabledGitProperties is not GitProperties.None) { diff --git a/src/Files.Core/Services/SizeProvider/DrivesSizeProvider.cs b/src/Files.Core/Services/SizeProvider/DrivesSizeProvider.cs index f855f119c38a..52cb08c8f5ea 100644 --- a/src/Files.Core/Services/SizeProvider/DrivesSizeProvider.cs +++ b/src/Files.Core/Services/SizeProvider/DrivesSizeProvider.cs @@ -24,14 +24,12 @@ public async Task CleanAsync() foreach (var oldDriveName in oldDriveNames) providers.TryRemove(oldDriveName, out _); - foreach (var provider in providers.Values) - await provider.CleanAsync(); + await Task.WhenAll(providers.Values.Select(provider => provider.CleanAsync())); } public async Task ClearAsync() { - foreach (var provider in providers.Values) - await provider.ClearAsync(); + await Task.WhenAll(providers.Values.Select(provider => provider.ClearAsync())); providers.Clear(); }