Skip to content

Commit 23abb36

Browse files
committed
Correct the execution path
1 parent 816fcdc commit 23abb36

File tree

4 files changed

+52
-41
lines changed

4 files changed

+52
-41
lines changed

src/Files.App.BackgroundTasks/UpdateTask.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,15 @@ private void DeleteLogFiles()
3535
private void RefreshJumpList()
3636
{
3737
// Make sure to delete the Files' custom destinations binary files
38-
var recentFolder = JumpListManager.Default.GetRecentFolderPath();
38+
var recentFolder = WindowsStorableHelpers.GetRecentFolderPath();
3939
File.Delete($"{recentFolder}\\CustomDestinations\\3b19d860a346d7da.customDestinations-ms");
4040
File.Delete($"{recentFolder}\\CustomDestinations\\1265066178db259d.customDestinations-ms");
4141
File.Delete($"{recentFolder}\\CustomDestinations\\8e2322986488aba5.customDestinations-ms");
4242
File.Delete($"{recentFolder}\\CustomDestinations\\6b0bf5ca007c8bea.customDestinations-ms");
43-
File.Delete($"{recentFolder}\\AutomaticDestinations\\3b19d860a346d7da.customDestinations-ms");
44-
File.Delete($"{recentFolder}\\AutomaticDestinations\\1265066178db259d.customDestinations-ms");
45-
File.Delete($"{recentFolder}\\AutomaticDestinations\\8e2322986488aba5.customDestinations-ms");
46-
File.Delete($"{recentFolder}\\AutomaticDestinations\\6b0bf5ca007c8bea.customDestinations-ms");
47-
48-
_ = STATask.Run(() =>
49-
{
50-
JumpListManager.Default.PullJumpListFromExplorer();
51-
});
43+
File.Delete($"{recentFolder}\\AutomaticDestinations\\3b19d860a346d7da.automaticDestinations-ms");
44+
File.Delete($"{recentFolder}\\AutomaticDestinations\\1265066178db259d.automaticDestinations-ms");
45+
File.Delete($"{recentFolder}\\AutomaticDestinations\\8e2322986488aba5.automaticDestinations-ms");
46+
File.Delete($"{recentFolder}\\AutomaticDestinations\\6b0bf5ca007c8bea.automaticDestinations-ms");
5247
}
5348
}
5449
}

src/Files.App.Storage/Windows/Helpers/WindowsStorableHelpers.Storage.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,12 @@ public static bool TryRenameVolumeLabel(string path, string newLabel)
9191

9292
return false;
9393
}
94+
95+
public static string GetRecentFolderPath()
96+
{
97+
using ComHeapPtr<char> pwszRecentFolderPath = default;
98+
PInvoke.SHGetKnownFolderPath(FOLDERID.FOLDERID_Recent, KNOWN_FOLDER_FLAG.KF_FLAG_DONT_VERIFY | KNOWN_FOLDER_FLAG.KF_FLAG_NO_ALIAS, HANDLE.Null, (PWSTR*)pwszRecentFolderPath.GetAddressOf());
99+
return new(pwszRecentFolderPath.Get());
100+
}
94101
}
95102
}

src/Files.App.Storage/Windows/Managers/JumpListManager.cs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
using System.IO;
55
using System.Runtime.CompilerServices;
6-
using Windows.ApplicationModel;
7-
using Windows.Devices.Enumeration.Pnp;
86
using Windows.Win32;
97
using Windows.Win32.Foundation;
108
using 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
}

src/Files.App/Helpers/Application/AppLifecycleHelper.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,22 @@ static AppLifecycleHelper()
7474
/// Gets the value that provides application environment or branch name.
7575
/// </summary>
7676
public static AppEnvironment AppEnvironment =>
77-
Enum.TryParse("cd_app_env_placeholder", true, out AppEnvironment appEnvironment)
77+
Enum.TryParse("cd_app_env_placeholder" /* This will be replaced with an actual value by the Files CD */, true, out AppEnvironment appEnvironment)
7878
? appEnvironment
7979
: AppEnvironment.Dev;
8080

81+
/// <summary>
82+
/// Gets the executable alias associated with the current application environment.
83+
/// </summary>
84+
public static string AppExeAlias => AppEnvironment switch
85+
{
86+
AppEnvironment.SideloadStable => "files.exe",
87+
AppEnvironment.SideloadPreview => "files-preview.exe",
88+
AppEnvironment.StoreStable => "files.exe",
89+
AppEnvironment.StorePreview => "files-preview.exe",
90+
_ => "files-dev.exe", // Default to Dev
91+
};
92+
8193
/// <summary>
8294
/// Gets the CRC hash string associated with the current application environment's AppUserModelId.
8395
/// </summary>
@@ -151,12 +163,15 @@ await Task.WhenAll(
151163

152164
_ = STATask.Run(() =>
153165
{
154-
HRESULT hr = JumpListManager.Default?.PullJumpListFromExplorer() ?? HRESULT.S_OK;
155-
if (hr.Value < 0)
156-
App.Logger.LogWarning("Failed to synchronizing jump list unexpectedly.");
166+
var manager = JumpListManager.Create($"{Package.Current.Id.FamilyName}!App", AppExeAlias);
167+
if (manager is null)
168+
return;
157169

158-
JumpListManager.Default?.WatchJumpListChanges(AppUserModelIdCrcHash);
170+
HRESULT hr = manager.PullJumpListFromExplorer();
171+
if (hr.Failed)
172+
App.Logger.LogWarning("Failed to synchronizing jump list unexpectedly.");
159173

174+
manager.WatchJumpListChanges(AppUserModelIdCrcHash);
160175
});
161176

162177
static Task OptionalTaskAsync(Task task, bool condition)

0 commit comments

Comments
 (0)