Skip to content

Commit 4bdcdfa

Browse files
committed
Fixed the first issue
1 parent ac21129 commit 4bdcdfa

File tree

2 files changed

+16
-38
lines changed

2 files changed

+16
-38
lines changed

src/Files.App/NativeMethods.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,5 @@ UnregisterClass
106106
SetWindowLong
107107
GetModuleHandle
108108
RegisterClassEx
109-
CREATESTRUCTW
109+
CREATESTRUCTW
110+
AssocQueryString

src/Files.App/ViewModels/UserControls/Previews/ShellPreviewViewModel.cs

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -48,52 +48,29 @@ public async override Task<List<FileProperty>> LoadPreviewAndDetailsAsync()
4848
if (string.IsNullOrEmpty(extension))
4949
return null;
5050

51-
var hr = PInvoke.AssocCreate(QueryAssociationsClsid, IQueryAssociationsIid, out var queryAssocObject);
52-
if (!hr.Succeeded)
53-
return null;
54-
5551
try
5652
{
57-
if (queryAssocObject is not IQueryAssociations queryAssoc)
58-
return null;
59-
60-
fixed (char* pszExtension = extension)
53+
fixed (char* pszOutput = new char[1024])
6154
{
62-
PWSTR lpwszExtension = new(pszExtension);
63-
64-
queryAssoc.Init(ASSOCF.ASSOCF_INIT_DEFAULTTOSTAR, lpwszExtension, HKEY.Null, new(hwnd));
65-
66-
fixed (char* pszIPreviewHandlerIID = IPreviewHandlerIid.ToString())
67-
{
68-
PWSTR lpwszIPreviewHandlerIID = new(pszIPreviewHandlerIID);
69-
70-
fixed (char* pszOutput = new char[256])
71-
{
72-
PWSTR lpwszOutput = new(pszOutput);
73-
uint cchOutput = 256u;
74-
75-
queryAssoc.GetString(
76-
ASSOCF.ASSOCF_NOTRUNCATE,
77-
ASSOCSTR.ASSOCSTR_SHELLEXTENSION,
78-
lpwszIPreviewHandlerIID,
79-
lpwszOutput,
80-
ref cchOutput);
81-
82-
Debug.WriteLine($"Preview handler for {lpwszExtension.ToString()}: {lpwszOutput.ToString()}");
83-
84-
return Guid.Parse(lpwszOutput.ToString());
85-
}
86-
}
55+
PWSTR pwszOutput = new(pszOutput);
56+
uint cchOutput = 512u;
57+
58+
// Try to find registered preview handler associated with specified extension name
59+
var res = PInvoke.AssocQueryString(
60+
ASSOCF.ASSOCF_NOTRUNCATE,
61+
ASSOCSTR.ASSOCSTR_SHELLEXTENSION,
62+
extension,
63+
"{8895b1c6-b41f-4c1c-a562-0d564250836f}",
64+
pszOutput,
65+
ref cchOutput);
66+
67+
return Guid.Parse(pwszOutput.ToString());
8768
}
8869
}
8970
catch
9071
{
9172
return null;
9273
}
93-
finally
94-
{
95-
Marshal.ReleaseComObject(queryAssocObject);
96-
}
9774
}
9875

9976
public void SizeChanged(RECT size)

0 commit comments

Comments
 (0)