Skip to content

Commit

Permalink
Code Quality: Migrated CreateDirectoryFromApp to CsWin32 (#15175)
Browse files Browse the repository at this point in the history
  • Loading branch information
gumbarros authored Apr 14, 2024
1 parent ff93aa7 commit 7fced5d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 37 deletions.
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

0 comments on commit 7fced5d

Please sign in to comment.