@@ -104,30 +104,53 @@ public async Task<LocationItem> CreateLocationItemFromPathAsync(string path)
104104 {
105105 locationItem . IsInvalid = false ;
106106 if ( res . Result is not null )
107- {
108- var result = await FileThumbnailHelper . GetIconAsync (
109- res . Result . Path ,
110- Constants . ShellIconSizes . Small ,
111- true ,
112- IconOptions . ReturnIconOnly | IconOptions . UseCurrentScale ) ;
113-
114- locationItem . IconData = result ;
115-
116- var bitmapImage = await MainWindow . Instance . DispatcherQueue . EnqueueOrInvokeAsync ( ( ) => locationItem . IconData . ToBitmapAsync ( ) , Microsoft . UI . Dispatching . DispatcherQueuePriority . Normal ) ;
117- if ( bitmapImage is not null )
118- locationItem . Icon = bitmapImage ;
119- }
107+ _ = LoadIconForLocationItemAsync ( locationItem , res . Result . Path ) ;
120108 }
121109 else
122110 {
123- locationItem . Icon = await MainWindow . Instance . DispatcherQueue . EnqueueOrInvokeAsync ( ( ) => UIHelpers . GetSidebarIconResource ( Constants . ImageRes . Folder ) ) ;
124111 locationItem . IsInvalid = true ;
125112 Debug . WriteLine ( $ "Pinned item was invalid { res ? . ErrorCode } , item: { path } ") ;
113+ _ = LoadDefaultIconForLocationItemAsync ( locationItem ) ;
126114 }
127115
128116 return locationItem ;
129117 }
130118
119+ private async Task LoadIconForLocationItemAsync ( LocationItem locationItem , string path )
120+ {
121+ try
122+ {
123+ var result = await FileThumbnailHelper . GetIconAsync (
124+ path ,
125+ Constants . ShellIconSizes . Small ,
126+ true ,
127+ IconOptions . ReturnIconOnly | IconOptions . UseCurrentScale ) ;
128+
129+ locationItem . IconData = result ;
130+
131+ var bitmapImage = await MainWindow . Instance . DispatcherQueue . EnqueueOrInvokeAsync ( ( ) => locationItem . IconData . ToBitmapAsync ( ) , Microsoft . UI . Dispatching . DispatcherQueuePriority . Normal ) ;
132+ if ( bitmapImage is not null )
133+ locationItem . Icon = bitmapImage ;
134+ }
135+ catch ( Exception ex )
136+ {
137+ Debug . WriteLine ( $ "Error loading icon for { path } : { ex . Message } ") ;
138+ }
139+ }
140+
141+ private async Task LoadDefaultIconForLocationItemAsync ( LocationItem locationItem )
142+ {
143+ try
144+ {
145+ var defaultIcon = await MainWindow . Instance . DispatcherQueue . EnqueueOrInvokeAsync ( ( ) => UIHelpers . GetSidebarIconResource ( Constants . ImageRes . Folder ) ) ;
146+ locationItem . Icon = defaultIcon ;
147+ }
148+ catch ( Exception ex )
149+ {
150+ Debug . WriteLine ( $ "Error loading default icon: { ex . Message } ") ;
151+ }
152+ }
153+
131154 /// <summary>
132155 /// Adds the item (from a path) to the navigation sidebar
133156 /// </summary>
0 commit comments