33
44using System . IO ;
55using System . Runtime . CompilerServices ;
6- using Windows . ApplicationModel ;
7- using Windows . Devices . Enumeration . Pnp ;
86using Windows . Win32 ;
97using Windows . Win32 . Foundation ;
108using Windows . Win32 . System . Com ;
@@ -24,12 +22,9 @@ namespace Files.App.Storage
2422 /// </remarks>
2523 public unsafe class JumpListManager : IDisposable
2624 {
27- private static readonly Lazy < JumpListManager ? > _default = new ( Create , LazyThreadSafetyMode . ExecutionAndPublication ) ;
28- public static JumpListManager ? Default => _default . Value ;
29-
30- private string _filesAUMID = null ! ;
31-
32- private string _localizedRecentCategoryName = null ! ;
25+ private string _aumid = null ! ;
26+ private string _exeAlias = null ! ;
27+ private string _recentCategoryName = null ! ;
3328
3429 private FileSystemWatcher ? _explorerJumpListWatcher ;
3530 private FileSystemWatcher ? _filesJumpListWatcher ;
@@ -88,15 +83,15 @@ public bool WatchJumpListChanges(string aumidCrcHash)
8883 _explorerJumpListWatcher ? . Dispose ( ) ;
8984 _explorerJumpListWatcher = new ( )
9085 {
91- Path = $ "{ GetRecentFolderPath ( ) } \\ AutomaticDestinations",
86+ Path = $ "{ WindowsStorableHelpers . GetRecentFolderPath ( ) } \\ AutomaticDestinations",
9287 Filter = "f01b4d95cf55d32a.automaticDestinations-ms" , // Microsoft.Windows.Explorer
9388 NotifyFilter = NotifyFilters . LastWrite | NotifyFilters . FileName | NotifyFilters . CreationTime ,
9489 } ;
9590
9691 _filesJumpListWatcher ? . Dispose ( ) ;
9792 _filesJumpListWatcher = new ( )
9893 {
99- Path = $ "{ GetRecentFolderPath ( ) } \\ AutomaticDestinations",
94+ Path = $ "{ WindowsStorableHelpers . GetRecentFolderPath ( ) } \\ AutomaticDestinations",
10095 Filter = $ "{ aumidCrcHash } .automaticDestinations-ms",
10196 NotifyFilter = NotifyFilters . LastWrite | NotifyFilters . FileName | NotifyFilters . CreationTime ,
10297 } ;
@@ -119,14 +114,7 @@ public bool WatchJumpListChanges(string aumidCrcHash)
119114 return true ;
120115 }
121116
122- public string GetRecentFolderPath ( )
123- {
124- using ComHeapPtr < char > pwszRecentFolderPath = default ;
125- PInvoke . SHGetKnownFolderPath ( FOLDERID . FOLDERID_Recent , KNOWN_FOLDER_FLAG . KF_FLAG_DONT_VERIFY | KNOWN_FOLDER_FLAG . KF_FLAG_NO_ALIAS , HANDLE . Null , ( PWSTR * ) pwszRecentFolderPath . GetAddressOf ( ) ) ;
126- return new ( pwszRecentFolderPath . Get ( ) ) ;
127- }
128-
129- private static JumpListManager ? Create ( )
117+ public static JumpListManager ? Create ( string amuid , string exeAlias )
130118 {
131119 HRESULT hr = default ;
132120
@@ -135,8 +123,9 @@ public string GetRecentFolderPath()
135123
136124 var instance = new JumpListManager ( )
137125 {
138- _filesAUMID = $ "{ Package . Current . Id . FamilyName } !App",
139- _localizedRecentCategoryName = categoryName ,
126+ _aumid = amuid ,
127+ _exeAlias = exeAlias ,
128+ _recentCategoryName = categoryName ,
140129 } ;
141130
142131 void * pv = default ;
@@ -149,17 +138,17 @@ public string GetRecentFolderPath()
149138 hr = PInvoke . CoCreateInstance ( CLSID . CLSID_AutomaticDestinationList , null , CLSCTX . CLSCTX_INPROC_SERVER , IID . IID_IAutomaticDestinationList , & pv ) ;
150139 if ( FAILED ( hr ) ) return null ;
151140 instance . _filesADL = ( IAutomaticDestinationList * ) pv ;
152- instance . _filesADL ->Initialize ( ( PCWSTR ) Unsafe . AsPointer ( ref Unsafe . AsRef ( in instance . _filesAUMID . GetPinnableReference ( ) ) ) , default , default ) ;
141+ instance . _filesADL ->Initialize ( ( PCWSTR ) Unsafe . AsPointer ( ref Unsafe . AsRef ( in instance . _aumid . GetPinnableReference ( ) ) ) , default , default ) ;
153142
154143 hr = PInvoke . CoCreateInstance ( CLSID . CLSID_DestinationList , null , CLSCTX . CLSCTX_INPROC_SERVER , IID . IID_ICustomDestinationList , & pv ) ;
155144 if ( FAILED ( hr ) ) return null ;
156145 instance . _filesCDL = ( ICustomDestinationList * ) pv ;
157- instance . _filesCDL ->SetAppID ( ( PCWSTR ) Unsafe . AsPointer ( ref Unsafe . AsRef ( in instance . _filesAUMID . GetPinnableReference ( ) ) ) ) ;
146+ instance . _filesCDL ->SetAppID ( ( PCWSTR ) Unsafe . AsPointer ( ref Unsafe . AsRef ( in instance . _aumid . GetPinnableReference ( ) ) ) ) ;
158147
159148 hr = PInvoke . CoCreateInstance ( CLSID . CLSID_DestinationList , null , CLSCTX . CLSCTX_INPROC_SERVER , IID . IID_IInternalCustomDestinationList , & pv ) ;
160149 if ( FAILED ( hr ) ) return null ;
161150 instance . _filesICDL = ( IInternalCustomDestinationList * ) pv ;
162- instance . _filesICDL ->SetApplicationID ( ( PCWSTR ) Unsafe . AsPointer ( ref Unsafe . AsRef ( in instance . _filesAUMID . GetPinnableReference ( ) ) ) ) ;
151+ instance . _filesICDL ->SetApplicationID ( ( PCWSTR ) Unsafe . AsPointer ( ref Unsafe . AsRef ( in instance . _aumid . GetPinnableReference ( ) ) ) ) ;
163152
164153 return instance ;
165154 }
@@ -181,7 +170,7 @@ private HRESULT SyncFilesJumpListWithExplorer(int maxItemsToSync)
181170 }
182171
183172 // Clear the Files' Custom Destination
184- hr = _filesCDL ->DeleteList ( ( PCWSTR ) Unsafe . AsPointer ( ref Unsafe . AsRef ( in _filesAUMID . GetPinnableReference ( ) ) ) ) ;
173+ hr = _filesCDL ->DeleteList ( ( PCWSTR ) Unsafe . AsPointer ( ref Unsafe . AsRef ( in _aumid . GetPinnableReference ( ) ) ) ) ;
185174
186175 // Get the Explorer's Pinned items from its Automatic Destination
187176 using ComPtr < IObjectCollection > poc = default ;
@@ -307,7 +296,7 @@ private HRESULT SyncExplorerJumpListWithFiles(int maxItemsToSync)
307296 hr = _filesICDL ->GetCategory ( index , GETCATFLAG . DEFAULT , & category ) ;
308297 if ( FAILED ( hr ) ||
309298 category . Type is not APPDESTCATEGORYTYPE . CUSTOM ||
310- ! _localizedRecentCategoryName . Equals ( new ( category . Anonymous . Name ) , StringComparison . OrdinalIgnoreCase ) )
299+ ! _recentCategoryName . Equals ( new ( category . Anonymous . Name ) , StringComparison . OrdinalIgnoreCase ) )
311300 continue ;
312301
313302 indexOfRecentCategory = index ;
@@ -336,6 +325,10 @@ category.Type is not APPDESTCATEGORYTYPE.CUSTOM ||
336325 hr = poc . Get ( ) ->GetAt ( index , IID . IID_IShellLinkW , ( void * * ) psl . GetAddressOf ( ) ) ;
337326 if ( FAILED ( hr ) ) continue ;
338327
328+ int pinIndex ;
329+ hr = _filesADL ->GetPinIndex ( ( IUnknown * ) psl . Get ( ) , & pinIndex ) ;
330+ if ( FAILED ( hr ) ) continue ;
331+
339332 using ComHeapPtr < char > pszParseablePath = default ;
340333 pszParseablePath . Allocate ( PInvoke . MAX_PATH ) ;
341334 hr = psl . Get ( ) ->GetArguments ( pszParseablePath . Get ( ) , ( int ) PInvoke . MAX_PATH ) ;
@@ -394,7 +387,7 @@ private HRESULT CreateLinkFromItem(IShellItem* psi, IShellLinkW** ppsl)
394387 if ( FAILED ( hr ) ) return hr ;
395388
396389 // Set the Files package path in the shell namespace
397- fixed ( char * pszFilesEntryPointPath = $ "files-dev.exe" )
390+ fixed ( char * pszFilesEntryPointPath = _exeAlias )
398391 hr = psl . Get ( ) ->SetPath ( pszFilesEntryPointPath ) ;
399392 if ( FAILED ( hr ) ) return hr ;
400393
@@ -495,6 +488,7 @@ public void Dispose()
495488 if ( _explorerADL is not null ) ( ( IUnknown * ) _explorerADL ) ->Release ( ) ;
496489 if ( _filesADL is not null ) ( ( IUnknown * ) _filesADL ) ->Release ( ) ;
497490 if ( _filesCDL is not null ) ( ( IUnknown * ) _filesCDL ) ->Release ( ) ;
491+ if ( _filesICDL is not null ) ( ( IUnknown * ) _filesICDL ) ->Release ( ) ;
498492 }
499493 }
500494}
0 commit comments