Skip to content

Commit 6fadea0

Browse files
committed
Init
1 parent bfc6ee1 commit 6fadea0

File tree

15 files changed

+243
-185
lines changed

15 files changed

+243
-185
lines changed

src/Files.App.CsWin32/ManualGuid.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public static Guid* IID_IStorageProviderStatusUISourceFactory
4141

4242
[GuidRVAGen.Guid("00021500-0000-0000-C000-000000000046")]
4343
public static partial Guid* IID_IQueryInfo { get; }
44+
45+
[GuidRVAGen.Guid("000214F9-0000-0000-C000-000000000046")]
46+
public static partial Guid* IID_IShellLinkW { get; }
4447
}
4548

4649
public static unsafe partial class CLSID

src/Files.App.CsWin32/NativeMethods.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,6 @@ _SICHINTF
226226
RoGetAgileReference
227227
IQueryInfo
228228
QITIPF_FLAGS
229+
GetDiskFreeSpaceEx
230+
GetDriveType
231+
SLGP_FLAGS
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace Files.App.Storage
5+
{
6+
public interface IWindowsFile : IWindowsStorable, IChildFile
7+
{
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
namespace Files.App.Storage
5+
{
6+
public interface IWindowsFolder : IWindowsStorable, IChildFolder
7+
{
8+
}
9+
}

src/Files.App.Storage/Storables/WindowsStorage/IWindowsStorable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Files.App.Storage
88
{
9-
public interface IWindowsStorable : IDisposable
9+
public interface IWindowsStorable : IStorableChild, IEquatable<IWindowsStorable>, IDisposable
1010
{
1111
ComPtr<IShellItem> ThisPtr { get; }
1212
}

src/Files.App.Storage/Storables/WindowsStorage/WindowsFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Files.App.Storage
99
{
1010
[DebuggerDisplay("{" + nameof(ToString) + "()}")]
11-
public sealed class WindowsFile : WindowsStorable, IChildFile
11+
public sealed class WindowsFile : WindowsStorable, IWindowsFile
1212
{
1313
public WindowsFile(ComPtr<IShellItem> nativeObject)
1414
{

src/Files.App.Storage/Storables/WindowsStorage/WindowsFolder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Files.App.Storage
1111
{
1212
[DebuggerDisplay("{" + nameof(ToString) + "()}")]
13-
public sealed class WindowsFolder : WindowsStorable, IChildFolder
13+
public sealed class WindowsFolder : WindowsStorable, IWindowsFolder
1414
{
1515
public WindowsFolder(ComPtr<IShellItem> nativeObject)
1616
{

src/Files.App.Storage/Storables/WindowsStorage/WindowsStorable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Files.App.Storage
1010
{
11-
public abstract class WindowsStorable : IWindowsStorable, IStorableChild, IEquatable<IWindowsStorable>
11+
public abstract class WindowsStorable : IWindowsStorable
1212
{
1313
public ComPtr<IShellItem> ThisPtr { get; protected set; }
1414

src/Files.App.Storage/Storables/WindowsStorage/WindowsStorableHelpers.Shell.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,19 @@ public unsafe static HRESULT TryGetShellTooltip(this IWindowsStorable storable,
143143

144144
return HRESULT.S_OK;
145145
}
146+
147+
public unsafe static HRESULT TryGetShellLink(this IWindowsStorable storable, out ComPtr<IShellLinkW> pShellLink)
148+
{
149+
pShellLink = default;
150+
151+
using ComPtr<IShellLinkW> pShellLinkW = default;
152+
HRESULT hr = storable.ThisPtr.Get()->BindToHandler(null, BHID.BHID_SFUIObject, IID.IID_IShellLinkW, (void**)pShellLinkW.GetAddressOf());
153+
if (hr.ThrowIfFailedOnDebug().Failed)
154+
return hr;
155+
156+
pShellLink = pShellLinkW;
157+
158+
return HRESULT.S_OK;
159+
}
146160
}
147161
}

src/Files.App.Storage/Storables/WindowsStorage/WindowsStorableHelpers.Storage.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Windows.Win32;
55
using Windows.Win32.Foundation;
6+
using Windows.Win32.NetworkManagement.WNet;
67
using Windows.Win32.Storage.FileSystem;
78
using Windows.Win32.UI.Shell;
89

@@ -84,5 +85,37 @@ public static bool TryShowFormatDriveDialog(HWND hWnd, uint driveLetterIndex, SH
8485
var result = PInvoke.SHFormatDrive(hWnd, driveLetterIndex, id, options);
8586
return result is 0xFFFF;
8687
}
88+
89+
public static bool TryGetDriveTotalSpace(this IWindowsStorable storable, out ulong totalSize)
90+
{
91+
ulong ulTotalSize = 0UL;
92+
bool res = PInvoke.GetDiskFreeSpaceEx(storable.GetDisplayName(), null, &ulTotalSize, null);
93+
94+
totalSize = ulTotalSize;
95+
96+
return res;
97+
}
98+
99+
public static bool TryGetDriveFreeSpace(this IWindowsStorable storable, out ulong freeSize)
100+
{
101+
ulong ulFreeSize = 0UL;
102+
bool res = PInvoke.GetDiskFreeSpaceEx(storable.GetDisplayName(), null, null, &ulFreeSize);
103+
104+
freeSize = ulFreeSize;
105+
106+
return res;
107+
}
108+
109+
public static bool TryGetDriveType(this IWindowsStorable storable, out uint driveType)
110+
{
111+
driveType = PInvoke.GetDriveType(storable.GetDisplayName());
112+
113+
return driveType is 0U; // DRIVE_UNKNOWN
114+
}
115+
116+
public static bool TryDisconnectNetworkDrive(this IWindowsStorable storable)
117+
{
118+
return PInvoke.WNetCancelConnection2W(storable.GetDisplayName().TrimEnd('\\'), NET_CONNECT_FLAGS.CONNECT_UPDATE_PROFILE, true) is WIN32_ERROR.NO_ERROR;
119+
}
87120
}
88121
}

0 commit comments

Comments
 (0)