Skip to content

Commit 1bc82c8

Browse files
committed
Native Support for Desktop Icons #1610
1 parent 34a361e commit 1bc82c8

File tree

3 files changed

+65
-19
lines changed

3 files changed

+65
-19
lines changed

QuickLook.Native/QuickLook.Native32/DOpus.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
class DOpus
2020
{
2121
public:
22-
static void PrepareMessageWindow();
23-
static void GetSelected(PWCHAR buffer);
22+
static void PrepareMessageWindow();
23+
static void GetSelected(PWCHAR buffer);
2424
private:
25-
static void ParseXmlBuffer(PWCHAR buffer);
26-
static LRESULT CALLBACK msgWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
25+
static void ParseXmlBuffer(PWCHAR buffer);
26+
static LRESULT CALLBACK msgWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
2727
};

QuickLook.Native/QuickLook.Native32/HelperMethods.cpp

+60-11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

1818
#include "stdafx.h"
19+
#include "strsafe.h"
20+
1921
#include "HelperMethods.h"
2022

2123
void HelperMethods::GetSelectedInternal(CComPtr<IShellBrowser> psb, PWCHAR buffer)
@@ -33,8 +35,11 @@ void HelperMethods::GetSelectedInternal(CComPtr<IShellBrowser> psb, PWCHAR buffe
3335

3436
void HelperMethods::ObtainFirstItem(CComPtr<IDataObject> dao, PWCHAR buffer)
3537
{
36-
FORMATETC formatetc;
37-
STGMEDIUM medium = {sizeof medium};
38+
if (!dao || !buffer)
39+
return;
40+
41+
FORMATETC formatetc = {};
42+
STGMEDIUM medium = {};
3843

3944
formatetc.cfFormat = CF_HDROP;
4045
formatetc.ptd = nullptr;
@@ -44,18 +49,62 @@ void HelperMethods::ObtainFirstItem(CComPtr<IDataObject> dao, PWCHAR buffer)
4449

4550
medium.tymed = TYMED_HGLOBAL;
4651

47-
if (FAILED(dao->GetData(&formatetc, &medium)))
48-
return;
52+
// Try CF_HDROP first
53+
if (SUCCEEDED(dao->GetData(&formatetc, &medium)))
54+
{
55+
HDROP hDrop = HDROP(medium.hGlobal);
56+
int count = DragQueryFile(hDrop, 0xFFFFFFFF, nullptr, 0);
57+
if (count >= 1)
58+
{
59+
WCHAR localBuffer[MAX_PATH] = { '\0' };
60+
if (DragQueryFileW(hDrop, 0, localBuffer, MAX_PATH) > 0)
61+
{
62+
GetLongPathName(localBuffer, buffer, MAX_PATH_EX);
63+
ReleaseStgMedium(&medium);
64+
return;
65+
}
66+
ReleaseStgMedium(&medium);
67+
}
68+
}
4969

50-
int n = DragQueryFile(HDROP(medium.hGlobal), 0xFFFFFFFF, nullptr, 0);
70+
// If CF_HDROP fails, try CFSTR_SHELLIDLIST
71+
// Support Desktop Icon (This PC, Recycle Bin and so on)
72+
// https://github.com/QL-Win/QuickLook/issues/1610
73+
static const CLIPFORMAT cfShellIDList = (CLIPFORMAT)RegisterClipboardFormatW(CFSTR_SHELLIDLIST);
74+
formatetc.cfFormat = cfShellIDList;
5175

52-
if (n < 1)
53-
return;
76+
if (SUCCEEDED(dao->GetData(&formatetc, &medium)))
77+
{
78+
CIDA* pida = (CIDA*)GlobalLock(medium.hGlobal);
79+
if (!pida)
80+
{
81+
ReleaseStgMedium(&medium);
82+
return;
83+
}
84+
85+
ITEMIDLIST* pidlFolder = (ITEMIDLIST*)((BYTE*)pida + pida->aoffset[0]);
86+
ITEMIDLIST* pidlItem = (ITEMIDLIST*)((BYTE*)pida + pida->aoffset[1]);
87+
PIDLIST_ABSOLUTE pidlFull = ILCombine(pidlFolder, pidlItem);
88+
GlobalUnlock(medium.hGlobal);
89+
ReleaseStgMedium(&medium);
90+
91+
if (!pidlFull)
92+
return;
93+
94+
// Convert to IShellItem to get canonical parsing path
95+
CComPtr<IShellItem> shellItem;
96+
if (SUCCEEDED(SHCreateItemFromIDList(pidlFull, IID_PPV_ARGS(&shellItem))))
97+
{
98+
PWSTR pszPath = nullptr;
99+
if (SUCCEEDED(shellItem->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, &pszPath)))
100+
{
101+
StringCchCopyW(buffer, MAX_PATH, pszPath); // returns e.g., ::{645FF040-5081-101B-9F08-00AA002F954E}
102+
CoTaskMemFree(pszPath);
103+
}
104+
}
54105

55-
WCHAR localBuffer[MAX_PATH] = { '\0' };
56-
DragQueryFile(HDROP(medium.hGlobal), 0, localBuffer, MAX_PATH);
57-
58-
GetLongPathName(localBuffer, buffer, MAX_PATH_EX);
106+
ILFree(pidlFull);
107+
}
59108
}
60109

61110
bool HelperMethods::IsListaryToolbarVisible()

QuickLook/Plugin/InfoPanel/InfoPanel.xaml.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ public void DisplayInfo(string path)
8383
}
8484
else if (Path.GetPathRoot(path) == path) // is this a drive?
8585
{
86-
long totalSpace;
87-
long totalFreeSpace;
88-
89-
FileHelper.GetDriveSpace(path, out totalSpace, out totalFreeSpace);
86+
FileHelper.GetDriveSpace(path, out var totalSpace, out var totalFreeSpace);
9087

9188
Dispatcher.Invoke(() =>
9289
{

0 commit comments

Comments
 (0)