@@ -341,7 +341,8 @@ public static Task LaunchNewWindowAsync()
341341 public static async Task OpenSelectedItemsAsync ( IShellPage associatedInstance , bool openViaApplicationPicker = false )
342342 {
343343 // Don't open files and folders inside recycle bin
344- if ( associatedInstance . ShellViewModel . WorkingDirectory . StartsWith ( Constants . UserEnvironmentPaths . RecycleBinPath , StringComparison . Ordinal ) ||
344+ if ( associatedInstance . ShellViewModel is null ||
345+ associatedInstance . ShellViewModel . WorkingDirectory . StartsWith ( Constants . UserEnvironmentPaths . RecycleBinPath , StringComparison . Ordinal ) ||
345346 associatedInstance . SlimContentPage ? . SelectedItems is null )
346347 {
347348 return ;
@@ -378,7 +379,8 @@ public static async Task OpenSelectedItemsAsync(IShellPage associatedInstance, b
378379 public static async Task OpenItemsWithExecutableAsync ( IShellPage associatedInstance , IEnumerable < IStorageItemWithPath > items , string executablePath )
379380 {
380381 // Don't open files and folders inside recycle bin
381- if ( associatedInstance . ShellViewModel . WorkingDirectory . StartsWith ( Constants . UserEnvironmentPaths . RecycleBinPath , StringComparison . Ordinal ) ||
382+ if ( associatedInstance . ShellViewModel is null ||
383+ associatedInstance . ShellViewModel . WorkingDirectory . StartsWith ( Constants . UserEnvironmentPaths . RecycleBinPath , StringComparison . Ordinal ) ||
382384 associatedInstance . SlimContentPage is null )
383385 return ;
384386
@@ -398,6 +400,9 @@ public static async Task OpenItemsWithExecutableAsync(IShellPage associatedInsta
398400 /// <param name="forceOpenInNewTab">Open folders in a new tab regardless of the "OpenFoldersInNewTab" option</param>
399401 public static async Task < bool > OpenPath ( string path , IShellPage associatedInstance , FilesystemItemType ? itemType = null , bool openSilent = false , bool openViaApplicationPicker = false , IEnumerable < string > ? selectItems = null , string ? args = default , bool forceOpenInNewTab = false )
400402 {
403+ if ( associatedInstance . ShellViewModel is null )
404+ return false ;
405+
401406 string previousDir = associatedInstance . ShellViewModel . WorkingDirectory ;
402407 bool isHiddenItem = Win32Helper . HasFileAttribute ( path , System . IO . FileAttributes . Hidden ) ;
403408 bool isDirectory = Win32Helper . HasFileAttribute ( path , System . IO . FileAttributes . Directory ) ;
@@ -550,13 +555,16 @@ private static async Task<FilesystemResult> OpenDirectory(string path, IShellPag
550555 }
551556 else
552557 {
553- opened = await associatedInstance . ShellViewModel . GetFolderWithPathFromPathAsync ( path )
554- . OnSuccess ( ( childFolder ) =>
555- {
556- // Add location to Recent Items List
557- if ( childFolder . Item is SystemStorageFolder )
558- WindowsRecentItemsService . Add ( childFolder . Path ) ;
559- } ) ;
558+ if ( associatedInstance . ShellViewModel is not null )
559+ {
560+ opened = await associatedInstance . ShellViewModel . GetFolderWithPathFromPathAsync ( path )
561+ . OnSuccess ( ( childFolder ) =>
562+ {
563+ // Add location to Recent Items List
564+ if ( childFolder . Item is SystemStorageFolder )
565+ WindowsRecentItemsService . Add ( childFolder . Path ) ;
566+ } ) ;
567+ }
560568 if ( ! opened )
561569 opened = ( FilesystemResult ) FolderHelpers . CheckFolderAccessWithWin32 ( path ) ;
562570
@@ -582,7 +590,7 @@ private static async Task<FilesystemResult> OpenFile(string path, IShellPage ass
582590 }
583591 else
584592 {
585- if ( ! FileExtensionHelpers . IsWebLinkFile ( path ) )
593+ if ( ! FileExtensionHelpers . IsWebLinkFile ( path ) && associatedInstance . ShellViewModel is not null )
586594 {
587595 StorageFileWithPath childFile = await associatedInstance . ShellViewModel . GetFileWithPathFromPathAsync ( shortcutInfo . TargetPath ) ;
588596 // Add location to Recent Items List
@@ -599,9 +607,13 @@ private static async Task<FilesystemResult> OpenFile(string path, IShellPage ass
599607 }
600608 else
601609 {
602- opened = await associatedInstance . ShellViewModel . GetFileWithPathFromPathAsync ( path )
603- . OnSuccess ( async childFile =>
604- {
610+ if ( associatedInstance . ShellViewModel is not null )
611+ {
612+ var shellViewModel = associatedInstance . ShellViewModel ;
613+
614+ opened = await shellViewModel . GetFileWithPathFromPathAsync ( path )
615+ . OnSuccess ( async childFile =>
616+ {
605617 // Add location to Recent Items List
606618 if ( childFile . Item is SystemStorageFile )
607619 WindowsRecentItemsService . Add ( childFile . Path ) ;
@@ -627,7 +639,7 @@ private static async Task<FilesystemResult> OpenFile(string path, IShellPage ass
627639 bool launchSuccess = false ;
628640 BaseStorageFileQueryResult ? fileQueryResult = null ;
629641 //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)
630- BaseStorageFolder currentFolder = await associatedInstance . ShellViewModel . GetFolderFromPathAsync ( PathNormalization . GetParentDir ( path ) ) ;
642+ BaseStorageFolder currentFolder = await shellViewModel . GetFolderFromPathAsync ( PathNormalization . GetParentDir ( path ) ) ;
631643 if ( currentFolder is not null )
632644 {
633645 QueryOptions queryOptions = new ( CommonFileQuery . DefaultQuery , null ) ;
@@ -692,6 +704,7 @@ private static async Task<FilesystemResult> OpenFile(string path, IShellPage ass
692704 }
693705 }
694706 } ) ;
707+ }
695708 }
696709 return opened ;
697710 }
0 commit comments