Skip to content

Commit 41ca094

Browse files
committed
Init
1 parent 72c3faf commit 41ca094

14 files changed

+115
-131
lines changed

Directory.Packages.props

+1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@
5656
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
5757
<PackageVersion Include="MSTest.TestAdapter" Version="3.8.2" />
5858
<PackageVersion Include="MSTest.TestFramework" Version="3.8.2" />
59+
<PackageVersion Include="Dongle.GuidRVAGen" Version="1.0.4" />
5960
</ItemGroup>
6061
</Project>

src/Files.App.CsWin32/ComPtr`1.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ public readonly ComPtr<U> As<U>() where U : unmanaged, IComIID
5656
}
5757

5858
[MethodImpl(MethodImplOptions.AggressiveInlining)]
59-
public readonly HRESULT CoCreateInstance<U>(CLSCTX dwClsContext = CLSCTX.CLSCTX_LOCAL_SERVER)
59+
public readonly HRESULT CoCreateInstance(Guid* rclsid, IUnknown* pUnkOuter = null, CLSCTX dwClsContext = CLSCTX.CLSCTX_LOCAL_SERVER)
6060
{
61-
Guid iid = typeof(T).GUID, clsid = typeof(U).GUID;
62-
return PInvoke.CoCreateInstance(&clsid, null, dwClsContext, &iid, (void**)this.GetAddressOf());
61+
return PInvoke.CoCreateInstance(rclsid, pUnkOuter, dwClsContext, (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in T.Guid)), (void**)this.GetAddressOf());
6362
}
6463

6564
[MethodImpl(MethodImplOptions.AggressiveInlining)]

src/Files.App.CsWin32/Files.App.CsWin32.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
<ItemGroup>
1515
<PackageReference Include="Microsoft.Windows.CsWin32" PrivateAssets="all" />
16+
<PackageReference Include="Dongle.GuidRVAGen" />
1617
</ItemGroup>
1718

1819
</Project>

src/Files.App.CsWin32/IStorageProviderQuotaUI.cs

+5-19
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
namespace Windows.Win32.System.WinRT
1111
{
12-
public unsafe struct IStorageProviderQuotaUI : IComIID
12+
public unsafe partial struct IStorageProviderQuotaUI : IComIID
1313
{
14+
#pragma warning disable CS0649 // Field 'field' is never assigned to, and will always have its default value 'value'
1415
private void** lpVtbl;
16+
#pragma warning restore CS0649 // Field 'field' is never assigned to, and will always have its default value 'value'
1517

1618
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1719
public HRESULT GetQuotaTotalInBytes(ulong* value)
@@ -25,23 +27,7 @@ public HRESULT GetQuotaUsedInBytes(ulong* value)
2527
return ((delegate* unmanaged[Stdcall]<IStorageProviderQuotaUI*, ulong*, HRESULT>)(lpVtbl[8]))((IStorageProviderQuotaUI*)Unsafe.AsPointer(ref this), value);
2628
}
2729

28-
public static ref readonly Guid Guid
29-
{
30-
get
31-
{
32-
// BA6295C3-312E-544F-9FD5-1F81B21F3649
33-
ReadOnlySpan<byte> data =
34-
[
35-
0xC3, 0x95, 0x62, 0xBA,
36-
0x2E, 0x31,
37-
0x4F, 0x54,
38-
0x9F, 0xD5,
39-
0x1F, 0x81, 0xB2, 0x1F, 0x36, 0x49
40-
];
41-
42-
Debug.Assert(data.Length == sizeof(Guid));
43-
return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data));
44-
}
45-
}
30+
[GuidRVAGen.Guid("BA6295C3-312E-544F-9FD5-1F81B21F3649")]
31+
public static partial ref readonly Guid Guid { get; }
4632
}
4733
}

src/Files.App.CsWin32/IStorageProviderStatusUI.cs

+5-19
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,19 @@
99

1010
namespace Windows.Win32.System.WinRT
1111
{
12-
public unsafe struct IStorageProviderStatusUI : IComIID
12+
public unsafe partial struct IStorageProviderStatusUI : IComIID
1313
{
14+
#pragma warning disable CS0649 // Field 'field' is never assigned to, and will always have its default value 'value'
1415
private void** lpVtbl;
16+
#pragma warning restore CS0649 // Field 'field' is never assigned to, and will always have its default value 'value'
1517

1618
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1719
public HRESULT GetQuotaUI(IStorageProviderQuotaUI** result)
1820
{
1921
return ((delegate* unmanaged[Stdcall]<IStorageProviderStatusUI*, IStorageProviderQuotaUI**, HRESULT>)lpVtbl[14])((IStorageProviderStatusUI*)Unsafe.AsPointer(ref this), result);
2022
}
2123

22-
public static ref readonly Guid Guid
23-
{
24-
get
25-
{
26-
// d6b6a758-198d-5b80-977f-5ff73da33118
27-
ReadOnlySpan<byte> data =
28-
[
29-
0x58, 0xa7, 0xb6, 0xd6,
30-
0x8d, 0x19,
31-
0x80, 0x5b,
32-
0x97, 0x7f,
33-
0x5f, 0xf7, 0x3d, 0xa3, 0x31, 0x18
34-
];
35-
36-
Debug.Assert(data.Length == sizeof(Guid));
37-
return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data));
38-
}
39-
}
24+
[GuidRVAGen.Guid("D6B6A758-198D-5B80-977F-5FF73DA33118")]
25+
public static partial ref readonly Guid Guid { get; }
4026
}
4127
}

src/Files.App.CsWin32/IStorageProviderStatusUISource.cs

+5-19
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,19 @@
99

1010
namespace Windows.Win32.System.WinRT
1111
{
12-
public unsafe struct IStorageProviderStatusUISource : IComIID
12+
public unsafe partial struct IStorageProviderStatusUISource : IComIID
1313
{
14+
#pragma warning disable CS0649 // Field 'field' is never assigned to, and will always have its default value 'value'
1415
private void** lpVtbl;
16+
#pragma warning restore CS0649 // Field 'field' is never assigned to, and will always have its default value 'value'
1517

1618
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1719
public HRESULT GetStatusUI(IStorageProviderStatusUI** result)
1820
{
1921
return ((delegate* unmanaged[Stdcall]<IStorageProviderStatusUISource*, IStorageProviderStatusUI**, HRESULT>)lpVtbl[6])((IStorageProviderStatusUISource*)Unsafe.AsPointer(ref this), result);
2022
}
2123

22-
public static ref readonly Guid Guid
23-
{
24-
get
25-
{
26-
// A306C249-3D66-5E70-9007-E43DF96051FF
27-
ReadOnlySpan<byte> data =
28-
[
29-
0x49, 0xc2, 0x06, 0xa3,
30-
0x66, 0x3d,
31-
0x70, 0x5e,
32-
0x90, 0x07,
33-
0xe4, 0x3d, 0xf9, 0x60, 0x51, 0xff
34-
];
35-
36-
Debug.Assert(data.Length == sizeof(Guid));
37-
return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data));
38-
}
39-
}
24+
[GuidRVAGen.Guid("A306C249-3D66-5E70-9007-E43DF96051FF")]
25+
public static partial ref readonly Guid Guid { get; }
4026
}
4127
}

src/Files.App.CsWin32/IStorageProviderStatusUISourceFactory.cs

+5-19
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,19 @@
99

1010
namespace Windows.Win32.System.WinRT
1111
{
12-
public unsafe struct IStorageProviderStatusUISourceFactory : IComIID
12+
public unsafe partial struct IStorageProviderStatusUISourceFactory : IComIID
1313
{
14+
#pragma warning disable CS0649 // Field 'field' is never assigned to, and will always have its default value 'value'
1415
private void** lpVtbl;
16+
#pragma warning restore CS0649 // Field 'field' is never assigned to, and will always have its default value 'value'
1517

1618
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1719
public HRESULT GetStatusUISource(nint syncRootId, IStorageProviderStatusUISource** result)
1820
{
1921
return ((delegate* unmanaged[Stdcall]<IStorageProviderStatusUISourceFactory*, nint, IStorageProviderStatusUISource**, HRESULT>)lpVtbl[6])((IStorageProviderStatusUISourceFactory*)Unsafe.AsPointer(ref this), syncRootId, result);
2022
}
2123

22-
public static ref readonly Guid Guid
23-
{
24-
get
25-
{
26-
// 12E46B74-4E5A-58D1-A62F-0376E8EE7DD8
27-
ReadOnlySpan<byte> data =
28-
[
29-
0x74, 0x6b, 0xe4, 0x12,
30-
0x5a, 0x4e,
31-
0xd1, 0x58,
32-
0xa6, 0x2f,
33-
0x03, 0x76, 0xe8, 0xee, 0x7d, 0xd8
34-
];
35-
36-
Debug.Assert(data.Length == sizeof(Guid));
37-
return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data));
38-
}
39-
}
24+
[GuidRVAGen.Guid("12E46B74-4E5A-58D1-A62F-0376E8EE7DD8")]
25+
public static partial ref readonly Guid Guid { get; }
4026
}
4127
}

src/Files.App.CsWin32/ManualGuid.cs

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Runtime.CompilerServices;
6+
using Windows.Win32.System.WinRT;
7+
8+
namespace Windows.Win32
9+
{
10+
public static unsafe partial class IID
11+
{
12+
public static Guid* IID_IStorageProviderStatusUISourceFactory
13+
=> (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in IStorageProviderStatusUISourceFactory.Guid));
14+
15+
[GuidRVAGen.Guid("000214E4-0000-0000-C000-000000000046")]
16+
public static partial Guid* IID_IContextMenu { get; }
17+
18+
[GuidRVAGen.Guid("70629033-E363-4A28-A567-0DB78006E6D7")]
19+
public static partial Guid* IID_IEnumShellItems { get; }
20+
21+
[GuidRVAGen.Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE")]
22+
public static partial Guid* IID_IShellItem { get; }
23+
24+
[GuidRVAGen.Guid("7E9FB0D3-919F-4307-AB2E-9B1860310C93")]
25+
public static partial Guid* IID_IShellItem2 { get; }
26+
27+
[GuidRVAGen.Guid("947AAB5F-0A5C-4C13-B4D6-4BF7836FC9F8")]
28+
public static partial Guid* IID_IFileOperation { get; }
29+
30+
[GuidRVAGen.Guid("D57C7288-D4AD-4768-BE02-9D969532D960")]
31+
public static partial Guid* IID_IFileOpenDialog { get; }
32+
33+
[GuidRVAGen.Guid("84BCCD23-5FDE-4CDB-AEA4-AF64B83D78AB")]
34+
public static partial Guid* IID_IFileSaveDialog { get; }
35+
36+
[GuidRVAGen.Guid("B92B56A9-8B55-4E14-9A89-0199BBB6F93B")]
37+
public static partial Guid* IID_IDesktopWallpaper { get; }
38+
39+
[GuidRVAGen.Guid("2E941141-7F97-4756-BA1D-9DECDE894A3D")]
40+
public static partial Guid* IID_IApplicationActivationManager { get; }
41+
}
42+
43+
public static unsafe partial class CLSID
44+
{
45+
[GuidRVAGen.Guid("3AD05575-8857-4850-9277-11B85BDB8E09")]
46+
public static partial Guid* CLSID_FileOperation { get; }
47+
48+
[GuidRVAGen.Guid("DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7")]
49+
public static partial Guid* CLSID_FileOpenDialog { get; }
50+
51+
[GuidRVAGen.Guid("C0B4E2F3-BA21-4773-8DBA-335EC946EB8B")]
52+
public static partial Guid* CLSID_FileSaveDialog { get; }
53+
54+
[GuidRVAGen.Guid("C2CF3110-460E-4FC1-B9D0-8A1C0C9CC4BD")]
55+
public static partial Guid* CLSID_DesktopWallpaper { get; }
56+
57+
[GuidRVAGen.Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C")]
58+
public static partial Guid* CLSID_ApplicationActivationManager { get; }
59+
}
60+
61+
public static unsafe partial class BHID
62+
{
63+
[GuidRVAGen.Guid("3981E225-F559-11D3-8E3A-00C04F6837D5")]
64+
public static partial Guid* BHID_SFUIObject { get; }
65+
66+
[GuidRVAGen.Guid("94F60519-2850-4924-AA5A-D15E84868039")]
67+
public static partial Guid* BHID_EnumItems { get; }
68+
}
69+
70+
public static unsafe partial class FOLDERID
71+
{
72+
[GuidRVAGen.Guid("B7534046-3ECB-4C18-BE4E-64CD4CB7D6AC")]
73+
public static partial Guid* FOLDERID_RecycleBinFolder { get; }
74+
}
75+
}

src/Files.App/Services/Storage/StorageTrashBinService.cs

+4-11
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,15 @@ private unsafe bool RestoreAllTrashesInternal()
102102
{
103103
// Get IShellItem for Recycle Bin folder
104104
using ComPtr<IShellItem> pRecycleBinFolderShellItem = default;
105-
var recycleBinFolderId = PInvoke.FOLDERID_RecycleBinFolder;
106-
var shellItemGuid = typeof(IShellItem).GUID;
107-
HRESULT hr = PInvoke.SHGetKnownFolderItem(&recycleBinFolderId, KNOWN_FOLDER_FLAG.KF_FLAG_DEFAULT, HANDLE.Null, &shellItemGuid, (void**)pRecycleBinFolderShellItem.GetAddressOf());
105+
HRESULT hr = PInvoke.SHGetKnownFolderItem(FOLDERID.FOLDERID_RecycleBinFolder, KNOWN_FOLDER_FLAG.KF_FLAG_DEFAULT, HANDLE.Null, IID.IID_IShellItem, (void**)pRecycleBinFolderShellItem.GetAddressOf());
108106

109107
// Get IEnumShellItems for Recycle Bin folder
110108
using ComPtr<IEnumShellItems> pEnumShellItems = default;
111-
Guid enumShellItemGuid = typeof(IEnumShellItems).GUID;
112-
var enumItemsBHID = PInvoke.BHID_EnumItems;
113-
hr = pRecycleBinFolderShellItem.Get()->BindToHandler(null, &enumItemsBHID, &enumShellItemGuid, (void**)pEnumShellItems.GetAddressOf());
109+
hr = pRecycleBinFolderShellItem.Get()->BindToHandler(null, BHID.BHID_EnumItems, IID.IID_IEnumShellItems, (void**)pEnumShellItems.GetAddressOf());
114110

115111
// Initialize how to perform the operation
116112
using ComPtr<IFileOperation> pFileOperation = default;
117-
var fileOperationIid = typeof(IFileOperation).GUID;
118-
var fileOperationInstanceIid = typeof(FileOperation).GUID;
119-
hr = PInvoke.CoCreateInstance(&fileOperationInstanceIid, null, CLSCTX.CLSCTX_LOCAL_SERVER, &fileOperationIid, (void**)pFileOperation.GetAddressOf());
113+
hr = PInvoke.CoCreateInstance(CLSID.CLSID_FileOperation, null, CLSCTX.CLSCTX_LOCAL_SERVER, IID.IID_IFileOperation, (void**)pFileOperation.GetAddressOf());
120114
hr = pFileOperation.Get()->SetOperationFlags(FILEOPERATION_FLAGS.FOF_NO_UI);
121115
hr = pFileOperation.Get()->SetOwnerWindow(new(MainWindow.Instance.WindowHandle));
122116

@@ -125,8 +119,7 @@ private unsafe bool RestoreAllTrashesInternal()
125119
{
126120
// Get the original path
127121
using ComPtr<IShellItem2> pShellItem2 = default;
128-
var shellItem2Iid = typeof(IShellItem2).GUID;
129-
hr = pShellItem.Get()->QueryInterface(&shellItem2Iid, (void**)pShellItem2.GetAddressOf());
122+
hr = pShellItem.Get()->QueryInterface(IID.IID_IShellItem2, (void**)pShellItem2.GetAddressOf());
130123
hr = PInvoke.PSGetPropertyKeyFromName("System.Recycle.DeletedFrom", out var originalPathPropertyKey);
131124
hr = pShellItem2.Get()->GetString(originalPathPropertyKey, out var szOriginalPath);
132125

src/Files.App/Services/Windows/WindowsDialogService.cs

+4-26
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,7 @@ public unsafe bool Open_FileOpenDialog(nint hWnd, bool pickFoldersOnly, string[]
2323
try
2424
{
2525
using ComPtr<IFileOpenDialog> pDialog = default;
26-
var dialogInstanceIid = typeof(FileOpenDialog).GUID;
27-
var dialogIid = typeof(IFileOpenDialog).GUID;
28-
29-
// Get a new instance of the dialog
30-
HRESULT hr = PInvoke.CoCreateInstance(
31-
&dialogInstanceIid,
32-
null,
33-
CLSCTX.CLSCTX_INPROC_SERVER,
34-
&dialogIid,
35-
(void**)pDialog.GetAddressOf())
36-
.ThrowOnFailure();
26+
HRESULT hr = pDialog.CoCreateInstance(CLSID.CLSID_FileOpenDialog, null, CLSCTX.CLSCTX_INPROC_SERVER);
3727

3828
if (filters.Length is not 0 && filters.Length % 2 is 0)
3929
{
@@ -56,13 +46,12 @@ public unsafe bool Open_FileOpenDialog(nint hWnd, bool pickFoldersOnly, string[]
5646

5747
// Get the default shell folder (My Computer)
5848
using ComPtr<IShellItem> pDefaultFolderShellItem = default;
59-
var shellItemIid = typeof(IShellItem).GUID;
6049
fixed (char* pszDefaultFolderPath = Environment.GetFolderPath(defaultFolder))
6150
{
6251
hr = PInvoke.SHCreateItemFromParsingName(
6352
pszDefaultFolderPath,
6453
null,
65-
&shellItemIid,
54+
IID.IID_IShellItem,
6655
(void**)pDefaultFolderShellItem.GetAddressOf())
6756
.ThrowOnFailure();
6857
}
@@ -104,17 +93,7 @@ public unsafe bool Open_FileSaveDialog(nint hWnd, bool pickFoldersOnly, string[]
10493
try
10594
{
10695
using ComPtr<IFileSaveDialog> pDialog = default;
107-
var dialogInstanceIid = typeof(FileSaveDialog).GUID;
108-
var dialogIid = typeof(IFileSaveDialog).GUID;
109-
110-
// Get a new instance of the dialog
111-
HRESULT hr = PInvoke.CoCreateInstance(
112-
&dialogInstanceIid,
113-
null,
114-
CLSCTX.CLSCTX_INPROC_SERVER,
115-
&dialogIid,
116-
(void**)pDialog.GetAddressOf())
117-
.ThrowOnFailure();
96+
HRESULT hr = pDialog.CoCreateInstance(CLSID.CLSID_FileSaveDialog, null, CLSCTX.CLSCTX_INPROC_SERVER);
11897

11998
if (filters.Length is not 0 && filters.Length % 2 is 0)
12099
{
@@ -137,13 +116,12 @@ public unsafe bool Open_FileSaveDialog(nint hWnd, bool pickFoldersOnly, string[]
137116

138117
// Get the default shell folder (My Computer)
139118
using ComPtr<IShellItem> pDefaultFolderShellItem = default;
140-
var shellItemIid = typeof(IShellItem).GUID;
141119
fixed (char* pszDefaultFolderPath = Environment.GetFolderPath(defaultFolder))
142120
{
143121
hr = PInvoke.SHCreateItemFromParsingName(
144122
pszDefaultFolderPath,
145123
null,
146-
&shellItemIid,
124+
IID.IID_IShellItem,
147125
(void**)pDefaultFolderShellItem.GetAddressOf())
148126
.ThrowOnFailure();
149127
}

0 commit comments

Comments
 (0)