From 48686a0b2c28f6959f3de4ba122ab97b13b40de7 Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Mon, 15 Dec 2025 16:11:31 +0000 Subject: [PATCH 1/4] Fix: Added null checks for ShellViewModel in navigation helpers --- .../Helpers/Navigation/NavigationHelpers.cs | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/Files.App/Helpers/Navigation/NavigationHelpers.cs b/src/Files.App/Helpers/Navigation/NavigationHelpers.cs index 0723bc313e09..c2910b6140be 100644 --- a/src/Files.App/Helpers/Navigation/NavigationHelpers.cs +++ b/src/Files.App/Helpers/Navigation/NavigationHelpers.cs @@ -341,7 +341,8 @@ public static Task LaunchNewWindowAsync() public static async Task OpenSelectedItemsAsync(IShellPage associatedInstance, bool openViaApplicationPicker = false) { // Don't open files and folders inside recycle bin - if (associatedInstance.ShellViewModel.WorkingDirectory.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal) || + if (associatedInstance.ShellViewModel is null || + associatedInstance.ShellViewModel.WorkingDirectory.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal) || associatedInstance.SlimContentPage?.SelectedItems is null) { return; @@ -378,7 +379,8 @@ public static async Task OpenSelectedItemsAsync(IShellPage associatedInstance, b public static async Task OpenItemsWithExecutableAsync(IShellPage associatedInstance, IEnumerable items, string executablePath) { // Don't open files and folders inside recycle bin - if (associatedInstance.ShellViewModel.WorkingDirectory.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal) || + if (associatedInstance.ShellViewModel is null || + associatedInstance.ShellViewModel.WorkingDirectory.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal) || associatedInstance.SlimContentPage is null) return; @@ -398,6 +400,9 @@ public static async Task OpenItemsWithExecutableAsync(IShellPage associatedInsta /// Open folders in a new tab regardless of the "OpenFoldersInNewTab" option public static async Task OpenPath(string path, IShellPage associatedInstance, FilesystemItemType? itemType = null, bool openSilent = false, bool openViaApplicationPicker = false, IEnumerable? selectItems = null, string? args = default, bool forceOpenInNewTab = false) { + if (associatedInstance.ShellViewModel is null) + return false; + string previousDir = associatedInstance.ShellViewModel.WorkingDirectory; bool isHiddenItem = Win32Helper.HasFileAttribute(path, System.IO.FileAttributes.Hidden); bool isDirectory = Win32Helper.HasFileAttribute(path, System.IO.FileAttributes.Directory); @@ -550,13 +555,16 @@ private static async Task OpenDirectory(string path, IShellPag } else { - opened = await associatedInstance.ShellViewModel.GetFolderWithPathFromPathAsync(path) - .OnSuccess((childFolder) => - { - // Add location to Recent Items List - if (childFolder.Item is SystemStorageFolder) - WindowsRecentItemsService.Add(childFolder.Path); - }); + if (associatedInstance.ShellViewModel is not null) + { + opened = await associatedInstance.ShellViewModel.GetFolderWithPathFromPathAsync(path) + .OnSuccess((childFolder) => + { + // Add location to Recent Items List + if (childFolder.Item is SystemStorageFolder) + WindowsRecentItemsService.Add(childFolder.Path); + }); + } if (!opened) opened = (FilesystemResult)FolderHelpers.CheckFolderAccessWithWin32(path); @@ -582,7 +590,7 @@ private static async Task OpenFile(string path, IShellPage ass } else { - if (!FileExtensionHelpers.IsWebLinkFile(path)) + if (!FileExtensionHelpers.IsWebLinkFile(path) && associatedInstance.ShellViewModel is not null) { StorageFileWithPath childFile = await associatedInstance.ShellViewModel.GetFileWithPathFromPathAsync(shortcutInfo.TargetPath); // Add location to Recent Items List @@ -599,9 +607,11 @@ private static async Task OpenFile(string path, IShellPage ass } else { - opened = await associatedInstance.ShellViewModel.GetFileWithPathFromPathAsync(path) - .OnSuccess(async childFile => - { + if (associatedInstance.ShellViewModel is not null) + { + opened = await associatedInstance.ShellViewModel.GetFileWithPathFromPathAsync(path) + .OnSuccess(async childFile => + { // Add location to Recent Items List if (childFile.Item is SystemStorageFile) WindowsRecentItemsService.Add(childFile.Path); @@ -627,7 +637,9 @@ private static async Task OpenFile(string path, IShellPage ass bool launchSuccess = false; BaseStorageFileQueryResult? fileQueryResult = null; //Get folder to create a file query (to pass to apps like Photos, Movies & TV..., needed to scroll through the folder like what Windows Explorer does) - BaseStorageFolder currentFolder = await associatedInstance.ShellViewModel.GetFolderFromPathAsync(PathNormalization.GetParentDir(path)); + BaseStorageFolder? currentFolder = associatedInstance.ShellViewModel is not null + ? await associatedInstance.ShellViewModel.GetFolderFromPathAsync(PathNormalization.GetParentDir(path)) + : null; if (currentFolder is not null) { QueryOptions queryOptions = new(CommonFileQuery.DefaultQuery, null); @@ -692,6 +704,7 @@ private static async Task OpenFile(string path, IShellPage ass } } }); + } } return opened; } From 78f8297e809cfea43122abe0ff0d8a38e93914f5 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Tue, 23 Dec 2025 10:38:43 -0500 Subject: [PATCH 2/4] Update src/Files.App/Helpers/Navigation/NavigationHelpers.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/Navigation/NavigationHelpers.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Files.App/Helpers/Navigation/NavigationHelpers.cs b/src/Files.App/Helpers/Navigation/NavigationHelpers.cs index c2910b6140be..e985351eb8b3 100644 --- a/src/Files.App/Helpers/Navigation/NavigationHelpers.cs +++ b/src/Files.App/Helpers/Navigation/NavigationHelpers.cs @@ -607,9 +607,9 @@ private static async Task OpenFile(string path, IShellPage ass } else { - if (associatedInstance.ShellViewModel is not null) + if (associatedInstance.ShellViewModel is not null shellViewModel) { - opened = await associatedInstance.ShellViewModel.GetFileWithPathFromPathAsync(path) + opened = await shellViewModel.GetFileWithPathFromPathAsync(path) .OnSuccess(async childFile => { // Add location to Recent Items List From 901b0628b6577c45c73ca5e63f8f6b50c32fd692 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Tue, 23 Dec 2025 10:38:49 -0500 Subject: [PATCH 3/4] Update src/Files.App/Helpers/Navigation/NavigationHelpers.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/Navigation/NavigationHelpers.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Files.App/Helpers/Navigation/NavigationHelpers.cs b/src/Files.App/Helpers/Navigation/NavigationHelpers.cs index e985351eb8b3..4caa139f3156 100644 --- a/src/Files.App/Helpers/Navigation/NavigationHelpers.cs +++ b/src/Files.App/Helpers/Navigation/NavigationHelpers.cs @@ -637,9 +637,7 @@ private static async Task OpenFile(string path, IShellPage ass bool launchSuccess = false; BaseStorageFileQueryResult? fileQueryResult = null; //Get folder to create a file query (to pass to apps like Photos, Movies & TV..., needed to scroll through the folder like what Windows Explorer does) - BaseStorageFolder? currentFolder = associatedInstance.ShellViewModel is not null - ? await associatedInstance.ShellViewModel.GetFolderFromPathAsync(PathNormalization.GetParentDir(path)) - : null; + BaseStorageFolder currentFolder = await shellViewModel.GetFolderFromPathAsync(PathNormalization.GetParentDir(path)); if (currentFolder is not null) { QueryOptions queryOptions = new(CommonFileQuery.DefaultQuery, null); From c3ad7eadcffdc6fa99b223ad1d7433775cfc6439 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Tue, 23 Dec 2025 12:25:43 -0500 Subject: [PATCH 4/4] Update NavigationHelpers.cs --- src/Files.App/Helpers/Navigation/NavigationHelpers.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Files.App/Helpers/Navigation/NavigationHelpers.cs b/src/Files.App/Helpers/Navigation/NavigationHelpers.cs index 4caa139f3156..a89d71ad5d8f 100644 --- a/src/Files.App/Helpers/Navigation/NavigationHelpers.cs +++ b/src/Files.App/Helpers/Navigation/NavigationHelpers.cs @@ -607,8 +607,10 @@ private static async Task OpenFile(string path, IShellPage ass } else { - if (associatedInstance.ShellViewModel is not null shellViewModel) + if (associatedInstance.ShellViewModel is not null) { + var shellViewModel = associatedInstance.ShellViewModel; + opened = await shellViewModel.GetFileWithPathFromPathAsync(path) .OnSuccess(async childFile => {