ReactOS 0.4.15-dev-8138-g1e75ea8
CDeskLinkDropHandler.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: sendmail
3 * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4 * PURPOSE: DeskLink implementation
5 * COPYRIGHT: Copyright 2019 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6 */
7
8#include "precomp.hpp"
9
11
13{
15}
16
18{
20}
21
22// IDropTarget
25 POINTL pt, DWORD *pdwEffect)
26{
27 TRACE("(%p)\n", this);
28
29 *pdwEffect &= DROPEFFECT_LINK;
30
31 return S_OK;
32}
33
36{
37 TRACE("(%p)\n", this);
38
39 *pdwEffect &= DROPEFFECT_LINK;
40
41 return S_OK;
42}
43
45{
46 TRACE("(%p)\n", this);
47 return S_OK;
48}
49
52 POINTL pt, DWORD *pdwEffect)
53{
54 TRACE("(%p)\n", this);
55
56 if (!pDataObject)
57 {
58 ERR("pDataObject is NULL\n");
59 return E_POINTER;
60 }
61
62 WCHAR szDir[MAX_PATH], szDest[MAX_PATH], szSrc[MAX_PATH];
64
65 CComPtr<IShellFolder> pDesktop;
66 HRESULT hr = SHGetDesktopFolder(&pDesktop);
68 return hr;
69
70 CDataObjectHIDA pida(pDataObject);
71 if (FAILED_UNEXPECTEDLY(pida.hr()))
72 return pida.hr();
73
74 LPCITEMIDLIST pidlParent = HIDA_GetPIDLFolder(pida);
75 for (UINT i = 0; i < pida->cidl; ++i)
76 {
77 LPCITEMIDLIST pidlChild = HIDA_GetPIDLItem(pida, i);
78
79 CComHeapPtr<ITEMIDLIST> pidl(ILCombine(pidlParent, pidlChild));
80 if (!pidl)
81 {
82 ERR("Out of memory\n");
83 break;
84 }
85
86 StringCbCopyW(szDest, sizeof(szDest), szDir);
87 if (SHGetPathFromIDListW(pidl, szSrc))
88 {
89 LPCWSTR pszSourceExt;
90 BOOL bIsLink;
91
92 pszSourceExt = PathFindExtensionW(szSrc);
93 bIsLink = ((_wcsicmp(pszSourceExt, L".lnk") == 0) ||
94 (_wcsicmp(pszSourceExt, L".url") == 0));
95
96 if (bIsLink)
97 {
98 PathAppendW(szDest, PathFindFileNameW(szSrc));
99 }
100 else
101 {
102 CStringW strTitle;
103 strTitle.Format(IDS_SHORTCUT, PathFindFileNameW(szSrc));
104
105 PathAppendW(szDest, strTitle);
106 PathRemoveExtensionW(szDest);
107 StringCbCatW(szDest, sizeof(szDest), L".lnk");
108 }
109
110 if (PathFileExistsW(szDest))
111 {
112 CStringW strName(PathFindFileNameW(szDest));
113 PathYetAnotherMakeUniqueName(szDest, szDir, NULL, strName);
114 }
115
116 if (bIsLink)
117 {
118 hr = (CopyFileW(szSrc, szDest, TRUE) ? S_OK : E_FAIL);
119 }
120 else if (PathIsDirectoryW(szSrc) || (_wcsicmp(pszSourceExt, L".zip") == 0))
121 {
122 hr = CreateShellLink(szDest, szSrc, NULL, NULL, NULL, NULL, -1, NULL);
123 }
124 else
125 {
126 /* Set default working directory for the shortcut */
127 CStringW strWorkingDir(szSrc);
128 PathRemoveFileSpecW(strWorkingDir.GetBuffer());
129
130 hr = CreateShellLink(szDest, szSrc, NULL, NULL, strWorkingDir, NULL, -1, NULL);
131 }
132 }
133 else
134 {
135 STRRET strret;
136 hr = pDesktop->GetDisplayNameOf(pidl, SHGDN_INFOLDER, &strret);
138 break;
139
140 hr = StrRetToBufW(&strret, pidl, szSrc, _countof(szSrc));
142 break;
143
144 CStringW strTitle;
145 strTitle.Format(IDS_SHORTCUT, szSrc);
146
147 PathAppendW(szDest, strTitle);
148 PathRemoveExtensionW(szDest);
149 StringCbCatW(szDest, sizeof(szDest), L".lnk");
150
151 hr = CreateShellLink(szDest, NULL, pidl, NULL, NULL, NULL, -1, NULL);
152 }
153
155 break;
156 }
157
158 return hr;
159}
160
161// IPersistFile
163{
164 FIXME("(%p)\n", this);
165 return E_NOTIMPL;
166}
167
169{
170 FIXME("(%p)\n", this);
171 return E_NOTIMPL;
172}
173
175{
176 return S_OK;
177}
178
180{
181 FIXME("(%p)\n", this);
182 return E_NOTIMPL;
183}
184
186{
187 FIXME("(%p)\n", this);
188 return E_NOTIMPL;
189}
190
191// IPersist
193{
194 TRACE("(%p)\n", this);
195
196 if (!lpClassId)
197 {
198 ERR("lpClassId is NULL\n");
199 return E_POINTER;
200 }
201
202 *lpClassId = CLSID_DeskLinkDropHandler;
203
204 return S_OK;
205}
LONG g_ModuleRefCnt
Definition: ACPPage.cpp:13
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define STDMETHODIMP
Definition: basetyps.h:43
#define FIXME(fmt,...)
Definition: debug.h:114
#define ERR(fmt,...)
Definition: debug.h:113
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:818
STDMETHODIMP DragOver(DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
STDMETHODIMP GetClassID(CLSID *lpClassId)
STDMETHODIMP GetCurFile(LPOLESTR *ppszFileName)
STDMETHODIMP Load(LPCOLESTR pszFileName, DWORD dwMode)
STDMETHODIMP SaveCompleted(LPCOLESTR pszFileName)
STDMETHODIMP Drop(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
STDMETHODIMP Save(LPCOLESTR pszFileName, BOOL fRemember)
STDMETHODIMP DragEnter(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define IDS_SHORTCUT
Definition: resource.h:12
#define MAX_PATH
Definition: compat.h:34
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
BOOL WINAPI CopyFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName, IN BOOL bFailIfExists)
Definition: copy.c:439
BOOL WINAPI PathYetAnotherMakeUniqueName(LPWSTR buffer, LPCWSTR path, LPCWSTR shortname, LPCWSTR longname)
Definition: shellpath.c:699
BOOL WINAPI SHGetSpecialFolderPathW(HWND hwndOwner, LPWSTR szPath, int nFolder, BOOL bCreate)
Definition: shellpath.c:3092
BOOL WINAPI PathRemoveFileSpecW(LPWSTR lpszPath)
Definition: path.c:629
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:394
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
void WINAPI PathRemoveExtensionW(LPWSTR lpszPath)
Definition: path.c:823
BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
Definition: path.c:1777
BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
Definition: path.c:1723
HRESULT WINAPI StrRetToBufW(LPSTRRET src, const ITEMIDLIST *pidl, LPWSTR dest, UINT len)
Definition: string.c:1530
#define pt(x, y)
Definition: drawing.c:79
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
const DWORD DROPEFFECT_LINK
Definition: oleidl.idl:932
#define S_OK
Definition: intsafe.h:52
static LPOLESTR
Definition: stg_prop.c:27
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define PathAppendW
Definition: pathcch.h:309
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:712
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1342
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
HRESULT CreateShellLink(LPCWSTR pszLinkPath, LPCWSTR pszTargetPath OPTIONAL, LPCITEMIDLIST pidlTarget OPTIONAL, LPCWSTR pszArg OPTIONAL, LPCWSTR pszDir OPTIONAL, LPCWSTR pszIconPath OPTIONAL, INT iIconNr OPTIONAL, LPCWSTR pszComment OPTIONAL)
Definition: sendmail.cpp:102
static PCUIDLIST_RELATIVE HIDA_GetPIDLItem(CIDA const *pida, SIZE_T i)
Definition: shellutils.h:589
static PCUIDLIST_ABSOLUTE HIDA_GetPIDLFolder(CIDA const *pida)
Definition: shellutils.h:584
HRESULT hr
Definition: shlfolder.c:183
#define CSIDL_DESKTOPDIRECTORY
Definition: shlobj.h:2181
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
#define _countof(array)
Definition: sndvol32.h:70
#define TRACE(s)
Definition: solgame.cpp:4
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:44
#define E_POINTER
Definition: winerror.h:2365
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185