Skip to content

Commit 3128916

Browse files
committed
Requested changes
1 parent 435035e commit 3128916

File tree

4 files changed

+11
-21
lines changed

4 files changed

+11
-21
lines changed

src/Files.App.CsWin32/NativeMethods.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,7 @@ ApplicationDocumentLists
167167
IApplicationActivationManager
168168
MENU_ITEM_TYPE
169169
COMPRESSION_FORMAT
170+
FSCTL_SET_COMPRESSION
171+
FSCTL_DISMOUNT_VOLUME
172+
FSCTL_LOCK_VOLUME
173+
FILE_FILE_COMPRESSION

src/Files.App/Data/Models/RemovableDevice.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Copyright (c) 2024 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using System;
5-
using System.Diagnostics;
6-
using System.Threading.Tasks;
4+
using Windows.Win32;
75
using Windows.Win32.Storage.FileSystem;
86
using static Files.App.Helpers.Win32PInvoke;
97

@@ -53,7 +51,7 @@ private async Task<bool> LockVolumeAsync()
5351

5452
for (int i = 0; i < 5; i++)
5553
{
56-
if (DeviceIoControl(handle, FSCTL_LOCK_VOLUME, nint.Zero, 0, nint.Zero, 0, out _, nint.Zero))
54+
if (DeviceIoControl(handle, PInvoke.FSCTL_LOCK_VOLUME, nint.Zero, 0, nint.Zero, 0, out _, nint.Zero))
5755
{
5856
Debug.WriteLine("Lock successful!");
5957
result = true;
@@ -73,7 +71,7 @@ private async Task<bool> LockVolumeAsync()
7371

7472
private bool DismountVolume()
7573
{
76-
return DeviceIoControl(handle, FSCTL_DISMOUNT_VOLUME, nint.Zero, 0, nint.Zero, 0, out _, nint.Zero);
74+
return DeviceIoControl(handle, PInvoke.FSCTL_DISMOUNT_VOLUME, nint.Zero, 0, nint.Zero, 0, out _, nint.Zero);
7775
}
7876

7977
private bool PreventRemovalOfVolume(bool prevent)

src/Files.App/Helpers/Win32/Win32Helper.Storage.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@
1111
using System.Runtime.InteropServices.ComTypes;
1212
using System.Text;
1313
using System.Windows.Forms;
14-
using Vanara;
1514
using Vanara.PInvoke;
1615
using Windows.System;
1716
using Windows.Win32;
1817
using Windows.Win32.Foundation;
1918
using Windows.Win32.Storage.FileSystem;
20-
using static Files.App.Constants.Widgets;
21-
using static Vanara.PInvoke.Kernel32;
22-
using COMPRESSION_FORMAT = Windows.Win32.Storage.FileSystem.COMPRESSION_FORMAT;
2319
using HRESULT = Vanara.PInvoke.HRESULT;
2420
using HWND = Vanara.PInvoke.HWND;
2521

@@ -333,7 +329,7 @@ public static string ExtractStringFromDLL(string file, int number)
333329
}
334330

335331
if (iconData is not null || iconOptions.HasFlag(IconOptions.ReturnThumbnailOnly))
336-
return iconData;
332+
return iconData;
337333
else
338334
{
339335
var shfi = new Shell32.SHFILEINFO();
@@ -342,7 +338,7 @@ public static string ExtractStringFromDLL(string file, int number)
342338
// Cannot access file, use file attributes
343339
var useFileAttibutes = iconData is null;
344340

345-
var ret = Shell32.SHGetFileInfo(path, isFolder ? FileAttributes.Directory : 0, ref shfi, Shell32.SHFILEINFO.Size, flags);
341+
var ret = Shell32.SHGetFileInfo(path, isFolder ? FileAttributes.Directory : 0, ref shfi, Shell32.SHFILEINFO.Size, flags);
346342
if (ret == IntPtr.Zero)
347343
return iconData;
348344

@@ -970,7 +966,7 @@ public static unsafe bool CanCompressContent(string path)
970966
return false;
971967

972968
// 0x00000010 FILE_FILE_COMPRESSION
973-
return (fileSystemFlags & 0x00000010) != 0;
969+
return (fileSystemFlags & PInvoke.FILE_FILE_COMPRESSION) != 0;
974970
}
975971

976972
public static unsafe bool SetCompressionAttributeIoctl(string lpFileName, bool isCompressed)
@@ -996,7 +992,7 @@ public static unsafe bool SetCompressionAttributeIoctl(string lpFileName, bool i
996992

997993
var result = PInvoke.DeviceIoControl(
998994
new(hFile.DangerousGetHandle()),
999-
Win32PInvoke.FSCTL_SET_COMPRESSION,
995+
PInvoke.FSCTL_SET_COMPRESSION,
1000996
&compressionFormat,
1001997
sizeof(ushort),
1002998
null,

src/Files.App/Helpers/Win32/Win32PInvoke.Consts.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@ public static partial class Win32PInvoke
4242

4343
// FSCTL
4444
public const int FSCTL_GET_REPARSE_POINT = 0x000900A8;
45-
public const int FSCTL_LOCK_VOLUME = 0x00090018;
46-
public const int FSCTL_DISMOUNT_VOLUME = 0x00090020;
47-
public const uint FSCTL_SET_COMPRESSION = 0x9C040u;
48-
49-
// Compression
50-
public const ushort COMPRESSION_FORMAT_NONE = 0x0000;
51-
public const ushort COMPRESSION_FORMAT_DEFAULT = 0x0001;
52-
5345

5446
public const int MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16 * 1024;
5547
public const uint IO_REPARSE_TAG_MOUNT_POINT = 0xA0000003;

0 commit comments

Comments
 (0)