Skip to content

Code Quality: Migrated DeleteFileFromApp and RemoveDirectoryFromApp to CsWin32 #15136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Files.App.Server.Data.Enums;
using System.Text.Json;
using Windows.Storage;
using Windows.Win32;

namespace Files.App.Data.Models
{
Expand Down Expand Up @@ -530,7 +531,7 @@ public static void SetLayoutPreferencesForPath(string path, LayoutPreferencesIte

// Port settings to the database, delete the ADS
SetLayoutPreferencesToDatabase(path, frn, layoutPreferences);
NativeFileOperationsHelper.DeleteFileFromApp($"{path}:files_layoutmode");
PInvoke.DeleteFileFromApp($"{path}:files_layoutmode");

return layoutPreferences;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Files.App/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ SetWindowPos
SetFocus
SetActiveWindow
CopyFileFromApp
MoveFileFromApp
MoveFileFromApp
DeleteFileFromApp
RemoveDirectoryFromApp
3 changes: 2 additions & 1 deletion src/Files.App/Utils/Archives/CompressHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Files.Shared.Helpers;
using System.IO;
using Windows.Storage;
using Windows.Win32;

namespace Files.App.Utils.Archives
{
Expand Down Expand Up @@ -92,7 +93,7 @@ public static async Task CompressArchiveAsync(ICompressArchiveModel creator)
}
else
{
NativeFileOperationsHelper.DeleteFileFromApp(archivePath);
PInvoke.DeleteFileFromApp(archivePath);

StatusCenterHelper.AddCard_Compress(
creator.Sources,
Expand Down
3 changes: 2 additions & 1 deletion src/Files.App/Utils/FileTags/FileTagsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Windows.Foundation.Metadata;
using Windows.Storage;
using Windows.Storage.FileProperties;
using Windows.Win32;
using IO = System.IO;

namespace Files.App.Utils.FileTags
Expand All @@ -31,7 +32,7 @@ public static async void WriteFileTag(string filePath, string[] tag)
}
if (tag is null || !tag.Any())
{
NativeFileOperationsHelper.DeleteFileFromApp($"{filePath}:files");
PInvoke.DeleteFileFromApp($"{filePath}:files");
}
else if (ReadFileTag(filePath) is not string[] arr || !tag.SequenceEqual(arr))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public async Task<IStorageHistory> DeleteAsync(IStorageItemWithPath source, IPro

if (permanently)
{
fsResult = (FilesystemResult)NativeFileOperationsHelper.DeleteFileFromApp(source.Path);
fsResult = (FilesystemResult)PInvoke.DeleteFileFromApp(source.Path);
}
if (!fsResult)
{
Expand Down
6 changes: 4 additions & 2 deletions src/Files.App/Utils/Storage/StorageItems/NativeStorageFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ private void CreateFile()

public override IAsyncAction DeleteAsync()
{
return AsyncInfo.Run(async (cancellationToken) =>
return AsyncInfo.Run(_ =>
{
if (!NativeFileOperationsHelper.DeleteFileFromApp(Path))
if (!PInvoke.DeleteFileFromApp(Path))
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}

return Task.CompletedTask;
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Utils/Storage/StorageItems/ZipStorageFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public override IAsyncAction DeleteAsync(StorageDeleteOption option)
}
else if (option == StorageDeleteOption.PermanentDelete)
{
NativeFileOperationsHelper.DeleteFileFromApp(Path);
PInvoke.DeleteFileFromApp(Path);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public override IAsyncAction DeleteAsync(StorageDeleteOption option)
}
else if (option == StorageDeleteOption.PermanentDelete)
{
NativeFileOperationsHelper.DeleteFileFromApp(Path);
PInvoke.DeleteFileFromApp(Path);
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion src/Files.App/Views/Properties/GeneralPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.Text.RegularExpressions;
using Windows.Storage;
using Windows.Win32;

namespace Files.App.Views.Properties
{
Expand Down Expand Up @@ -168,7 +169,7 @@ await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() =>
}

if (ViewModel.IsUnblockFileSelected)
NativeFileOperationsHelper.DeleteFileFromApp($"{item.ItemPath}:Zone.Identifier");
PInvoke.DeleteFileFromApp($"{item.ItemPath}:Zone.Identifier");

if (ViewModel.IsAblumCoverModified)
{
Expand Down
Loading