From b66a807c678a93cd5c3e201eed60c2e794ef070b Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Thu, 4 May 2023 12:00:37 +0900 Subject: [PATCH 01/10] Fix: Fixed issue where removing an item from the recent list didn't work (#12273) --- src/Files.App/Shell/ContextMenu.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Files.App/Shell/ContextMenu.cs b/src/Files.App/Shell/ContextMenu.cs index f1e406b63ae9..88cb0bd312d7 100644 --- a/src/Files.App/Shell/ContextMenu.cs +++ b/src/Files.App/Shell/ContextMenu.cs @@ -52,6 +52,11 @@ public async Task InvokeVerb(string? verb) if (string.IsNullOrEmpty(verb)) return false; + var item = Items.Where(x => x.CommandString == verb).FirstOrDefault(); + if (item is not null && item.ID >= 0) + // Prefer invocation by ID + return await InvokeItem(item.ID); + try { var currentWindows = Win32API.GetDesktopWindows(); @@ -76,10 +81,10 @@ public async Task InvokeVerb(string? verb) return false; } - public async Task InvokeItem(int itemID) + public async Task InvokeItem(int itemID) { if (itemID < 0) - return; + return false; try { @@ -93,13 +98,16 @@ public async Task InvokeItem(int itemID) pici.cbSize = (uint)Marshal.SizeOf(pici); await owningThread.PostMethod(() => cMenu.InvokeCommand(pici)); - Win32API.BringToForeground(currentWindows); + + return true; } catch (Exception ex) when (ex is COMException or UnauthorizedAccessException) { Debug.WriteLine(ex); } + + return false; } #region FactoryMethods From 92e07da92902b5be34d03430c7d5a07eb9aa5e10 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Sun, 7 May 2023 14:35:35 +0900 Subject: [PATCH 02/10] Fix: Fixed crash with Win32Exception (#12299) --- src/Files.App/Helpers/FileOperationsHelpers.cs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/Files.App/Helpers/FileOperationsHelpers.cs b/src/Files.App/Helpers/FileOperationsHelpers.cs index 4599da865a62..2cd4ad0cef1e 100644 --- a/src/Files.App/Helpers/FileOperationsHelpers.cs +++ b/src/Files.App/Helpers/FileOperationsHelpers.cs @@ -2,22 +2,12 @@ using Files.App.Filesystem.Security; using Files.App.Shell; using Files.Backend.Helpers; -using Files.Shared; -using Files.Shared.Enums; -using Files.Shared.Extensions; using Microsoft.Extensions.Logging; using Microsoft.Win32; -using System; using System.Collections.Concurrent; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; using System.IO; -using System.Linq; using System.Runtime.InteropServices; using System.Security.Principal; -using System.Threading; -using System.Threading.Tasks; using Tulpep.ActiveDirectoryObjectPicker; using Vanara.PInvoke; using Vanara.Windows.Shell; @@ -522,7 +512,7 @@ public static void TryCancelOperation(string operationId) { Name = x.ProcessName, Pid = x.Id, - FileName = x.MainModule?.FileName, + FileName = SafetyExtensions.IgnoreExceptions(() => x.MainModule?.FileName), AppName = SafetyExtensions.IgnoreExceptions(() => x.MainModule?.FileVersionInfo?.FileDescription) }).ToList(); processes.ForEach(x => x.Dispose()); From dc5e58c3cc1d56d1c9af566a2a283f13849f00cf Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Sun, 7 May 2023 22:34:20 +0900 Subject: [PATCH 03/10] Fix: Fixed wrong total editing time format (#12301) --- src/Files.App/Resources/PreviewPanePropertiesInformation.json | 1 + src/Files.App/Resources/PropertiesInformation.json | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Files.App/Resources/PreviewPanePropertiesInformation.json b/src/Files.App/Resources/PreviewPanePropertiesInformation.json index 737bd95c5e6c..225415d52974 100644 --- a/src/Files.App/Resources/PreviewPanePropertiesInformation.json +++ b/src/Files.App/Resources/PreviewPanePropertiesInformation.json @@ -332,6 +332,7 @@ "SectionResource": "Document", "Property": "System.Document.TotalEditingTime", "IsReadOnly": true, + "DisplayFunctionName": "FormatDuration", "ID": null }, { diff --git a/src/Files.App/Resources/PropertiesInformation.json b/src/Files.App/Resources/PropertiesInformation.json index f617fe89efdc..1b20cdd97ee5 100644 --- a/src/Files.App/Resources/PropertiesInformation.json +++ b/src/Files.App/Resources/PropertiesInformation.json @@ -434,6 +434,7 @@ "SectionResource": "Document", "Property": "System.Document.TotalEditingTime", "IsReadOnly": true, + "DisplayFunctionName": "FormatDuration", "ID": null }, { From 7a126972468ff13ad20ef756f06edb2c31903965 Mon Sep 17 00:00:00 2001 From: Filippo Ferrario <102259289+ferrariofilippo@users.noreply.github.com> Date: Sun, 7 May 2023 16:49:51 +0200 Subject: [PATCH 04/10] Fix: Fixed issue with file preview in column layout (#12284) --- src/Files.App/BaseLayout.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/BaseLayout.cs b/src/Files.App/BaseLayout.cs index 5bca9bfae7a1..9ff204fe1d01 100644 --- a/src/Files.App/BaseLayout.cs +++ b/src/Files.App/BaseLayout.cs @@ -218,7 +218,7 @@ internal set //if (!(value?.All(x => selectedItems?.Contains(x) ?? false) ?? value == selectedItems)) if (value != selectedItems) { - if (value?.FirstOrDefault() != selectedItems?.FirstOrDefault()) + if (value?.FirstOrDefault() != PreviewPaneViewModel.SelectedItem) { // Update preview pane properties PreviewPaneViewModel.IsItemSelected = value?.Count > 0; From 424b92e2e634d6787004d7f3bd623244e5227efc Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Mon, 8 May 2023 00:32:44 +0900 Subject: [PATCH 05/10] Fix: Fixed crash when creating bitmap images (#12303) --- src/Files.App/Helpers/BitmapHelper.cs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Files.App/Helpers/BitmapHelper.cs b/src/Files.App/Helpers/BitmapHelper.cs index 3422fa6e160e..1c7bce7a96b4 100644 --- a/src/Files.App/Helpers/BitmapHelper.cs +++ b/src/Files.App/Helpers/BitmapHelper.cs @@ -1,9 +1,7 @@ using Files.App.Filesystem; using Files.App.Filesystem.StorageItems; using Microsoft.UI.Xaml.Media.Imaging; -using System; using System.IO; -using System.Threading.Tasks; using Windows.Graphics.Imaging; using Windows.Storage; using Windows.Storage.Streams; @@ -19,15 +17,22 @@ public static async Task ToBitmapAsync(this byte[]? data, int decod return null; } - using var ms = new MemoryStream(data); - var image = new BitmapImage(); - if (decodeSize > 0) + try + { + using var ms = new MemoryStream(data); + var image = new BitmapImage(); + if (decodeSize > 0) + { + image.DecodePixelWidth = decodeSize; + image.DecodePixelHeight = decodeSize; + } + await image.SetSourceAsync(ms.AsRandomAccessStream()); + return image; + } + catch (Exception) { - image.DecodePixelWidth = decodeSize; - image.DecodePixelHeight = decodeSize; + return null; } - await image.SetSourceAsync(ms.AsRandomAccessStream()); - return image; } /// From 07d78dbdb895fabad3e5cbc0dee3a3d9e7a9c602 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Wed, 10 May 2023 10:26:44 +0900 Subject: [PATCH 06/10] Fix: Fixed duration formatting when it is more than one day (#12314) --- src/Files.App/ViewModels/Properties/FileProperty.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Files.App/ViewModels/Properties/FileProperty.cs b/src/Files.App/ViewModels/Properties/FileProperty.cs index 6fd366388b40..d655aa93d860 100644 --- a/src/Files.App/ViewModels/Properties/FileProperty.cs +++ b/src/Files.App/ViewModels/Properties/FileProperty.cs @@ -324,12 +324,15 @@ public async static Task> RetrieveAndInitializePropertiesAsyn private static readonly Dictionary> DisplayFuncs = new Dictionary>() { { "DivideBy1000", input => (((uint) input)/1000).ToString() }, - { "FormatDuration", input => new TimeSpan(Convert.ToInt64(input)).ToString("hh':'mm':'ss")}, + { "FormatDuration", input => TimeSpanToString(new TimeSpan(Convert.ToInt64(input)))}, { "Fraction" , input => ((double)input).ToFractions(2000)}, { "AddF" , input => $"f/{(double)input}"}, { "AddISO" , input => $"ISO-{(UInt16)input}"}, { "RoundDouble" , input => $"{Math.Round((double)input)}"}, { "UnitMM" , input => $"{(double)input} mm"}, }; + + private static string TimeSpanToString(TimeSpan t) + => t.Days > 0 ? (t.Days * 24 + t.Hours) + t.ToString("':'mm':'ss") : t.ToString("hh':'mm':'ss"); } } From 95d9d6c078bffd2eb1553c82f4188edbb418081b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Garc=C3=ADa=20Ruiz?= <55754091+hecksmosis@users.noreply.github.com> Date: Thu, 11 May 2023 18:40:29 +0200 Subject: [PATCH 07/10] Fix: Fixed crash when trying to create bitmap from null IconData in `SidebarPinnedModel.cs` (#12333) --- src/Files.App/DataModels/SidebarPinnedModel.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Files.App/DataModels/SidebarPinnedModel.cs b/src/Files.App/DataModels/SidebarPinnedModel.cs index 8ac8515cd2cf..f80ec9e3fd66 100644 --- a/src/Files.App/DataModels/SidebarPinnedModel.cs +++ b/src/Files.App/DataModels/SidebarPinnedModel.cs @@ -115,7 +115,9 @@ public async Task CreateLocationItemFromPathAsync(string path) { var iconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(res.Result, 96u, ThumbnailMode.ListView); locationItem.IconData = iconData; - locationItem.Icon = await App.Window.DispatcherQueue.EnqueueOrInvokeAsync(() => locationItem.IconData.ToBitmapAsync()); + + if (locationItem.IconData is not null) + locationItem.Icon = await App.Window.DispatcherQueue.EnqueueOrInvokeAsync(() => locationItem.IconData.ToBitmapAsync()); } if (locationItem.IconData is null) From 1042d49b366e99f4ea8ddac383973e5243ff1dc2 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Fri, 12 May 2023 02:21:15 +0900 Subject: [PATCH 08/10] Fix: Fixed System.ArgumentException caused by adding the same key (#12302) --- src/Files.Shared/Extensions/LinqExtensions.cs | 54 ++++++++++++++----- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/src/Files.Shared/Extensions/LinqExtensions.cs b/src/Files.Shared/Extensions/LinqExtensions.cs index 499e937bfc89..012537356483 100644 --- a/src/Files.Shared/Extensions/LinqExtensions.cs +++ b/src/Files.Shared/Extensions/LinqExtensions.cs @@ -22,17 +22,33 @@ public static class LinqExtensions /// public static bool IsEmpty(this IEnumerable enumerable) => enumerable is null || !enumerable.Any(); - public static TOut? Get(this IDictionary dictionary, TKey key, TOut? defaultValue = default) + public static TOut? Get(this IDictionary dictionary, TKey key, TOut? defaultValue = default) where TKey : notnull { if (dictionary is null || key is null) return defaultValue; - if (!dictionary.ContainsKey(key)) + if (dictionary is ConcurrentDictionary cDict) { - if (defaultValue is TValue value) - dictionary.Add(key, value); + if (!cDict.ContainsKey(key)) + { + if (defaultValue is TValue value) + cDict.TryAdd(key, value); - return defaultValue; + return defaultValue; + } + } + else + { + lock (dictionary) + { + if (!dictionary.ContainsKey(key)) + { + if (defaultValue is TValue value) + dictionary.Add(key, value); + + return defaultValue; + } + } } if (dictionary[key] is TOut o) @@ -46,22 +62,32 @@ public static class LinqExtensions if (dictionary is null || key is null) return defaultValueFunc(); - if (!dictionary.ContainsKey(key)) + if (dictionary is ConcurrentDictionary> cDict) { - var defaultValue = defaultValueFunc(); - if (defaultValue is Task value) + if (!cDict.ContainsKey(key)) { - if (dictionary is ConcurrentDictionary> cDict) - { + var defaultValue = defaultValueFunc(); + if (defaultValue is Task value) cDict.TryAdd(key, value); - } - else + + return defaultValue; + } + } + else + { + lock (dictionary) + { + if (!dictionary.ContainsKey(key)) { - dictionary.Add(key, value); + var defaultValue = defaultValueFunc(); + if (defaultValue is Task value) + dictionary.Add(key, value); + + return defaultValue; } } - return defaultValue; } + return dictionary[key]; } From f36aedea315706f886ad7155d5b7fb24e6812663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Garc=C3=ADa=20Ruiz?= <55754091+hecksmosis@users.noreply.github.com> Date: Thu, 11 May 2023 22:24:46 +0200 Subject: [PATCH 09/10] Fix: Fixed NullReferenceException with EnumerateItemsFromStandardFolderAsync (#12335) --- src/Files.App/ViewModels/ItemViewModel.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Files.App/ViewModels/ItemViewModel.cs b/src/Files.App/ViewModels/ItemViewModel.cs index 5a365075abfc..394feb35568c 100644 --- a/src/Files.App/ViewModels/ItemViewModel.cs +++ b/src/Files.App/ViewModels/ItemViewModel.cs @@ -104,7 +104,7 @@ public ListedItem CurrentFolder public string WorkingDirectory { get; private set; } - private StorageFolderWithPath currentStorageFolder; + private StorageFolderWithPath? currentStorageFolder; private StorageFolderWithPath workingRoot; public delegate void WorkingDirectoryModifiedEventHandler(object sender, WorkingDirectoryModifiedEventArgs e); @@ -1400,7 +1400,7 @@ public async Task EnumerateItemsFromSpecialFolderAsync(string path) { var isFtp = FtpHelpers.IsFtpPath(path); - CurrentFolder = new ListedItem(null) + CurrentFolder = new ListedItem(null!) { PrimaryItemAttribute = StorageItemTypes.Folder, ItemPropertiesInitialized = true, @@ -1569,22 +1569,22 @@ await DialogDisplayHelper.ShowDialogAsync( if (enumFromStorageFolder) { var basicProps = await rootFolder?.GetBasicPropertiesAsync(); - var currentFolder = library ?? new ListedItem(rootFolder.FolderRelativeId) + var currentFolder = library ?? new ListedItem(rootFolder?.FolderRelativeId ?? string.Empty) { PrimaryItemAttribute = StorageItemTypes.Folder, ItemPropertiesInitialized = true, - ItemNameRaw = rootFolder.DisplayName, + ItemNameRaw = rootFolder?.DisplayName ?? string.Empty, ItemDateModifiedReal = basicProps.DateModified, - ItemType = rootFolder.DisplayType, + ItemType = rootFolder?.DisplayType ?? string.Empty, FileImage = null, LoadFileIcon = false, - ItemPath = string.IsNullOrEmpty(rootFolder.Path) ? currentStorageFolder.Path : rootFolder.Path, + ItemPath = string.IsNullOrEmpty(rootFolder?.Path) ? currentStorageFolder?.Path ?? string.Empty : rootFolder.Path, FileSize = null, FileSizeBytes = 0, }; if (library is null) - currentFolder.ItemDateCreatedReal = rootFolder.DateCreated; + currentFolder.ItemDateCreatedReal = rootFolder?.DateCreated ?? DateTimeOffset.Now; CurrentFolder = currentFolder; await EnumFromStorageFolderAsync(path, rootFolder, currentStorageFolder, cancellationToken); From 305b1b985b67e13532c25ec66660e5e98b4e40f4 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Fri, 12 May 2023 15:57:49 +0900 Subject: [PATCH 10/10] Added missing using --- src/Files.App/Helpers/BitmapHelper.cs | 2 ++ src/Files.App/Helpers/FileOperationsHelpers.cs | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/Files.App/Helpers/BitmapHelper.cs b/src/Files.App/Helpers/BitmapHelper.cs index 1c7bce7a96b4..253922d3b6dd 100644 --- a/src/Files.App/Helpers/BitmapHelper.cs +++ b/src/Files.App/Helpers/BitmapHelper.cs @@ -1,7 +1,9 @@ using Files.App.Filesystem; using Files.App.Filesystem.StorageItems; using Microsoft.UI.Xaml.Media.Imaging; +using System; using System.IO; +using System.Threading.Tasks; using Windows.Graphics.Imaging; using Windows.Storage; using Windows.Storage.Streams; diff --git a/src/Files.App/Helpers/FileOperationsHelpers.cs b/src/Files.App/Helpers/FileOperationsHelpers.cs index 2cd4ad0cef1e..c96e01789ae5 100644 --- a/src/Files.App/Helpers/FileOperationsHelpers.cs +++ b/src/Files.App/Helpers/FileOperationsHelpers.cs @@ -2,12 +2,22 @@ using Files.App.Filesystem.Security; using Files.App.Shell; using Files.Backend.Helpers; +using Files.Shared; +using Files.Shared.Enums; +using Files.Shared.Extensions; using Microsoft.Extensions.Logging; using Microsoft.Win32; +using System; using System.Collections.Concurrent; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; using System.IO; +using System.Linq; using System.Runtime.InteropServices; using System.Security.Principal; +using System.Threading; +using System.Threading.Tasks; using Tulpep.ActiveDirectoryObjectPicker; using Vanara.PInvoke; using Vanara.Windows.Shell;