Skip to content

Commit 7fced5d

Browse files
authored
Code Quality: Migrated CreateDirectoryFromApp to CsWin32 (#15175)
1 parent ff93aa7 commit 7fced5d

File tree

3 files changed

+4
-37
lines changed

3 files changed

+4
-37
lines changed

src/Files.App/Helpers/Interop/NativeFileOperationsHelper.cs

-33
Original file line numberDiff line numberDiff line change
@@ -123,39 +123,6 @@ private static extern bool DeviceIoControl(
123123
out uint lpBytesReturned,
124124
IntPtr lpOverlapped);
125125

126-
[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", CharSet = CharSet.Auto,
127-
CallingConvention = CallingConvention.StdCall,
128-
SetLastError = true)]
129-
public static extern IntPtr CreateFile2FromApp(
130-
string lpFileName,
131-
uint dwDesiredAccess,
132-
uint dwShareMode,
133-
uint dwCreationDisposition,
134-
IntPtr pCreateExParams
135-
);
136-
137-
[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", CharSet = CharSet.Auto,
138-
CallingConvention = CallingConvention.StdCall,
139-
SetLastError = true)]
140-
public static extern bool CreateDirectoryFromApp(
141-
string lpPathName,
142-
IntPtr SecurityAttributes
143-
);
144-
145-
[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", CharSet = CharSet.Auto,
146-
CallingConvention = CallingConvention.StdCall,
147-
SetLastError = true)]
148-
public static extern bool DeleteFileFromApp(
149-
string lpFileName
150-
);
151-
152-
[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", CharSet = CharSet.Auto,
153-
CallingConvention = CallingConvention.StdCall,
154-
SetLastError = true)]
155-
public static extern bool RemoveDirectoryFromApp(
156-
string lpPathName
157-
);
158-
159126
[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", SetLastError = true, CharSet = CharSet.Auto)]
160127
[return: MarshalAs(UnmanagedType.Bool)]
161128
public static extern bool GetFileAttributesExFromApp(

src/Files.App/NativeMethods.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ CopyFileFromApp
4343
MoveFileFromApp
4444
DeleteFileFromApp
4545
RemoveDirectoryFromApp
46-
GetKeyState
46+
GetKeyState
47+
CreateDirectoryFromApp

src/Files.App/Utils/Serialization/Implementation/DefaultSettingsSerializer.cs

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

4-
using Files.Shared.Extensions;
5-
using System;
64
using System.IO;
5+
using Windows.Win32;
76
using static Files.App.Helpers.NativeFileOperationsHelper;
87

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

1514
public bool CreateFile(string path)
1615
{
17-
CreateDirectoryFromApp(Path.GetDirectoryName(path), IntPtr.Zero);
16+
PInvoke.CreateDirectoryFromApp(Path.GetDirectoryName(path), null);
1817

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

0 commit comments

Comments
 (0)