Skip to content

Code Quality: Migrated DeleteFileFromApp and RemoveDirectoryFromApp to CsWin32 #15136

New issue

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

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

Already on GitHub? # to your account

Merged
merged 6 commits into from
Apr 7, 2024
Merged
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
@@ -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
{
@@ -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;
}
4 changes: 3 additions & 1 deletion src/Files.App/NativeMethods.txt
Original file line number Diff line number Diff line change
@@ -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
@@ -4,6 +4,7 @@
using Files.Shared.Helpers;
using System.IO;
using Windows.Storage;
using Windows.Win32;

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

StatusCenterHelper.AddCard_Compress(
creator.Sources,
3 changes: 2 additions & 1 deletion src/Files.App/Utils/FileTags/FileTagsHelper.cs
Original file line number Diff line number Diff line change
@@ -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
@@ -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))
{
Original file line number Diff line number Diff line change
@@ -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)
{
6 changes: 4 additions & 2 deletions src/Files.App/Utils/Storage/StorageItems/NativeStorageFile.cs
Original file line number Diff line number Diff line change
@@ -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;
});
}

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

namespace Files.App.Views.Properties
{
@@ -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)
{
Loading