Skip to content

Code Quality: Migrated CreateDirectoryFromApp to CsWin32 #15175

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
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
33 changes: 0 additions & 33 deletions src/Files.App/Helpers/Interop/NativeFileOperationsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,39 +123,6 @@ private static extern bool DeviceIoControl(
out uint lpBytesReturned,
IntPtr lpOverlapped);

[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall,
SetLastError = true)]
public static extern IntPtr CreateFile2FromApp(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
uint dwCreationDisposition,
IntPtr pCreateExParams
);

[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall,
SetLastError = true)]
public static extern bool CreateDirectoryFromApp(
string lpPathName,
IntPtr SecurityAttributes
);

[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall,
SetLastError = true)]
public static extern bool DeleteFileFromApp(
string lpFileName
);

[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall,
SetLastError = true)]
public static extern bool RemoveDirectoryFromApp(
string lpPathName
);

[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetFileAttributesExFromApp(
Expand Down
3 changes: 2 additions & 1 deletion src/Files.App/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ CopyFileFromApp
MoveFileFromApp
DeleteFileFromApp
RemoveDirectoryFromApp
GetKeyState
GetKeyState
CreateDirectoryFromApp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.Shared.Extensions;
using System;
using System.IO;
using Windows.Win32;
using static Files.App.Helpers.NativeFileOperationsHelper;

namespace Files.App.Utils.Serialization.Implementation
Expand All @@ -14,7 +13,7 @@ internal sealed class DefaultSettingsSerializer : ISettingsSerializer

public bool CreateFile(string path)
{
CreateDirectoryFromApp(Path.GetDirectoryName(path), IntPtr.Zero);
PInvoke.CreateDirectoryFromApp(Path.GetDirectoryName(path), null);

var hFile = CreateFileFromApp(path, GENERIC_READ, FILE_SHARE_READ, IntPtr.Zero, OPEN_ALWAYS, (uint)File_Attributes.BackupSemantics, IntPtr.Zero);
if (hFile.IsHandleInvalid())
Expand Down
Loading