@@ -259,19 +259,20 @@ public async Task AddItemToSidebarAsync(string path)
259259 {
260260 var item = await FilesystemTasks . Wrap ( ( ) => DrivesManager . GetRootFromPathAsync ( path ) ) ;
261261 var res = await FilesystemTasks . Wrap ( ( ) => StorageFileExtensions . DangerousGetFolderFromPathAsync ( path , item ) ) ;
262- if ( res || ( FilesystemResult ) FolderHelpers . CheckFolderAccessWithWin32 ( path ) )
262+ var lastItem = favoriteSection . ChildItems . LastOrDefault ( x => x . ItemType == NavigationControlItemType . Location && ! x . Path . Equals ( CommonPaths . RecycleBinPath ) ) ;
263+ int insertIndex = lastItem != null ? favoriteSection . ChildItems . IndexOf ( lastItem ) + 1 : 0 ;
264+ var locationItem = new LocationItem
263265 {
264- var lastItem = favoriteSection . ChildItems . LastOrDefault ( x => x . ItemType == NavigationControlItemType . Location && ! x . Path . Equals ( CommonPaths . RecycleBinPath ) ) ;
265- int insertIndex = lastItem != null ? favoriteSection . ChildItems . IndexOf ( lastItem ) + 1 : 0 ;
266- var locationItem = new LocationItem
267- {
268- Font = MainViewModel . FontName ,
269- Path = path ,
270- Section = SectionType . Favorites ,
271- IsDefaultLocation = false ,
272- Text = res . Result ? . DisplayName ?? Path . GetFileName ( path . TrimEnd ( '\\ ' ) )
273- } ;
266+ Font = MainViewModel . FontName ,
267+ Path = path ,
268+ Section = SectionType . Favorites ,
269+ IsDefaultLocation = false ,
270+ Text = res . Result ? . DisplayName ?? Path . GetFileName ( path . TrimEnd ( '\\ ' ) )
271+ } ;
274272
273+ if ( res || ( FilesystemResult ) FolderHelpers . CheckFolderAccessWithWin32 ( path ) )
274+ {
275+ locationItem . IsInvalid = false ;
275276 if ( res )
276277 {
277278 var iconData = await FileThumbnailHelper . LoadIconFromStorageItemAsync ( res . Result , 24u , Windows . Storage . FileProperties . ThumbnailMode . ListView ) ;
@@ -290,16 +291,17 @@ public async Task AddItemToSidebarAsync(string path)
290291 locationItem . Icon = await CoreApplication . MainView . DispatcherQueue . EnqueueAsync ( ( ) => locationItem . IconData . ToBitmapAsync ( ) ) ;
291292 }
292293 }
293-
294- if ( ! favoriteSection . ChildItems . Any ( x => x . Path == locationItem . Path ) )
295- {
296- await CoreApplication . MainView . DispatcherQueue . EnqueueAsync ( ( ) => favoriteSection . ChildItems . Insert ( insertIndex , locationItem ) ) ;
297- }
298294 }
299295 else
300296 {
301- Debug . WriteLine ( $ "Pinned item was invalid and will be removed from the file lines list soon: { res . ErrorCode } ") ;
302- RemoveItem ( path ) ;
297+ locationItem . Icon = await CoreApplication . MainView . DispatcherQueue . EnqueueAsync ( ( ) => UIHelpers . GetIconResource ( Constants . ImageRes . Folder ) ) ;
298+ locationItem . IsInvalid = true ;
299+ Debug . WriteLine ( $ "Pinned item was invalid { res . ErrorCode } , item: { path } ") ;
300+ }
301+
302+ if ( ! favoriteSection . ChildItems . Any ( x => x . Path == locationItem . Path ) )
303+ {
304+ await CoreApplication . MainView . DispatcherQueue . EnqueueAsync ( ( ) => favoriteSection . ChildItems . Insert ( insertIndex , locationItem ) ) ;
303305 }
304306 }
305307
0 commit comments