Skip to content

Commit 778d9ff

Browse files
committed
Init
1 parent 72c3faf commit 778d9ff

File tree

6 files changed

+64
-46
lines changed

6 files changed

+64
-46
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/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/ManualGuid.cs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) Files Community
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
6+
namespace Windows.Win32
7+
{
8+
public static unsafe partial class IID
9+
{
10+
[GuidRVAGen.Guid("000214E4-0000-0000-C000-000000000046")]
11+
public static partial Guid* IID_IContextMenu { get; }
12+
13+
[GuidRVAGen.Guid("70629033-E363-4A28-A567-0DB78006E6D7")]
14+
public static partial Guid* IID_IEnumShellItems { get; }
15+
16+
[GuidRVAGen.Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE")]
17+
public static partial Guid* IID_IShellItem { get; }
18+
19+
[GuidRVAGen.Guid("7E9FB0D3-919F-4307-AB2E-9B1860310C93")]
20+
public static partial Guid* IID_IShellItem2 { get; }
21+
22+
[GuidRVAGen.Guid("947AAB5F-0A5C-4C13-B4D6-4BF7836FC9F8")]
23+
public static partial Guid* IID_IFileOperation { get; }
24+
25+
[GuidRVAGen.Guid("D57C7288-D4AD-4768-BE02-9D969532D960")]
26+
public static partial Guid* IID_IFileOpenDialog { get; }
27+
}
28+
29+
public static unsafe partial class CLSID
30+
{
31+
[GuidRVAGen.Guid("3AD05575-8857-4850-9277-11B85BDB8E09")]
32+
public static partial Guid* CLSID_FileOperation { get; }
33+
34+
[GuidRVAGen.Guid("DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7")]
35+
public static partial Guid* CLSID_FileOpenDialog { get; }
36+
}
37+
38+
public static unsafe partial class BHID
39+
{
40+
[GuidRVAGen.Guid("3981E225-F559-11D3-8E3A-00C04F6837D5")]
41+
public static partial Guid* BHID_SFUIObject { get; }
42+
43+
[GuidRVAGen.Guid("94F60519-2850-4924-AA5A-D15E84868039")]
44+
public static partial Guid* BHID_EnumItems { get; }
45+
}
46+
47+
public static unsafe partial class FOLDERID
48+
{
49+
}
50+
}

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

+4-10
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,15 @@ private unsafe bool RestoreAllTrashesInternal()
103103
// Get IShellItem for Recycle Bin folder
104104
using ComPtr<IShellItem> pRecycleBinFolderShellItem = default;
105105
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());
106+
HRESULT hr = PInvoke.SHGetKnownFolderItem(&recycleBinFolderId, KNOWN_FOLDER_FLAG.KF_FLAG_DEFAULT, HANDLE.Null, IID.IID_IShellItem, (void**)pRecycleBinFolderShellItem.GetAddressOf());
108107

109108
// Get IEnumShellItems for Recycle Bin folder
110109
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());
110+
hr = pRecycleBinFolderShellItem.Get()->BindToHandler(null, BHID.BHID_EnumItems, IID.IID_IEnumShellItems, (void**)pEnumShellItems.GetAddressOf());
114111

115112
// Initialize how to perform the operation
116113
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());
114+
hr = PInvoke.CoCreateInstance(CLSID.CLSID_FileOperation, null, CLSCTX.CLSCTX_LOCAL_SERVER, IID.IID_IFileOperation, (void**)pFileOperation.GetAddressOf());
120115
hr = pFileOperation.Get()->SetOperationFlags(FILEOPERATION_FLAGS.FOF_NO_UI);
121116
hr = pFileOperation.Get()->SetOwnerWindow(new(MainWindow.Instance.WindowHandle));
122117

@@ -125,8 +120,7 @@ private unsafe bool RestoreAllTrashesInternal()
125120
{
126121
// Get the original path
127122
using ComPtr<IShellItem2> pShellItem2 = default;
128-
var shellItem2Iid = typeof(IShellItem2).GUID;
129-
hr = pShellItem.Get()->QueryInterface(&shellItem2Iid, (void**)pShellItem2.GetAddressOf());
123+
hr = pShellItem.Get()->QueryInterface(IID.IID_IShellItem2, (void**)pShellItem2.GetAddressOf());
130124
hr = PInvoke.PSGetPropertyKeyFromName("System.Recycle.DeletedFrom", out var originalPathPropertyKey);
131125
hr = pShellItem2.Get()->GetString(originalPathPropertyKey, out var szOriginalPath);
132126

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<FileOpenDialog>(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<FileSaveDialog>(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
}

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

+4-10
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,8 @@ public unsafe bool Remove(RecentItem item)
115115
{
116116
try
117117
{
118-
var bhid = PInvoke.BHID_SFUIObject;
119-
var contextMenuIid = typeof(IContextMenu).GUID;
120118
using ComPtr<IContextMenu> pContextMenu = default;
121-
HRESULT hr = item.ShellItem.Get()->BindToHandler(null, &bhid, &contextMenuIid, (void**)pContextMenu.GetAddressOf());
119+
HRESULT hr = item.ShellItem.Get()->BindToHandler(null, BHID.BHID_SFUIObject, IID.IID_IContextMenu, (void**)pContextMenu.GetAddressOf());
122120
HMENU hMenu = PInvoke.CreatePopupMenu();
123121
hr = pContextMenu.Get()->QueryContextMenu(hMenu, 0, 1, 0x7FFF, PInvoke.CMF_OPTIMIZEFORINVOKE);
124122

@@ -191,16 +189,13 @@ private unsafe bool UpdateRecentItems(bool isFolder)
191189
: "Shell:::{679F85CB-0220-4080-B29B-5540CC05AAB6}"; // Quick Access folder (recent files)
192190

193191
// Get IShellItem of the shell folder
194-
var shellItemIid = typeof(IShellItem).GUID;
195192
using ComPtr<IShellItem> pFolderShellItem = default;
196193
fixed (char* pszFolderShellPath = szFolderShellPath)
197-
hr = PInvoke.SHCreateItemFromParsingName(pszFolderShellPath, null, &shellItemIid, (void**)pFolderShellItem.GetAddressOf());
194+
hr = PInvoke.SHCreateItemFromParsingName(pszFolderShellPath, null, IID.IID_IShellItem, (void**)pFolderShellItem.GetAddressOf());
198195

199196
// Get IEnumShellItems of the quick access shell folder
200-
var enumItemsBHID = PInvoke.BHID_EnumItems;
201-
Guid enumShellItemIid = typeof(IEnumShellItems).GUID;
202197
using ComPtr<IEnumShellItems> pEnumShellItems = default;
203-
hr = pFolderShellItem.Get()->BindToHandler(null, &enumItemsBHID, &enumShellItemIid, (void**)pEnumShellItems.GetAddressOf());
198+
hr = pFolderShellItem.Get()->BindToHandler(null, BHID.BHID_EnumItems, IID.IID_IEnumShellItems, (void**)pEnumShellItems.GetAddressOf());
204199

205200
// Enumerate recent items and populate the list
206201
int index = 0;
@@ -233,9 +228,8 @@ private unsafe bool UpdateRecentItems(bool isFolder)
233228
fileName = string.IsNullOrEmpty(fileNameWithoutExtension) ? SystemIO.Path.GetFileName(fileName) : fileNameWithoutExtension;
234229

235230
// Get the date last modified
236-
var shellItem2Iid = typeof(IShellItem2).GUID;
237231
using ComPtr<IShellItem2> pShellItem2 = default;
238-
hr = pShellItem.Get()->QueryInterface(&shellItem2Iid, (void**)pShellItem2.GetAddressOf());
232+
hr = pShellItem.Get()->QueryInterface(IID.IID_IShellItem2, (void**)pShellItem2.GetAddressOf());
239233
hr = PInvoke.PSGetPropertyKeyFromName("System.DateModified", out var propertyKey);
240234
hr = pShellItem2.Get()->GetString(propertyKey, out var szPropertyValue);
241235
if (DateTime.TryParse(szPropertyValue.ToString(), out var lastModified))

0 commit comments

Comments
 (0)