Skip to content

Commit 59fc68a

Browse files
committed
DELETED ALL
1 parent 4670021 commit 59fc68a

14 files changed

+75
-194
lines changed

src/Files.App/Actions/FileSystem/EmptyRecycleBinAction.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Files.App.Actions
99
{
1010
internal sealed class EmptyRecycleBinAction : BaseUIAction, IAction
1111
{
12+
private readonly IWindowsRecycleBinService WindowsRecycleBinService = Ioc.Default.GetRequiredService<IWindowsRecycleBinService>();
1213
private readonly StatusCenterViewModel StatusCenterViewModel = Ioc.Default.GetRequiredService<StatusCenterViewModel>();
1314
private readonly IUserSettingsService UserSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
1415
private readonly IContentPageContext context;
@@ -25,7 +26,7 @@ public RichGlyph Glyph
2526
public override bool IsExecutable =>
2627
UIHelpers.CanShowDialog &&
2728
((context.PageType == ContentPageTypes.RecycleBin && context.HasItem) ||
28-
RecycleBinHelpers.RecycleBinHasItems());
29+
WindowsRecycleBinService.HasItems());
2930

3031
public EmptyRecycleBinAction()
3132
{

src/Files.App/Actions/FileSystem/RestoreAllRecycleBinAction.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace Files.App.Actions
99
{
1010
internal sealed class RestoreAllRecycleBinAction : BaseUIAction, IAction
1111
{
12+
private readonly IWindowsRecycleBinService WindowsRecycleBinService = Ioc.Default.GetRequiredService<IWindowsRecycleBinService>();
13+
1214
public string Label
1315
=> "RestoreAllItems".GetLocalizedResource();
1416

@@ -20,7 +22,7 @@ public RichGlyph Glyph
2022

2123
public override bool IsExecutable =>
2224
UIHelpers.CanShowDialog &&
23-
RecycleBinHelpers.RecycleBinHasItems();
25+
WindowsRecycleBinService.HasItems();
2426

2527
public async Task ExecuteAsync(object? parameter = null)
2628
{

src/Files.App/Data/Contracts/IWindowsRecycleBinService.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,20 @@
33

44
namespace Files.App.Data.Contracts
55
{
6-
public interface IWindowsRecycleBinService
6+
public interface IWindowsRecycleBinService : ITrashWatcher
77
{
8+
Task<List<ShellFileItem>> GetAllRecycleBinFoldersAsync();
9+
10+
ulong GetSize();
11+
12+
bool IsRecycled(string? path);
13+
14+
Task<bool> IsRecyclableAsync(string? path);
15+
16+
bool HasItems();
17+
18+
bool DeleteAll();
19+
20+
bool RestoreAll();
821
}
922
}

src/Files.App/Data/Items/LocationItem.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,13 @@ public int CompareTo(INavigationControlItem other)
123123

124124
public sealed class RecycleBinLocationItem : LocationItem
125125
{
126-
public void RefreshSpaceUsed(object sender, FileSystemEventArgs e)
126+
private readonly IWindowsRecycleBinService WindowsRecycleBinService = Ioc.Default.GetRequiredService<IWindowsRecycleBinService>();
127+
128+
public void RefreshSpaceUsed(object? sender, FileSystemEventArgs e)
127129
{
128130
MainWindow.Instance.DispatcherQueue.TryEnqueue(() =>
129131
{
130-
SpaceUsed = RecycleBinHelpers.GetSize();
132+
SpaceUsed = WindowsRecycleBinService.GetSize();
131133
});
132134
}
133135

@@ -149,10 +151,10 @@ public override object ToolTip
149151

150152
public RecycleBinLocationItem()
151153
{
152-
SpaceUsed = RecycleBinHelpers.GetSize();
154+
SpaceUsed = WindowsRecycleBinService.GetSize();
153155

154-
RecycleBinManager.Default.RecycleBinItemCreated += RefreshSpaceUsed;
155-
RecycleBinManager.Default.RecycleBinItemDeleted += RefreshSpaceUsed;
156+
WindowsRecycleBinService.ItemAdded += RefreshSpaceUsed;
157+
WindowsRecycleBinService.ItemDeleted += RefreshSpaceUsed;
156158
}
157159
}
158160
}

src/Files.App/Services/App/FileTagsService.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ namespace Files.App.Services
1111
/// <inheritdoc cref="IFileTagsService"/>
1212
internal sealed class FileTagsService : IFileTagsService
1313
{
14-
private IStorageService StorageService { get; } = Ioc.Default.GetRequiredService<IStorageService>();
15-
16-
private IFileTagsSettingsService FileTagsSettingsService { get; } = Ioc.Default.GetRequiredService<IFileTagsSettingsService>();
14+
private readonly IWindowsRecycleBinService WindowsRecycleBinService = Ioc.Default.GetRequiredService<IWindowsRecycleBinService>();
15+
private readonly IFileTagsSettingsService FileTagsSettingsService = Ioc.Default.GetRequiredService<IFileTagsSettingsService>();
16+
private readonly IStorageService StorageService = Ioc.Default.GetRequiredService<IStorageService>();
1717

1818
/// <inheritdoc/>
1919
public Task<bool> IsSupportedAsync()
@@ -42,7 +42,7 @@ public async IAsyncEnumerable<TaggedItemModel> GetItemsForTagAsync(string tagUid
4242
{
4343
foreach (var item in FileTagsHelper.GetDbInstance().GetAll())
4444
{
45-
if (!item.Tags.Contains(tagUid) || RecycleBinHelpers.IsPathUnderRecycleBin(item.FilePath))
45+
if (!item.Tags.Contains(tagUid) || WindowsRecycleBinService.IsRecycled(item.FilePath))
4646
continue;
4747

4848
var storable = await StorageService.TryGetStorableAsync(item.FilePath, cancellationToken);

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

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// Copyright (c) 2024 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4+
using System.Security.Principal;
5+
46
namespace Files.App.Services
57
{
68
/// <inheritdoc cref="IWindowsRecycleBinService"/>
7-
public class WindowsRecycleBinService : IWindowsRecycleBinService, ITrashWatcher
9+
public class WindowsRecycleBinService : IWindowsRecycleBinService
810
{
9-
private List<SystemIO.FileSystemWatcher>? _watchers = [];
11+
private readonly List<SystemIO.FileSystemWatcher> _watchers = [];
1012

1113
/// <inheritdoc/>
1214
public event EventHandler<SystemIO.FileSystemEventArgs>? ItemAdded;
@@ -24,15 +26,15 @@ public class WindowsRecycleBinService : IWindowsRecycleBinService, ITrashWatcher
2426
public event EventHandler<SystemIO.FileSystemEventArgs>? RefreshRequested;
2527

2628
/// <summary>
27-
/// Initializes an instance of <see href="WindowsRecycleBinService"/> class.
29+
/// Initializes an instance of <see cref="WindowsRecycleBinService"/> class.
2830
/// </summary>
2931
public WindowsRecycleBinService()
3032
{
3133
StartWatcher();
3234
}
3335

3436
/// <inheritdoc/>
35-
public async Task<List<ShellFileItem>> GetAllRecyleBinFoldersAsync()
37+
public async Task<List<ShellFileItem>> GetAllRecycleBinFoldersAsync()
3638
{
3739
return (await Win32Helper.GetShellFolderAsync(Constants.UserEnvironmentPaths.RecycleBinPath, false, true, 0, int.MaxValue)).Enumerate;
3840
}
@@ -52,7 +54,7 @@ public bool IsRecycled(string? path)
5254
}
5355

5456
/// <inheritdoc/>
55-
public async Task<bool> IsRecylableAsync(string? path)
57+
public async Task<bool> IsRecyclableAsync(string? path)
5658
{
5759
if (string.IsNullOrEmpty(path) ||
5860
path.StartsWith(@"\\?\", StringComparison.Ordinal))
@@ -91,7 +93,9 @@ public void StartWatcher()
9193
// Create file system watcher to monitor recycle bin folder(s) instead.
9294

9395
// Listen changes only on the Recycle Bin that the current logon user has
94-
var sid = WindowsIdentity.GetCurrent().User.ToString();
96+
var sid = WindowsIdentity.GetCurrent().User?.ToString() ?? string.Empty;
97+
if (string.IsNullOrEmpty(sid))
98+
return;
9599

96100
// TODO: Use IStorageDevicesService to enumerate drives
97101
foreach (var drive in SystemIO.DriveInfo.GetDrives())
@@ -127,13 +131,14 @@ public void StopWatcher()
127131
private void Watcher_Changed(object sender, SystemIO.FileSystemEventArgs e)
128132
{
129133
// Don't listen changes on files starting with '$I'
130-
if (e.Name.StartsWith("$I", StringComparison.Ordinal))
134+
if (string.IsNullOrEmpty(e.Name) ||
135+
e.Name.StartsWith("$I", StringComparison.Ordinal))
131136
return;
132137

133138
switch (e.ChangeType)
134139
{
135140
case SystemIO.WatcherChangeTypes.Created:
136-
ItemCreated?.Invoke(this, e);
141+
ItemAdded?.Invoke(this, e);
137142
break;
138143
case SystemIO.WatcherChangeTypes.Deleted:
139144
ItemDeleted?.Invoke(this, e);
@@ -148,7 +153,7 @@ private void Watcher_Changed(object sender, SystemIO.FileSystemEventArgs e)
148153
}
149154

150155
/// <inheritdoc/>
151-
public override void Dispose()
156+
public void Dispose()
152157
{
153158
StopWatcher();
154159
}

src/Files.App/Utils/RecycleBin/RecycleBinHelpers.cs

-39
This file was deleted.

src/Files.App/Utils/RecycleBin/RecycleBinManager.cs

-111
This file was deleted.

0 commit comments

Comments
 (0)