Skip to content

Commit eb60923

Browse files
authored
Code Quality: Migrated DeleteFileFromApp and RemoveDirectoryFromApp to CsWin32 (#15136)
1 parent 938aaa7 commit eb60923

File tree

9 files changed

+18
-10
lines changed

9 files changed

+18
-10
lines changed

src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Files.App.Server.Data.Enums;
55
using System.Text.Json;
66
using Windows.Storage;
7+
using Windows.Win32;
78

89
namespace Files.App.Data.Models
910
{
@@ -530,7 +531,7 @@ public static void SetLayoutPreferencesForPath(string path, LayoutPreferencesIte
530531

531532
// Port settings to the database, delete the ADS
532533
SetLayoutPreferencesToDatabase(path, frn, layoutPreferences);
533-
NativeFileOperationsHelper.DeleteFileFromApp($"{path}:files_layoutmode");
534+
PInvoke.DeleteFileFromApp($"{path}:files_layoutmode");
534535

535536
return layoutPreferences;
536537
}

src/Files.App/NativeMethods.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ SetWindowPos
4040
SetFocus
4141
SetActiveWindow
4242
CopyFileFromApp
43-
MoveFileFromApp
43+
MoveFileFromApp
44+
DeleteFileFromApp
45+
RemoveDirectoryFromApp

src/Files.App/Utils/Archives/CompressHelper.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Files.Shared.Helpers;
55
using System.IO;
66
using Windows.Storage;
7+
using Windows.Win32;
78

89
namespace Files.App.Utils.Archives
910
{
@@ -92,7 +93,7 @@ public static async Task CompressArchiveAsync(ICompressArchiveModel creator)
9293
}
9394
else
9495
{
95-
NativeFileOperationsHelper.DeleteFileFromApp(archivePath);
96+
PInvoke.DeleteFileFromApp(archivePath);
9697

9798
StatusCenterHelper.AddCard_Compress(
9899
creator.Sources,

src/Files.App/Utils/FileTags/FileTagsHelper.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Windows.Foundation.Metadata;
66
using Windows.Storage;
77
using Windows.Storage.FileProperties;
8+
using Windows.Win32;
89
using IO = System.IO;
910

1011
namespace Files.App.Utils.FileTags
@@ -31,7 +32,7 @@ public static async void WriteFileTag(string filePath, string[] tag)
3132
}
3233
if (tag is null || !tag.Any())
3334
{
34-
NativeFileOperationsHelper.DeleteFileFromApp($"{filePath}:files");
35+
PInvoke.DeleteFileFromApp($"{filePath}:files");
3536
}
3637
else if (ReadFileTag(filePath) is not string[] arr || !tag.SequenceEqual(arr))
3738
{

src/Files.App/Utils/Storage/Operations/FilesystemOperations.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ public async Task<IStorageHistory> DeleteAsync(IStorageItemWithPath source, IPro
504504

505505
if (permanently)
506506
{
507-
fsResult = (FilesystemResult)NativeFileOperationsHelper.DeleteFileFromApp(source.Path);
507+
fsResult = (FilesystemResult)PInvoke.DeleteFileFromApp(source.Path);
508508
}
509509
if (!fsResult)
510510
{

src/Files.App/Utils/Storage/StorageItems/NativeStorageFile.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,14 @@ private void CreateFile()
105105

106106
public override IAsyncAction DeleteAsync()
107107
{
108-
return AsyncInfo.Run(async (cancellationToken) =>
108+
return AsyncInfo.Run(_ =>
109109
{
110-
if (!NativeFileOperationsHelper.DeleteFileFromApp(Path))
110+
if (!PInvoke.DeleteFileFromApp(Path))
111111
{
112112
throw new Win32Exception(Marshal.GetLastWin32Error());
113113
}
114+
115+
return Task.CompletedTask;
114116
});
115117
}
116118

src/Files.App/Utils/Storage/StorageItems/ZipStorageFile.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ public override IAsyncAction DeleteAsync(StorageDeleteOption option)
355355
}
356356
else if (option == StorageDeleteOption.PermanentDelete)
357357
{
358-
NativeFileOperationsHelper.DeleteFileFromApp(Path);
358+
PInvoke.DeleteFileFromApp(Path);
359359
}
360360
else
361361
{

src/Files.App/Utils/Storage/StorageItems/ZipStorageFolder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ public override IAsyncAction DeleteAsync(StorageDeleteOption option)
398398
}
399399
else if (option == StorageDeleteOption.PermanentDelete)
400400
{
401-
NativeFileOperationsHelper.DeleteFileFromApp(Path);
401+
PInvoke.DeleteFileFromApp(Path);
402402
}
403403
else
404404
{

src/Files.App/Views/Properties/GeneralPage.xaml.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.IO;
99
using System.Text.RegularExpressions;
1010
using Windows.Storage;
11+
using Windows.Win32;
1112

1213
namespace Files.App.Views.Properties
1314
{
@@ -168,7 +169,7 @@ await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() =>
168169
}
169170

170171
if (ViewModel.IsUnblockFileSelected)
171-
NativeFileOperationsHelper.DeleteFileFromApp($"{item.ItemPath}:Zone.Identifier");
172+
PInvoke.DeleteFileFromApp($"{item.ItemPath}:Zone.Identifier");
172173

173174
if (ViewModel.IsAblumCoverModified)
174175
{

0 commit comments

Comments
 (0)