@@ -23,6 +23,8 @@ namespace Files.App.Storage
2323 /// </remarks>
2424 public unsafe class JumpListManager : IDisposable
2525 {
26+ private static readonly Lock _updateJumpListLock = new ( ) ;
27+
2628 private string _aumid = null ! ;
2729 private string _exeAlias = null ! ;
2830 private string _recentCategoryName = null ! ;
@@ -36,14 +38,14 @@ public unsafe class JumpListManager : IDisposable
3638
3739 private JumpListManager ( ) { }
3840
39- public static JumpListManager ? Create ( string amuid , string exeAlias )
41+ public static JumpListManager ? Create ( string aumid , string exeAlias )
4042 {
4143 var categoryName = WindowsStorableHelpers . ResolveIndirectString ( $ "@{{{WindowsStorableHelpers.GetEnvironmentVariable(" SystemRoot")}\\ SystemResources\\ Windows.UI.ShellCommon\\ Windows.UI.ShellCommon.pri? ms-resource://Windows.UI.ShellCommon/JumpViewUI/JumpViewCategoryType_Recent}}" ) ;
4244 if ( categoryName is null ) return null ;
4345
4446 return new JumpListManager ( )
4547 {
46- _aumid = amuid ,
48+ _aumid = aumid ,
4749 _exeAlias = exeAlias ,
4850 _recentCategoryName = categoryName ,
4951 } ;
@@ -111,12 +113,12 @@ public HRESULT PullJumpListFromExplorer(int maxCount = 200)
111113 if ( FAILED ( hr ) ) continue ;
112114
113115 // Get an instance of IShellLinkW from the IShellItem instance
114- IShellLinkW * psl = default ;
115- hr = CreateLinkFromItem ( psi . Get ( ) , & psl ) ;
116+ using ComPtr < IShellLinkW > psl = default ;
117+ hr = CreateLinkFromItem ( psi . Get ( ) , psl . GetAddressOf ( ) ) ;
116118 if ( FAILED ( hr ) ) continue ;
117119
118120 // Pin it to the Files' Automatic Destinations
119- hr = pFilesADL . Get ( ) ->PinItem ( ( IUnknown * ) psl , pinIndex ) ;
121+ hr = pFilesADL . Get ( ) ->PinItem ( ( IUnknown * ) psl . Get ( ) , pinIndex ) ;
120122 if ( FAILED ( hr ) ) continue ;
121123 }
122124
@@ -147,12 +149,12 @@ public HRESULT PullJumpListFromExplorer(int maxCount = 200)
147149 if ( SUCCEEDED ( hr ) ) continue ; // If not pinned, HRESULT is E_NOT_SET
148150
149151 // Get an instance of IShellLinkW from the IShellItem instance
150- IShellLinkW * psl = default ;
151- hr = CreateLinkFromItem ( psi . Get ( ) , & psl ) ;
152+ using ComPtr < IShellLinkW > psl = default ;
153+ hr = CreateLinkFromItem ( psi . Get ( ) , psl . GetAddressOf ( ) ) ;
152154 if ( FAILED ( hr ) ) continue ;
153155
154156 // Add it to the Files' Custom Destinations
155- hr = pNewObjectCollection . Get ( ) ->AddObject ( ( IUnknown * ) psl ) ;
157+ hr = pNewObjectCollection . Get ( ) ->AddObject ( ( IUnknown * ) psl . Get ( ) ) ;
156158 if ( FAILED ( hr ) ) continue ;
157159 }
158160
@@ -224,7 +226,8 @@ public HRESULT PushJumpListToExplorer(int maxCount = 200)
224226
225227 // Get the count of categories in the Files' Custom Destinations
226228 uint count = 0U ;
227- pFilesICDL . Get ( ) ->GetCategoryCount ( & count ) ;
229+ hr = pFilesICDL . Get ( ) ->GetCategoryCount ( & count ) ;
230+ if ( FAILED ( hr ) ) return hr ;
228231
229232 // Find the "Recent" category index
230233 uint indexOfRecentCategory = 0U ;
@@ -254,6 +257,7 @@ category.Type is not APPDESTCATEGORYTYPE.CUSTOM ||
254257 // Get the items in the "Recent" category
255258 using ComPtr < IObjectCollection > poc = default ;
256259 hr = pFilesICDL . Get ( ) ->EnumerateCategoryDestinations ( indexOfRecentCategory , IID . IID_IObjectCollection , ( void * * ) poc . GetAddressOf ( ) ) ;
260+ if ( FAILED ( hr ) ) return hr ;
257261
258262 // Get the count of items in the "Recent" category
259263 uint countOfItems = 0U ;
@@ -274,6 +278,7 @@ category.Type is not APPDESTCATEGORYTYPE.CUSTOM ||
274278 using ComHeapPtr < char > pszParseablePath = default ;
275279 pszParseablePath . Allocate ( PInvoke . MAX_PATH ) ;
276280 hr = psl . Get ( ) ->GetArguments ( pszParseablePath . Get ( ) , ( int ) PInvoke . MAX_PATH ) ;
281+ if ( FAILED ( hr ) ) continue ;
277282
278283 using ComHeapPtr < IShellItem > psi = default ;
279284 hr = PInvoke . SHCreateItemFromParsingName ( pszParseablePath . Get ( ) , null , IID . IID_IShellItem , ( void * * ) psi . GetAddressOf ( ) ) ;
@@ -308,6 +313,7 @@ category.Type is not APPDESTCATEGORYTYPE.CUSTOM ||
308313 using ComHeapPtr < char > pszParseablePath = default ;
309314 pszParseablePath . Allocate ( PInvoke . MAX_PATH ) ;
310315 hr = psl . Get ( ) ->GetArguments ( pszParseablePath . Get ( ) , ( int ) PInvoke . MAX_PATH ) ;
316+ if ( FAILED ( hr ) ) continue ;
311317
312318 using ComHeapPtr < IShellItem > psi = default ;
313319 hr = PInvoke . SHCreateItemFromParsingName ( pszParseablePath . Get ( ) , null , IID . IID_IShellItem , ( void * * ) psi . GetAddressOf ( ) ) ;
@@ -491,33 +497,42 @@ private HRESULT GetFolderIconLocation(IShellItem* psi, PWSTR* pIconFilePath, uin
491497
492498 private void ExplorerJumpListWatcher_Changed ( object sender , FileSystemEventArgs e )
493499 {
494- ExplorerJumpListChanged ? . Invoke ( this , EventArgs . Empty ) ;
495- PullJumpListFromExplorer ( ) ;
500+ lock ( _updateJumpListLock )
501+ {
502+ ExplorerJumpListChanged ? . Invoke ( this , EventArgs . Empty ) ;
503+ PullJumpListFromExplorer ( ) ;
504+ }
496505 }
497506
498507 private void FilesJumpListWatcher_Changed ( object sender , FileSystemEventArgs e )
499508 {
500- FilesJumpListChanged ? . Invoke ( this , EventArgs . Empty ) ;
501- PushJumpListToExplorer ( ) ;
509+ lock ( _updateJumpListLock )
510+ {
511+ FilesJumpListChanged ? . Invoke ( this , EventArgs . Empty ) ;
512+ PushJumpListToExplorer ( ) ;
513+ }
502514 }
503515
504516 public void Dispose ( )
505517 {
506518 if ( _explorerADLStoreFileWatcher is not null )
507519 {
508520 _explorerADLStoreFileWatcher . EnableRaisingEvents = false ;
521+ _explorerADLStoreFileWatcher . Changed -= ExplorerJumpListWatcher_Changed ;
509522 _explorerADLStoreFileWatcher . Dispose ( ) ;
510523 }
511524
512525 if ( _filesADLStoreFileWatcher is not null )
513526 {
514527 _filesADLStoreFileWatcher . EnableRaisingEvents = false ;
528+ _filesADLStoreFileWatcher . Changed -= FilesJumpListWatcher_Changed ;
515529 _filesADLStoreFileWatcher . Dispose ( ) ;
516530 }
517531
518532 if ( _filesCDLStoreFileWatcher is not null )
519533 {
520534 _filesCDLStoreFileWatcher . EnableRaisingEvents = false ;
535+ _filesCDLStoreFileWatcher . Changed -= FilesJumpListWatcher_Changed ;
521536 _filesCDLStoreFileWatcher . Dispose ( ) ;
522537 }
523538 }
0 commit comments