Skip to content

Commit b549af2

Browse files
Fix: Handle redirected AppData folders without Windows system directories (#17518)
Co-authored-by: seer-by-sentry[bot] <157164994+seer-by-sentry[bot]@users.noreply.github.com>
1 parent d065d23 commit b549af2

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

src/Files.App/Services/Windows/WindowsJumpListService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ public async Task RefreshPinnedFoldersAsync()
7979
{
8080
try
8181
{
82-
App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = false;
82+
if (App.QuickAccessManager.PinnedItemsWatcher is not null)
83+
App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = false;
8384

8485
if (JumpList.IsSupported())
8586
{
@@ -101,7 +102,8 @@ public async Task RefreshPinnedFoldersAsync()
101102
}
102103
finally
103104
{
104-
SafetyExtensions.IgnoreExceptions(() => App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = true);
105+
if (App.QuickAccessManager.PinnedItemsWatcher is not null)
106+
SafetyExtensions.IgnoreExceptions(() => App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = true);
105107
}
106108
}
107109

src/Files.App/Services/Windows/WindowsQuickAccessService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ public async Task SaveAsync(string[] items)
9595
if (Equals(items, App.QuickAccessManager.Model.PinnedFolders.ToArray()))
9696
return;
9797

98-
App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = false;
98+
if (App.QuickAccessManager.PinnedItemsWatcher is not null)
99+
App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = false;
99100

100101
// Unpin every item that is below this index and then pin them all in order
101102
await UnpinFromSidebarAsync([], false);
102103

103104
await PinToSidebarAsync(items, false);
104-
App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = true;
105+
if (App.QuickAccessManager.PinnedItemsWatcher is not null)
106+
App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = true;
105107

106108
App.QuickAccessManager.UpdateQuickAccessWidget?.Invoke(this, new ModifyQuickAccessEventArgs(items, true)
107109
{

src/Files.App/Utils/Global/QuickAccessManager.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,27 @@ public QuickAccessManager()
2525

2626
public void Initialize()
2727
{
28-
PinnedItemsWatcher = new()
28+
var automaticDestinationsPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Microsoft", "Windows", "Recent", "AutomaticDestinations");
29+
30+
// Only initialize FileSystemWatcher if the directory exists
31+
// This handles cases where AppData is redirected to network locations that don't contain Windows system directories
32+
if (Directory.Exists(automaticDestinationsPath))
2933
{
30-
Path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Microsoft", "Windows", "Recent", "AutomaticDestinations"),
31-
Filter = "f01b4d95cf55d32a.automaticDestinations-ms",
32-
NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName
33-
};
34-
35-
PinnedItemsWatcher.Changed += PinnedItemsWatcher_Changed;
34+
PinnedItemsWatcher = new()
35+
{
36+
Path = automaticDestinationsPath,
37+
Filter = "f01b4d95cf55d32a.automaticDestinations-ms",
38+
NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName
39+
};
40+
41+
PinnedItemsWatcher.Changed += PinnedItemsWatcher_Changed;
42+
}
43+
else
44+
{
45+
// If the directory doesn't exist (e.g., redirected AppData), skip FileSystemWatcher initialization
46+
// The app will still function, but won't receive automatic updates when pinned items change externally
47+
PinnedItemsWatcher = null;
48+
}
3649
}
3750

3851
private void PinnedItemsWatcher_Changed(object sender, FileSystemEventArgs e)

0 commit comments

Comments
 (0)