From de932658ace490140b7a9a9687df8419555ef696 Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Mon, 10 Nov 2025 00:20:16 +0000 Subject: [PATCH 1/4] Fix: Prevent crash when default layout preferences are applied to empty paths --- src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs | 8 ++++++++ src/Files.App/ViewModels/ShellViewModel.cs | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs b/src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs index cb372d9e33d9..d3fd04566e71 100644 --- a/src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs +++ b/src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs @@ -310,6 +310,10 @@ public void ToggleLayoutModeAdaptive() public void OnDefaultPreferencesChanged(string path, string settingsName) { + // Guard against null or empty path + if (string.IsNullOrWhiteSpace(path)) + return; + var preferencesItem = GetLayoutPreferencesForPath(path); if (preferencesItem is null) return; @@ -486,6 +490,10 @@ public static void SetLayoutPreferencesForPath(string path, LayoutPreferencesIte private static LayoutPreferencesItem? GetLayoutPreferencesForPath(string path) { + // Guard against null or empty paths + if (string.IsNullOrWhiteSpace(path)) + return new LayoutPreferencesItem(); + //Recycle Bin does not support Column View due to navigation conflicts with hierarchical display //Fall back to Details View when Column View is configured if (path.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal)) diff --git a/src/Files.App/ViewModels/ShellViewModel.cs b/src/Files.App/ViewModels/ShellViewModel.cs index e5bd26e0a617..ff2a72359b79 100644 --- a/src/Files.App/ViewModels/ShellViewModel.cs +++ b/src/Files.App/ViewModels/ShellViewModel.cs @@ -707,8 +707,12 @@ await dispatcherQueue.EnqueueOrInvokeAsync(() => case nameof(UserSettingsService.LayoutSettingsService.DefaultLayoutMode): await dispatcherQueue.EnqueueOrInvokeAsync(() => { - folderSettings.OnDefaultPreferencesChanged(WorkingDirectory, e.SettingName); - UpdateSortAndGroupOptions(); + // Only update preferences if WorkingDirectory is initialized + if (!string.IsNullOrWhiteSpace(WorkingDirectory)) + { + folderSettings.OnDefaultPreferencesChanged(WorkingDirectory, e.SettingName); + UpdateSortAndGroupOptions(); + } }); await OrderFilesAndFoldersAsync(); await ApplyFilesAndFoldersChangesAsync(); From 5a22f3783ec3f86682112ca22cf44259c3b36cd1 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 12 Nov 2025 09:40:09 -0500 Subject: [PATCH 2/4] Update src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs Co-authored-by: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Signed-off-by: Yair <39923744+yaira2@users.noreply.github.com> --- src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs b/src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs index d3fd04566e71..e5e5ef7ff0ae 100644 --- a/src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs +++ b/src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs @@ -490,9 +490,9 @@ public static void SetLayoutPreferencesForPath(string path, LayoutPreferencesIte private static LayoutPreferencesItem? GetLayoutPreferencesForPath(string path) { - // Guard against null or empty paths - if (string.IsNullOrWhiteSpace(path)) - return new LayoutPreferencesItem(); + // Guard against null + if (path is null) + return null; //Recycle Bin does not support Column View due to navigation conflicts with hierarchical display //Fall back to Details View when Column View is configured From 4955abf0995402221bc5f97bf5c1756a7f87effb Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 12 Nov 2025 09:40:22 -0500 Subject: [PATCH 3/4] Update src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs Co-authored-by: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Signed-off-by: Yair <39923744+yaira2@users.noreply.github.com> --- src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs b/src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs index e5e5ef7ff0ae..866cedd4f4bb 100644 --- a/src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs +++ b/src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs @@ -310,10 +310,6 @@ public void ToggleLayoutModeAdaptive() public void OnDefaultPreferencesChanged(string path, string settingsName) { - // Guard against null or empty path - if (string.IsNullOrWhiteSpace(path)) - return; - var preferencesItem = GetLayoutPreferencesForPath(path); if (preferencesItem is null) return; From 558d32a4af2ded648e40edc740a6fb017da6f9db Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Wed, 12 Nov 2025 09:40:32 -0500 Subject: [PATCH 4/4] Update src/Files.App/ViewModels/ShellViewModel.cs Co-authored-by: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Signed-off-by: Yair <39923744+yaira2@users.noreply.github.com> --- src/Files.App/ViewModels/ShellViewModel.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Files.App/ViewModels/ShellViewModel.cs b/src/Files.App/ViewModels/ShellViewModel.cs index ff2a72359b79..e5bd26e0a617 100644 --- a/src/Files.App/ViewModels/ShellViewModel.cs +++ b/src/Files.App/ViewModels/ShellViewModel.cs @@ -707,12 +707,8 @@ await dispatcherQueue.EnqueueOrInvokeAsync(() => case nameof(UserSettingsService.LayoutSettingsService.DefaultLayoutMode): await dispatcherQueue.EnqueueOrInvokeAsync(() => { - // Only update preferences if WorkingDirectory is initialized - if (!string.IsNullOrWhiteSpace(WorkingDirectory)) - { - folderSettings.OnDefaultPreferencesChanged(WorkingDirectory, e.SettingName); - UpdateSortAndGroupOptions(); - } + folderSettings.OnDefaultPreferencesChanged(WorkingDirectory, e.SettingName); + UpdateSortAndGroupOptions(); }); await OrderFilesAndFoldersAsync(); await ApplyFilesAndFoldersChangesAsync();