Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2335 lines
81 KiB

  1. /*****************************************************************************\
  2. FILE: ftpdrop.cpp - IDropTarget interface
  3. Remarks:
  4. Note that you cannot create a shortcut on an FTP site. Although
  5. there's nothing technically preventing it, it's not done because
  6. the shortcut won't be of much use on an FTP site. (It points to
  7. your local machine, which doesn't help much for people not on the
  8. same network!)
  9. If you really want to put a shortcut file on an FTP site, create
  10. it on the desktop, then drag the shortcut onto the FTP site.
  11. The default verb for FTP sites is always "Copy". This is true
  12. even if an intra-site drag-drop is being done.
  13. DESCRIPTION:
  14. DefView will cache the IDropTarget pointer (CFtpDrop) for a shell extension.
  15. When it calls CFtpDrop::Drop(), the work needs to be done on a background
  16. thread in order to not block the UI thread. The problem is that if the user
  17. does another drag to the same Ftp Window, CFtpDrop::Drop() will be called again.
  18. For this reasons, CFtpDrop::Drop() cannot have any state after it returns.
  19. In order to accomplish this with the asynch background thread, we have
  20. CFtpDrop::Drop() call CDropOperation_Create(), and then CDropOperation->DoOperation().
  21. And then it will orphan (call Release()) the CDropOperation. The CDropOperation
  22. will then destroy itself when the copy is finishes. This enables subsequent calls
  23. to CFtpDrop::Drop() to spawn separate CDropOperation objects so each can maintain
  24. the state for that specifc operation and CFtpDrop remains stateless.
  25. \*****************************************************************************/
  26. #include "priv.h"
  27. #include "ftpdrop.h"
  28. #include "ftpurl.h"
  29. #include "statusbr.h"
  30. #include "newmenu.h"
  31. class CDropOperation;
  32. HRESULT CDropOperation_Create(CFtpFolder * pff, HWND hwnd, LPCTSTR pszzFSSource, LPCTSTR pszzFtpDest, CDropOperation ** ppfdt, DROPEFFECT de, OPS ops, int cobj);
  33. HRESULT ConfirmCopy(LPCWSTR pszLocal, LPCWSTR pszFtpName, OPS * pOps, HWND hwnd, CFtpFolder * pff, CFtpDir * pfd, DROPEFFECT * pde, int nObjs, BOOL * pfFireChangeNotify);
  34. // Declared because of recusion
  35. HRESULT FtpCopyDirectory(HINTERNET hint, HINTPROCINFO * phpi, LPCOPYONEHDROPINFO pcohi);
  36. HRESULT FtpCopyFile(HINTERNET hint, HINTPROCINFO * phpi, LPCOPYONEHDROPINFO pcohi);
  37. HRESULT UpdateCopyFileName(LPCOPYONEHDROPINFO pcohi)
  38. {
  39. HRESULT hr = S_OK;
  40. static WCHAR wzCopyTemplate[MAX_PATH] = L"";
  41. WCHAR wzLine1[MAX_PATH];
  42. if (!wzCopyTemplate[0])
  43. LoadStringW(HINST_THISDLL, IDS_COPYING, wzCopyTemplate, ARRAYSIZE(wzCopyTemplate));
  44. wnsprintfW(wzLine1, ARRAYSIZE(wzLine1), wzCopyTemplate, pcohi->pszFtpDest);
  45. EVAL(SUCCEEDED(pcohi->progInfo.ppd->SetLine(1, wzLine1, FALSE, NULL)));
  46. return hr;
  47. }
  48. HRESULT UpdateSrcDestDirs(LPCOPYONEHDROPINFO pcohi)
  49. {
  50. HRESULT hr = S_OK;
  51. WCHAR wzFrom[MAX_PATH];
  52. WCHAR wzStatusStr[MAX_PATH];
  53. StrCpyN(wzFrom, pcohi->pszFSSource, ARRAYSIZE(wzFrom));
  54. PathRemoveFileSpecW(wzFrom);
  55. if (EVAL(SUCCEEDED(hr = CreateFromToStr(wzStatusStr, ARRAYSIZE(wzStatusStr), wzFrom, pcohi->pszDir))))
  56. EVAL(SUCCEEDED(hr = pcohi->progInfo.ppd->SetLine(2, wzStatusStr, FALSE, NULL))); // Line one is the file being copied.
  57. return hr;
  58. }
  59. HRESULT DeleteOneFileCB(HINTERNET hint, HINTPROCINFO * phpi, LPVOID pv, BOOL * pfReleaseHint)
  60. {
  61. LPCOPYONEHDROPINFO pcohi = (LPCOPYONEHDROPINFO) pv;
  62. WIRECHAR wFtpPath[MAX_PATH];
  63. phpi->pfd->GetFtpSite()->GetCWireEncoding()->UnicodeToWireBytes(pcohi->pmlc, pcohi->pszFtpDest, (phpi->pfd->IsUTF8Supported() ? WIREENC_USE_UTF8 : WIREENC_NONE), wFtpPath, ARRAYSIZE(wFtpPath));
  64. return FtpDeleteFileWrap(hint, TRUE, wFtpPath);
  65. }
  66. HRESULT UpdateProgressDialogStr(LPCOPYONEHDROPINFO pcohi)
  67. {
  68. EVAL(SUCCEEDED(UpdateCopyFileName(pcohi)));
  69. EVAL(SUCCEEDED(UpdateSrcDestDirs(pcohi)));
  70. return S_OK;
  71. }
  72. /*****************************************************************************\
  73. CopyFileSysItem
  74. This function may cause recursion.
  75. \*****************************************************************************/
  76. HRESULT CopyFileSysItem(HINTERNET hint, HINTPROCINFO * phpi, LPCOPYONEHDROPINFO pcohi)
  77. {
  78. HRESULT hr = S_OK;
  79. // Check if the user canceled.
  80. if (pcohi->progInfo.ppd)
  81. {
  82. if (pcohi->progInfo.ppd->HasUserCancelled())
  83. return HRESULT_FROM_WIN32(ERROR_CANCELLED);
  84. if (pcohi->dwOperation != COHDI_FILESIZE_COUNT)
  85. UpdateProgressDialogStr(pcohi);
  86. }
  87. if (PathIsDirectory(pcohi->pszFSSource))
  88. {
  89. hr = FtpCopyDirectory(hint, phpi, pcohi);
  90. if (SUCCEEDED(hr) && (pcohi->dwOperation != COHDI_FILESIZE_COUNT))
  91. {
  92. /*
  93. WIN32_FIND_DATA wfd;
  94. HANDLE handle = FindFirstFile(pcohi->pszFSSource, &wfd);
  95. // NOTE: The date is wrong doing it this way, but it's faster. We should
  96. // find out if FtpCreateDirectory always stamps the directory with
  97. // the current date, and then update wfd with the current time/date.
  98. // This will simulate the server entry w/o the perf hit.
  99. if (handle != INVALID_HANDLE_VALUE)
  100. {
  101. // If we are the root, then we need to notify the shell that
  102. // a folder was created so the view needs to be updated.
  103. // We fire the FtpChangeNotify() call for SHCNE_MKDIR in FtpCreateDirectoryWithCN().
  104. // FtpChangeNotify(SHCNE_MKDIR) is fired in FtpCreateDirectoryWithCN
  105. FindClose(handle);
  106. }
  107. */
  108. }
  109. }
  110. else
  111. hr = FtpCopyFile(hint, phpi, pcohi);
  112. return hr;
  113. }
  114. HRESULT FtpCopyItem(HINTERNET hint, HINTPROCINFO * phpi, LPCOPYONEHDROPINFO pcohi, LPWIN32_FIND_DATA pwfd, LPCWIRESTR pwCurrentDir)
  115. {
  116. HRESULT hr = S_OK;
  117. TCHAR szFrom[MAX_PATH];
  118. WCHAR wzDestDir[MAX_PATH];
  119. TCHAR szServer[INTERNET_MAX_HOST_NAME_LENGTH];
  120. COPYONEHDROPINFO cohi = {pcohi->pff, szFrom, pwfd->cFileName, wzDestDir, pcohi->dwOperation, pcohi->ops, FALSE, pcohi->pmlc, pcohi->pidlServer, pcohi->fFireChangeNotify, NULL};
  121. CFtpDir * pfd = phpi->pfd;
  122. BOOL fSkipCurrentFile = FALSE;
  123. CWireEncoding * pwe = phpi->pfd->GetFtpSite()->GetCWireEncoding();
  124. cohi.progInfo.ppd = pcohi->progInfo.ppd;
  125. cohi.progInfo.hint = pcohi->progInfo.hint;
  126. cohi.progInfo.uliBytesCompleted.QuadPart = pcohi->progInfo.uliBytesCompleted.QuadPart;
  127. cohi.progInfo.uliBytesTotal.QuadPart = pcohi->progInfo.uliBytesTotal.QuadPart;
  128. phpi->pfd->GetDisplayPath(wzDestDir, ARRAYSIZE(wzDestDir));
  129. DisplayPathAppend(wzDestDir, ARRAYSIZE(wzDestDir), pcohi->pszFtpDest);
  130. if (EVAL(SUCCEEDED(pfd->GetFtpSite()->GetServer(szServer, ARRAYSIZE(szServer)))) &&
  131. SUCCEEDED(pfd->GetFtpSite()->GetFtpDir(szServer, wzDestDir, &(phpi->pfd))))
  132. {
  133. ASSERT(phpi->hwnd);
  134. // Make sure the user thinks it's ok to replace. We don't care about replacing directories
  135. if ((pcohi->dwOperation != COHDI_FILESIZE_COUNT) &&
  136. !(FILE_ATTRIBUTE_DIRECTORY & pwfd->dwFileAttributes))
  137. {
  138. TCHAR szSourceFile[MAX_PATH];
  139. StrCpyN(szSourceFile, pcohi->pszFSSource, ARRAYSIZE(szSourceFile));
  140. if (PathAppend(szSourceFile, pwfd->cFileName))
  141. {
  142. // PERF: We should do the Confirm copy only if the upload fails because it's
  143. // so costly.
  144. hr = ConfirmCopy(szSourceFile, pwfd->cFileName, &(cohi.ops), phpi->hwnd, pcohi->pff, phpi->pfd, NULL, 1, &cohi.fFireChangeNotify);
  145. if (S_FALSE == hr)
  146. {
  147. // S_FALSE from ConfirmCopy() means doen't replace this specific file, but continue
  148. // copying. We need to return S_OK or we will cancel copying all the files.
  149. fSkipCurrentFile = TRUE;
  150. hr = S_OK;
  151. }
  152. }
  153. else
  154. hr = HRESULT_FROM_WIN32(ERROR_BUFFER_OVERFLOW); // Path too long, probably.
  155. }
  156. if (!fSkipCurrentFile && (S_OK == hr) && IS_VALID_FILE(pwfd->cFileName))
  157. {
  158. StrCpyN(szFrom, pcohi->pszFSSource, ARRAYSIZE(szFrom)); // Set the source directory.
  159. // Specify the file/dir in that directory to copy.
  160. if (PathAppend(szFrom, pwfd->cFileName))
  161. {
  162. // 5. Call CopyFileSysItem() to get it copied (maybe recursively)
  163. //TraceMsg(TF_FTPOPERATION, "FtpCopyDirectory() calling CopyFileSysItem(From=%s. To=%s)", szFrom, pwfd->cFileName);
  164. hr = CopyFileSysItem(hint, phpi, &cohi);
  165. if (FAILED(hr) && (HRESULT_FROM_WIN32(ERROR_CANCELLED) != hr) &&
  166. (pcohi->dwOperation != COHDI_FILESIZE_COUNT))
  167. {
  168. int nResult = DisplayWininetError(phpi->hwnd, TRUE, HRESULT_CODE(hr), IDS_FTPERR_TITLE_ERROR, IDS_FTPERR_FILECOPY, IDS_FTPERR_WININET, MB_OK, pcohi->progInfo.ppd);
  169. hr = HRESULT_FROM_WIN32(ERROR_CANCELLED);
  170. }
  171. }
  172. else
  173. hr = HRESULT_FROM_WIN32(ERROR_BUFFER_OVERFLOW); // Path too long, probably.
  174. }
  175. pcohi->progInfo.hint = cohi.progInfo.hint; // Maybe the user cancelled.
  176. pcohi->progInfo.uliBytesCompleted.QuadPart = cohi.progInfo.uliBytesCompleted.QuadPart;
  177. pcohi->progInfo.uliBytesTotal.QuadPart = cohi.progInfo.uliBytesTotal.QuadPart;
  178. pcohi->ops = cohi.ops;
  179. phpi->pfd->Release();
  180. }
  181. phpi->pfd = pfd;
  182. return hr;
  183. }
  184. HRESULT _FtpSetCurrentDirectory(HINTERNET hint, HINTPROCINFO * phpi, LPCWSTR pwzFtpPath)
  185. {
  186. HRESULT hr;
  187. WIRECHAR wFtpPath[MAX_PATH];
  188. CWireEncoding * pwe = phpi->pfd->GetFtpSite()->GetCWireEncoding();
  189. hr = pwe->UnicodeToWireBytes(NULL, pwzFtpPath, (phpi->pfd->IsUTF8Supported() ? WIREENC_USE_UTF8 : WIREENC_NONE), wFtpPath, ARRAYSIZE(wFtpPath));
  190. if (SUCCEEDED(hr))
  191. hr = FtpSetCurrentDirectoryWrap(hint, TRUE, wFtpPath);
  192. return hr;
  193. }
  194. /*****************************************************************************\
  195. FtpCopyDirectory
  196. DESCRIPTION:
  197. This function will need to copy all the items in the directory to the
  198. FTP server if the item is a folder, it will need to recurse.
  199. Recursion algorithm:
  200. // 1. Create Directory
  201. // 2. Get Current Directory (To save for later).
  202. // 3. Change Directory Into new Directory.
  203. // 4. Find Next item (file/dir) in file system
  204. // 5. Call CopyFileSysItem() to get it copied (maybe recursively)
  205. // 6. Go to Step 4 if there are any left.
  206. // 7. Go back to original directory (Step 2)
  207. \*****************************************************************************/
  208. HRESULT FtpCopyDirectory(HINTERNET hint, HINTPROCINFO * phpi, LPCOPYONEHDROPINFO pcohi)
  209. {
  210. HRESULT hr = S_OK;
  211. if (phpi->psb && (pcohi->dwOperation != COHDI_FILESIZE_COUNT))
  212. phpi->psb->SetStatusMessage(IDS_COPYING, pcohi->pszFSSource);
  213. //TraceMsg(TF_FTPOPERATION, "FtpCopyDirectory() calling FtpCreateDirectoryA(%s)", pcohi->pszFSSource);
  214. // Create the directories on the first pass when we calculate file sizes.
  215. // We then skip creating them on the copy pass.
  216. if (pcohi->dwOperation == COHDI_FILESIZE_COUNT)
  217. {
  218. hr = FtpSafeCreateDirectory(phpi->hwnd, hint, pcohi->pmlc, pcohi->pff, phpi->pfd, pcohi->progInfo.ppd, pcohi->pszFtpDest, pcohi->fIsRoot);
  219. }
  220. // 1. Create Directory
  221. if (SUCCEEDED(hr))
  222. {
  223. WIRECHAR wCurrentDir[MAX_PATH];
  224. hr = FtpGetCurrentDirectoryWrap(hint, TRUE, wCurrentDir, ARRAYSIZE(wCurrentDir));
  225. if (EVAL(SUCCEEDED(hr)))
  226. {
  227. // NOTE: At this point, pcohi->pszFSSource is the DIRECTORY on the local
  228. // file system that is being copied.
  229. hr = _FtpSetCurrentDirectory(hint, phpi, pcohi->pszFtpDest);
  230. if (SUCCEEDED(hr))
  231. {
  232. WCHAR szSearchStr[MAX_PATH*2];
  233. WIN32_FIND_DATA wfd;
  234. HANDLE handle = NULL;
  235. StrCpyN(szSearchStr, pcohi->pszFSSource, ARRAYSIZE(szSearchStr));
  236. // We need to copy the entire directory.
  237. if (PathAppend(szSearchStr, SZ_ALL_FILES))
  238. {
  239. // 4. Find Next item (file/dir) in file system
  240. handle = FindFirstFile(szSearchStr, &wfd);
  241. if (handle != INVALID_HANDLE_VALUE)
  242. {
  243. do
  244. {
  245. //TraceMsg(TF_WININET_DEBUG, "FindFirstFileNext() returned %s", wfd.cFileName);
  246. hr = FtpCopyItem(hint, phpi, pcohi, &wfd, wCurrentDir);
  247. // 6. Check if the user canceled.
  248. if ((pcohi->progInfo.ppd) && (pcohi->progInfo.ppd->HasUserCancelled()))
  249. {
  250. hr = HRESULT_FROM_WIN32(ERROR_CANCELLED);
  251. break;
  252. }
  253. // 7. Repeat if there are any left and it wasn't cancelled (S_FALSE)
  254. }
  255. while ((S_OK == hr) && FindNextFile(handle, &wfd));
  256. FindClose(handle);
  257. }
  258. }
  259. else
  260. hr = HRESULT_FROM_WIN32(ERROR_BUFFER_OVERFLOW); // Path too long, probably.
  261. }
  262. // 7. Go back to original directory (from Step 2)
  263. // The only time we don't want to return to the original directory is if
  264. // the hinst was freed in an wininet callback function. We may cache the hinst
  265. // so we need the directory to be valid later.
  266. if (pcohi->progInfo.hint)
  267. {
  268. EVAL(SUCCEEDED(FtpSetCurrentDirectoryWrap(hint, TRUE, wCurrentDir)));
  269. }
  270. }
  271. }
  272. else
  273. {
  274. if (HRESULT_FROM_WIN32(ERROR_CANCELLED) != hr)
  275. {
  276. DisplayWininetError(phpi->hwnd, TRUE, HRESULT_CODE(hr), IDS_FTPERR_TITLE_ERROR, IDS_FTPERR_DIRCOPY, IDS_FTPERR_WININET, MB_OK, pcohi->progInfo.ppd);
  277. hr = HRESULT_FROM_WIN32(ERROR_CANCELLED);
  278. }
  279. }
  280. return hr;
  281. }
  282. HRESULT UpdateCopyProgressInfo(IProgressDialog * ppd, LPCTSTR pszFileName)
  283. {
  284. HRESULT hr = E_FAIL;
  285. TCHAR szTemplate[MAX_PATH];
  286. if (EVAL(LoadString(HINST_THISDLL, IDS_COPYING, szTemplate, ARRAYSIZE(szTemplate))))
  287. {
  288. TCHAR szStatusStr[MAX_PATH];
  289. WCHAR wzStatusStr[MAX_PATH];
  290. wnsprintf(szStatusStr, ARRAYSIZE(szStatusStr), szTemplate, pszFileName);
  291. SHTCharToUnicode(szStatusStr, wzStatusStr, ARRAYSIZE(wzStatusStr));
  292. EVAL(SUCCEEDED(hr = ppd->SetLine(1, wzStatusStr, FALSE, NULL)));
  293. }
  294. return hr;
  295. }
  296. /*****************************************************************************\
  297. FUNCTION: _FireChangeNotify
  298. DESCRIPTION:
  299. asd
  300. \*****************************************************************************/
  301. HRESULT _FireChangeNotify(HINTPROCINFO * phpi, LPCOPYONEHDROPINFO pcohi)
  302. {
  303. HRESULT hr = S_OK;
  304. WIN32_FIND_DATA wfd;
  305. HANDLE handle = FindFirstFile(pcohi->pszFSSource, &wfd);
  306. TraceMsg(TF_WININET_DEBUG, "_FireChangeNotify() FtpPutFileEx(%s -> %s) succeeded", pcohi->pszFSSource, pcohi->pszFtpDest);
  307. if (handle != INVALID_HANDLE_VALUE)
  308. {
  309. ULARGE_INTEGER uliFileSize;
  310. FTP_FIND_DATA ffd;
  311. CWireEncoding * pwe = pcohi->pff->GetCWireEncoding();
  312. uliFileSize.LowPart = wfd.nFileSizeLow;
  313. uliFileSize.HighPart = wfd.nFileSizeHigh;
  314. pcohi->progInfo.uliBytesCompleted.QuadPart += uliFileSize.QuadPart;
  315. hr = pwe->UnicodeToWireBytes(pcohi->pmlc, wfd.cFileName, (phpi->pfd->IsUTF8Supported() ? WIREENC_USE_UTF8 : WIREENC_NONE), ffd.cFileName, ARRAYSIZE(ffd.cFileName));
  316. if (EVAL(SUCCEEDED(hr)))
  317. {
  318. LPITEMIDLIST pidlFtpFile;
  319. SYSTEMTIME st;
  320. FILETIME ftUTC;
  321. if (0 == wfd.dwFileAttributes)
  322. {
  323. // Bug in Millennium's FindFirstFile(). It will sometimes return
  324. // 0 instead of FILE_ATTRIBUTE_NORMAL (0x80) or
  325. // FILE_ATTRIBUTE_DIRECTORY (0x10), so we patch it now.
  326. wfd.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
  327. }
  328. ffd.dwFileAttributes = wfd.dwFileAttributes;
  329. ffd.dwReserved0 = wfd.dwReserved0;
  330. ffd.dwReserved1 = wfd.dwReserved1;
  331. ffd.nFileSizeHigh = wfd.nFileSizeHigh;
  332. ffd.nFileSizeLow = wfd.nFileSizeLow;
  333. // wfd.ft*Time is in UTF and FtpItemID_CreateReal wants
  334. // it in LocalTime, so we need to convert here.
  335. GetSystemTime(&st);
  336. SystemTimeToFileTime(&st, &ftUTC);
  337. FileTimeToLocalFileTime(&ftUTC, &ffd.ftLastWriteTime); // UTC->LocalTime
  338. ffd.ftCreationTime = ffd.ftLastWriteTime;
  339. ffd.ftLastAccessTime = ffd.ftLastWriteTime;
  340. hr = FtpItemID_CreateReal(&ffd, pcohi->pszFtpDest, &pidlFtpFile);
  341. if (SUCCEEDED(hr))
  342. {
  343. // Note that we created the mapped name
  344. // PERF: Note that we give the time/date stamp to SHChangeNotify that comes from the source
  345. // file, not from the FTP server, so it may be inforrect. However, it's perf prohibitive
  346. // to do the right thing.
  347. FtpChangeNotify(phpi->hwnd, SHCNE_CREATE, pcohi->pff, phpi->pfd, pidlFtpFile, NULL, pcohi->fIsRoot);
  348. ILFree(pidlFtpFile);
  349. }
  350. }
  351. FindClose(handle);
  352. }
  353. return hr;
  354. }
  355. #define CCH_SIZE_ERROR_MESSAGE 6*1024
  356. /*****************************************************************************\
  357. FtpCopyFile
  358. Callback procedure that copies a single hdrop / map.
  359. Should I try to make the name unique in case of collision?
  360. Naah, just prompt, but! no way to tell if destination is case-sensitive...
  361. \*****************************************************************************/
  362. HRESULT FtpCopyFile(HINTERNET hint, HINTPROCINFO * phpi, LPCOPYONEHDROPINFO pcohi)
  363. {
  364. HRESULT hr = S_OK;
  365. if (pcohi->dwOperation != COHDI_FILESIZE_COUNT)
  366. {
  367. WIRECHAR wWireName[MAX_PATH];
  368. EVAL(SUCCEEDED(pcohi->pff->GetCWireEncoding()->UnicodeToWireBytes(pcohi->pmlc, pcohi->pszFtpDest, (pcohi->pff->IsUTF8Supported() ? WIREENC_USE_UTF8 : WIREENC_NONE), wWireName, ARRAYSIZE(wWireName))));
  369. if (phpi->psb)
  370. phpi->psb->SetStatusMessage(IDS_COPYING, pcohi->pszFSSource);
  371. if (pcohi->progInfo.ppd)
  372. {
  373. EVAL(SUCCEEDED(UpdateCopyProgressInfo(pcohi->progInfo.ppd, pcohi->pszFtpDest)));
  374. EVAL(SUCCEEDED(pcohi->progInfo.ppd->SetProgress64(pcohi->progInfo.uliBytesCompleted.QuadPart, pcohi->progInfo.uliBytesTotal.QuadPart)));
  375. }
  376. pcohi->progInfo.dwCompletedInCurFile = 0;
  377. pcohi->progInfo.dwLastDisplayed = 0;
  378. // We need to pass the FTP_TRANSFER_TYPE (_ASCII vs. _BINARY) if we ever want to add the
  379. // feature to allow users to force one type vs. the other.
  380. hr = FtpPutFileExWrap(hint, TRUE, pcohi->pszFSSource, wWireName, FTP_TRANSFER_TYPE_UNKNOWN, (DWORD_PTR)&(pcohi->progInfo));
  381. if (SUCCEEDED(hr))
  382. {
  383. // We don't fire change notify on browser only if we
  384. // are replacing a file because ChangeNotify really
  385. // just hacks ListView and doen't know how to handle
  386. // duplicates (file replace).
  387. if (pcohi->fFireChangeNotify)
  388. hr = _FireChangeNotify(phpi, pcohi);
  389. }
  390. else
  391. {
  392. if (HRESULT_FROM_WIN32(ERROR_INTERNET_OPERATION_CANCELLED) == hr)
  393. {
  394. // Clean up the file.
  395. EVAL(SUCCEEDED(phpi->pfd->WithHint(NULL, phpi->hwnd, DeleteOneFileCB, pcohi, NULL, pcohi->pff)));
  396. hr = HRESULT_FROM_WIN32(ERROR_CANCELLED);
  397. }
  398. else
  399. {
  400. // We still want to delete the file, but we need to save the error message
  401. // so the dialog is correct.
  402. CHAR szErrorMsg[CCH_SIZE_ERROR_MESSAGE];
  403. WCHAR wzErrorMsg[CCH_SIZE_ERROR_MESSAGE];
  404. DWORD cchSize = ARRAYSIZE(szErrorMsg);
  405. InternetGetLastResponseInfoWrap(TRUE, NULL, szErrorMsg, &cchSize);
  406. HRESULT hrOrig = hr;
  407. CWireEncoding * pwe = phpi->pfd->GetFtpSite()->GetCWireEncoding();
  408. pwe->WireBytesToUnicode(NULL, szErrorMsg, WIREENC_NONE, wzErrorMsg, ARRAYSIZE(wzErrorMsg));
  409. // Does it already exist? This may fail.
  410. SUCCEEDED(phpi->pfd->WithHint(NULL, phpi->hwnd, DeleteOneFileCB, pcohi, NULL, pcohi->pff));
  411. // No, so it was a real error, now display the error message with the original
  412. // server response.
  413. DisplayWininetErrorEx(phpi->hwnd, TRUE, HRESULT_CODE(hrOrig), IDS_FTPERR_TITLE_ERROR, IDS_FTPERR_FILECOPY, IDS_FTPERR_WININET, MB_OK, pcohi->progInfo.ppd, wzErrorMsg);
  414. hr = HRESULT_FROM_WIN32(ERROR_CANCELLED);
  415. }
  416. }
  417. }
  418. else
  419. {
  420. // Just get the file size.
  421. WIN32_FIND_DATA wfd;
  422. HANDLE handle = FindFirstFile(pcohi->pszFSSource, &wfd);
  423. if (handle && (handle != INVALID_HANDLE_VALUE))
  424. {
  425. ULARGE_INTEGER uliFileSize;
  426. uliFileSize.LowPart = wfd.nFileSizeLow;
  427. uliFileSize.HighPart = wfd.nFileSizeHigh;
  428. pcohi->progInfo.uliBytesTotal.QuadPart += uliFileSize.QuadPart;
  429. FindClose(handle);
  430. }
  431. }
  432. //TraceMsg(TF_FTPOPERATION, "FtpPutFileA(From=%ls, To=%s) hr=%#08lX", pcohi->pszFSSource, pcohi->pszFtpDest, hr);
  433. return hr;
  434. }
  435. /*****************************************************************************\
  436. _EnumOneHdropW
  437. Handle one hdrop and corresponding filemap.
  438. This is annoying because we need to convert from UNICODE to ANSI.
  439. \*****************************************************************************/
  440. #define OleStrToStrA(a, b) OleStrToStrN(a, ARRAYSIZE(a), b, -1)
  441. HRESULT _EnumOneHdropW(LPCWSTR * ppwzzFSSources, LPCWSTR * ppwzzFtpDest, LPTSTR pszFSSourceOut, DWORD cchFSSourceOut, LPTSTR pszFtpDestOut, DWORD cchFtpDestOut)
  442. {
  443. HRESULT hres;
  444. int cwch;
  445. if (*ppwzzFSSources && (*ppwzzFSSources)[0])
  446. {
  447. cwch = SHUnicodeToTChar(*ppwzzFSSources, pszFSSourceOut, cchFSSourceOut);
  448. if (EVAL(cwch))
  449. {
  450. *ppwzzFSSources += cwch;
  451. if (EVAL((*ppwzzFtpDest)[0]))
  452. {
  453. cwch = SHUnicodeToTChar(*ppwzzFtpDest, pszFtpDestOut, cchFtpDestOut);
  454. if (EVAL(cwch))
  455. {
  456. *ppwzzFtpDest += cwch;
  457. hres = S_OK; // Both strings converted okay
  458. }
  459. else
  460. hres = E_UNEXPECTED; // File name too long
  461. }
  462. else
  463. hres = E_UNEXPECTED; // Premature EOF in map
  464. }
  465. else
  466. hres = E_UNEXPECTED; // File name too long
  467. }
  468. else
  469. hres = S_FALSE; // End of buffer
  470. return hres;
  471. }
  472. /*****************************************************************************\
  473. _EnumOneHdropA
  474. Handle one hdrop and corresponding filemap.
  475. \*****************************************************************************/
  476. HRESULT _EnumOneHdropA(LPCSTR * ppszzFSSource, LPCSTR * ppszzFtpDest, LPTSTR pszFSSourceOut, DWORD cchFSSourceOut, LPTSTR pszFtpDestOut, DWORD cchFtpDestOut)
  477. {
  478. HRESULT hres;
  479. if ((*ppszzFSSource)[0])
  480. {
  481. SHAnsiToTChar(*ppszzFSSource, pszFSSourceOut, cchFSSourceOut);
  482. *ppszzFSSource += lstrlenA(*ppszzFSSource) + 1;
  483. if (EVAL((*ppszzFtpDest)[0]))
  484. {
  485. SHAnsiToTChar(*ppszzFtpDest, pszFtpDestOut, cchFtpDestOut);
  486. *ppszzFtpDest += lstrlenA(*ppszzFtpDest) + 1;
  487. hres = S_OK; // No problemo
  488. }
  489. else
  490. hres = E_UNEXPECTED; // Premature EOF in map
  491. }
  492. else
  493. hres = S_FALSE; // No more files
  494. return hres;
  495. }
  496. /*****************************************************************************\
  497. ConfirmCopy
  498. Callback procedure that checks if this file really ought to be
  499. copied.
  500. Returns S_OK if the file should be copied.
  501. Returns S_FALSE if the file should not be copied.
  502. - If the user cancelled, then say S_FALSE from now on.
  503. - If the user said Yes to All, then say S_OK.
  504. - If there is no conflict, then say S_OK.
  505. - If the user said No to All, then say S_FALSE.
  506. - Else, ask the user what to do.
  507. Note that the order of the tests above means that if you say
  508. "Yes to All", then we don't waste our time doing overwrite checks.
  509. _GROSS_: NOTE! that we don't try to uniquify the name, because
  510. WinINet doesn't support the STOU (store unique) command, and
  511. there is no way to know what filenames are valid on the server.
  512. \*****************************************************************************/
  513. HRESULT ConfirmCopy(LPCWSTR pszLocal, LPCWSTR pszFtpName, OPS * pOps, HWND hwnd, CFtpFolder * pff, CFtpDir * pfd, DROPEFFECT * pde, int nObjs, BOOL * pfFireChangeNotify)
  514. {
  515. HRESULT hr = S_OK;
  516. *pfFireChangeNotify = TRUE;
  517. if (*pOps == opsCancel)
  518. hr = S_FALSE;
  519. else
  520. {
  521. HANDLE hfind;
  522. WIN32_FIND_DATA wfdSrc;
  523. hfind = FindFirstFile(pszLocal, &wfdSrc);
  524. if (hfind != INVALID_HANDLE_VALUE)
  525. {
  526. FindClose(hfind);
  527. // Is it a file? We don't care about confirming the replacement
  528. // of directories.
  529. if (!(FILE_ATTRIBUTE_DIRECTORY & wfdSrc.dwFileAttributes))
  530. {
  531. FTP_FIND_DATA wfd;
  532. hr = pfd->GetFindDataForDisplayPath(hwnd, pszFtpName, &wfd, pff);
  533. if (*pOps == opsYesToAll)
  534. {
  535. // If the file exists (S_OK) and it's browser only,
  536. // then don't fire the change notify.
  537. if ((S_OK == hr) && (SHELL_VERSION_NT5 != GetShellVersion()))
  538. *pfFireChangeNotify = FALSE;
  539. hr = S_OK;
  540. }
  541. else
  542. {
  543. switch (hr)
  544. {
  545. case S_OK: // File exists; worry
  546. if (*pOps == opsNoToAll)
  547. hr = S_FALSE;
  548. else
  549. {
  550. FILETIME ftUTC = wfdSrc.ftLastWriteTime;
  551. FileTimeToLocalFileTime(&ftUTC, &wfdSrc.ftLastWriteTime); // UTC->LocalTime
  552. // If we needed to set the browser model, we would do it here.
  553. // However, we don't because we are asynch.
  554. switch (FtpConfirmReplaceDialog(hwnd, &wfdSrc, &wfd, nObjs, pff))
  555. {
  556. case IDC_REPLACE_YESTOALL:
  557. *pOps = opsYesToAll;
  558. // FALLTHROUGH
  559. case IDC_REPLACE_YES:
  560. // pre-NT5 doesn't work
  561. if (SHELL_VERSION_NT5 != GetShellVersion())
  562. *pfFireChangeNotify = FALSE;
  563. hr = S_OK;
  564. break;
  565. case IDC_REPLACE_NOTOALL:
  566. *pOps = opsNoToAll;
  567. // FALLTHROUGH
  568. case IDC_REPLACE_NO:
  569. hr = S_FALSE;
  570. break;
  571. default:
  572. ASSERT(0); // Huh?
  573. // FALLTHROUGH
  574. case IDC_REPLACE_CANCEL:
  575. if (pde)
  576. *pde = 0;
  577. *pOps = opsCancel;
  578. hr = HRESULT_FROM_WIN32(ERROR_CANCELLED);
  579. break;
  580. }
  581. }
  582. break;
  583. case S_FALSE:
  584. default:
  585. // Assume the file doesn't exist; no problemo
  586. hr = S_OK;
  587. break;
  588. }
  589. }
  590. }
  591. }
  592. else
  593. { // File doesn't exist
  594. hr = S_OK; // The open will raise the error
  595. }
  596. }
  597. //TraceMsg(TF_FTPDRAGDROP, "ConfirmCopy(%s) -> %08x", pszFtpName, hr);
  598. return hr;
  599. }
  600. /*****************************************************************************\
  601. CLASS: CDropOperation
  602. DESCRIPTION:
  603. DefView will cache the IDropTarget pointer (CFtpDrop) for a shell extension.
  604. When it calls CFtpDrop::Drop(), the work needs to be done on a background
  605. thread in order to not block the UI thread. The problem is that if the user
  606. does another drag to the same Ftp Window, CFtpDrop::Drop() will be called again.
  607. For this reasons, CFtpDrop::Drop() cannot have any state after it returns.
  608. In order to accomplish this with the asynch background thread, we have
  609. CFtpDrop::Drop() call CDropOperation_Create(), and then CDropOperation->DoOperation().
  610. And then it will orphan (call Release()) the CDropOperation. The CDropOperation
  611. will then destroy itself when the copy is finishes. This enables subsequent calls
  612. to CFtpDrop::Drop() to spawn separate CDropOperation objects so each can maintain
  613. the state for that specifc operation and CFtpDrop remains stateless.
  614. \*****************************************************************************/
  615. class CDropOperation : public IUnknown
  616. {
  617. public:
  618. //////////////////////////////////////////////////////
  619. // Public Interfaces
  620. //////////////////////////////////////////////////////
  621. // *** IUnknown ***
  622. virtual STDMETHODIMP_(ULONG) AddRef(void);
  623. virtual STDMETHODIMP_(ULONG) Release(void);
  624. virtual STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  625. public:
  626. CDropOperation();
  627. ~CDropOperation(void);
  628. // Public Member Functions
  629. HRESULT DoOperation(BOOL fAsync);
  630. static HRESULT CopyCB(HINTERNET hint, HINTPROCINFO * phpi, LPVOID pv, BOOL * pfReleaseHint);
  631. // Friend Functions
  632. friend HRESULT CDropOperation_Create(CFtpFolder * pff, HWND hwnd, LPCTSTR pszzFSSource, LPCTSTR pszzFtpDest, CDropOperation ** ppfdt, DROPEFFECT de, OPS ops, int cobj);
  633. protected:
  634. // Protected Member Variables
  635. int m_cRef;
  636. CFtpFolder * m_pff; // The owner
  637. CFtpDir * m_pfd; // The FtpDir of the owner
  638. HWND m_hwnd; // The window being drug over
  639. DROPEFFECT m_de; // Effect being performed
  640. OPS m_ops; // Overwrite prompting state
  641. int m_cobj; // Number of objects being dropped
  642. ULARGE_INTEGER m_uliBytesCompleted;
  643. ULARGE_INTEGER m_uliBytesTotal;
  644. // Private Member Functions
  645. HRESULT _ConfirmCopy(LPCWSTR pszLocal, LPCWSTR psz, BOOL * pfFireChangeNotify);
  646. HRESULT _CalcSizeOneHdrop(LPCWSTR pszFSSource, LPCWSTR pszFtpDest, IProgressDialog * ppd);
  647. HRESULT _ThreadProcCB(void);
  648. HRESULT _CopyOneHdrop(LPCWSTR pszFSSource, LPCWSTR pszFtpDest);
  649. HRESULT _StartBackgroundInteration(void);
  650. HRESULT _DoCopyIteration(void);
  651. HRESULT _CalcUploadProgress(void);
  652. private:
  653. // Private Member Variables
  654. IProgressDialog * m_ppd;
  655. LPCWSTR m_pszzFSSource; // Paths
  656. LPCWSTR m_pszzFtpDest; // Map
  657. CMultiLanguageCache m_mlc; // Cache for fast str thunking.
  658. static DWORD CALLBACK _ThreadProc(LPVOID pThis) {return ((CDropOperation *)pThis)->_ThreadProcCB();};
  659. };
  660. HRESULT CDropOperation_Create(CFtpFolder * pff, HWND hwnd, LPCTSTR pszzFSSource, LPCTSTR pszzFtpDest, CDropOperation ** ppfdt,
  661. DROPEFFECT de, OPS ops, int cobj)
  662. {
  663. HRESULT hr = E_OUTOFMEMORY;
  664. CDropOperation * pfdt = new CDropOperation();
  665. *ppfdt = pfdt;
  666. if (pfdt)
  667. {
  668. pfdt->m_hwnd = hwnd;
  669. // Copy the CFtpFolder * value
  670. pfdt->m_pff = pff;
  671. if (pff)
  672. pff->AddRef();
  673. // Copy the CFtpDir * value
  674. ASSERT(!pfdt->m_pfd);
  675. pfdt->m_pfd = pff->GetFtpDir();
  676. ASSERT(pfdt->m_pfd);
  677. ASSERT(!pfdt->m_pszzFSSource);
  678. pfdt->m_pszzFSSource = pszzFSSource;
  679. ASSERT(!pfdt->m_pszzFtpDest);
  680. pfdt->m_pszzFtpDest = pszzFtpDest;
  681. pfdt->m_de = de; // Effect being performed
  682. pfdt->m_ops = ops; // Overwrite prompting state
  683. pfdt->m_cobj = cobj; // Number of objects being dropped
  684. hr = S_OK;
  685. }
  686. ASSERT_POINTER_MATCHES_HRESULT(*ppfdt, hr);
  687. return hr;
  688. }
  689. /****************************************************\
  690. Constructor
  691. \****************************************************/
  692. CDropOperation::CDropOperation() : m_cRef(1)
  693. {
  694. DllAddRef();
  695. // This needs to be allocated in Zero Inited Memory.
  696. // Assert that all Member Variables are inited to Zero.
  697. ASSERT(!m_pff);
  698. ASSERT(!m_pfd);
  699. ASSERT(!m_hwnd);
  700. ASSERT(!m_cobj);
  701. LEAK_ADDREF(LEAK_CDropOperation);
  702. }
  703. /****************************************************\
  704. Destructor
  705. \****************************************************/
  706. CDropOperation::~CDropOperation()
  707. {
  708. // use ATOMICRELEASE
  709. IUnknown_Set(&m_pff, NULL);
  710. IUnknown_Set(&m_pfd, NULL);
  711. IUnknown_Set((IUnknown **)&m_ppd, NULL);
  712. Str_SetPtr((LPTSTR *) &m_pszzFSSource, NULL);
  713. Str_SetPtr((LPTSTR *) &m_pszzFtpDest, NULL);
  714. DllRelease();
  715. LEAK_DELREF(LEAK_CDropOperation);
  716. }
  717. //===========================
  718. // *** IUnknown Interface ***
  719. //===========================
  720. ULONG CDropOperation::AddRef()
  721. {
  722. m_cRef++;
  723. return m_cRef;
  724. }
  725. ULONG CDropOperation::Release()
  726. {
  727. ASSERT(m_cRef > 0);
  728. m_cRef--;
  729. if (m_cRef > 0)
  730. return m_cRef;
  731. delete this;
  732. return 0;
  733. }
  734. HRESULT CDropOperation::QueryInterface(REFIID riid, void **ppvObj)
  735. {
  736. if (IsEqualIID(riid, IID_IUnknown))
  737. {
  738. *ppvObj = SAFECAST(this, IUnknown*);
  739. }
  740. else
  741. {
  742. TraceMsg(TF_FTPQI, "CDropOperation::QueryInterface() failed.");
  743. *ppvObj = NULL;
  744. return E_NOINTERFACE;
  745. }
  746. AddRef();
  747. return S_OK;
  748. }
  749. /****************************************************\
  750. FUNCTION: _ThreadProcCB
  751. DESCRIPTION:
  752. \****************************************************/
  753. HRESULT CDropOperation::_ThreadProcCB(void)
  754. {
  755. HRESULT hr;
  756. HRESULT hrOleInit = SHCoInitialize();
  757. // WARNING: Init OLE if you plan to do COM.
  758. m_ppd = CProgressDialog_CreateInstance(IDS_COPY_TITLE, IDA_FTPUPLOAD);
  759. if (m_ppd)
  760. {
  761. ASSERT(m_hwnd);
  762. // We give a NULL punkEnableModless because we don't want to go modal.
  763. EVAL(SUCCEEDED(m_ppd->StartProgressDialog(m_hwnd, NULL, PROGDLG_AUTOTIME, NULL)));
  764. }
  765. hr = _CalcUploadProgress();
  766. // Did we succeed creating the directories and counting the
  767. // size we need to copy?
  768. if (SUCCEEDED(hr))
  769. {
  770. if (m_ppd)
  771. {
  772. EVAL(SUCCEEDED(m_ppd->SetProgress64(m_uliBytesCompleted.QuadPart, m_uliBytesTotal.QuadPart)));
  773. // Reset because _CalcUploadProgress() can take a long time and the estimated time
  774. // is based on the time between ::StartProgressDialog() and the first
  775. // ::SetProgress() call.
  776. EVAL(SUCCEEDED(m_ppd->Timer(PDTIMER_RESET, NULL)));
  777. }
  778. hr = _DoCopyIteration();
  779. }
  780. if (m_ppd)
  781. {
  782. EVAL(SUCCEEDED(m_ppd->StopProgressDialog()));
  783. ATOMICRELEASE(m_ppd);
  784. }
  785. SHCoUninitialize(hrOleInit);
  786. Release();
  787. return hr;
  788. }
  789. HRESULT CDropOperation::DoOperation(BOOL fAsync)
  790. {
  791. HRESULT hr = S_OK;
  792. AddRef();
  793. if (fAsync)
  794. {
  795. HANDLE hThread;
  796. DWORD dwThreadId;
  797. hThread = CreateThread(NULL, 0, CDropOperation::_ThreadProc, this, 0, &dwThreadId);
  798. if (hThread)
  799. CloseHandle(hThread);
  800. else
  801. {
  802. TraceMsg(TF_ERROR, "CDropOperation::DoOperation() CreateThread() failed and GetLastError()=%lu.", GetLastError());
  803. Release();
  804. }
  805. }
  806. else
  807. hr = _ThreadProcCB();
  808. return hr;
  809. }
  810. /****************************************************\
  811. FUNCTION: _CalcUploadProgress
  812. DESCRIPTION:
  813. \****************************************************/
  814. HRESULT CDropOperation::_CalcUploadProgress(void)
  815. {
  816. HRESULT hr = S_OK;
  817. LPCWSTR pszzFSSource = m_pszzFSSource;
  818. LPCWSTR pszzFtpDest = m_pszzFtpDest;
  819. WCHAR wzProgressDialogStr[MAX_PATH];
  820. m_uliBytesCompleted.QuadPart = 0;
  821. m_uliBytesTotal.QuadPart = 0;
  822. // Tell the user we are calculating how long it will take.
  823. if (EVAL(LoadStringW(HINST_THISDLL, IDS_PROGRESS_UPLOADTIMECALC, wzProgressDialogStr, ARRAYSIZE(wzProgressDialogStr))))
  824. EVAL(SUCCEEDED(m_ppd->SetLine(2, wzProgressDialogStr, FALSE, NULL)));
  825. while (S_OK == hr)
  826. {
  827. WCHAR szFSSource[MAX_PATH];
  828. WCHAR szFtpDest[MAX_PATH];
  829. hr = _EnumOneHdrop(&pszzFSSource, &pszzFtpDest, szFSSource, ARRAYSIZE(szFSSource), szFtpDest, ARRAYSIZE(szFtpDest));
  830. if (S_OK == hr)
  831. hr = _CalcSizeOneHdrop(szFSSource, szFtpDest, m_ppd);
  832. }
  833. if (FAILED(hr))
  834. TraceMsg(TF_ALWAYS, "CDropOperation::_CalcUploadProgress() Calculating the upload time failed, but oh well.");
  835. return hr;
  836. }
  837. HRESULT CDropOperation::_CalcSizeOneHdrop(LPCWSTR pszFSSource, LPCWSTR pszFtpDest, IProgressDialog * ppd)
  838. {
  839. HRESULT hr;
  840. WCHAR wzTo[MAX_PATH];
  841. EVAL(SUCCEEDED(m_pfd->GetDisplayPath(wzTo, ARRAYSIZE(wzTo))));
  842. pszFtpDest = PathFindFileName(pszFtpDest);
  843. COPYONEHDROPINFO cohi = {0};
  844. cohi.pff = m_pff;
  845. cohi.pszFSSource = pszFSSource;
  846. cohi.pszFtpDest = pszFtpDest;
  847. cohi.pszDir = wzTo;
  848. cohi.dwOperation = COHDI_FILESIZE_COUNT;
  849. cohi.ops = opsPrompt;
  850. cohi.fIsRoot = TRUE;
  851. cohi.pmlc = &m_mlc;
  852. cohi.pidlServer = FtpCloneServerID(m_pff->GetPrivatePidlReference());
  853. cohi.progInfo.ppd = ppd;
  854. cohi.fFireChangeNotify = TRUE;
  855. cohi.progInfo.uliBytesCompleted.QuadPart = m_uliBytesCompleted.QuadPart;
  856. cohi.progInfo.uliBytesTotal.QuadPart = m_uliBytesTotal.QuadPart;
  857. hr = m_pfd->WithHint(NULL, m_hwnd, CopyCB, &cohi, NULL, m_pff);
  858. if (SUCCEEDED(hr))
  859. {
  860. m_uliBytesCompleted = cohi.progInfo.uliBytesCompleted;
  861. m_uliBytesTotal = cohi.progInfo.uliBytesTotal;
  862. }
  863. ILFree(cohi.pidlServer);
  864. return hr;
  865. }
  866. /****************************************************\
  867. FUNCTION: CDropOperation
  868. DESCRIPTION:
  869. \****************************************************/
  870. HRESULT CDropOperation::_DoCopyIteration()
  871. {
  872. HRESULT hr = S_OK;
  873. LPCTSTR pszzFSSource = m_pszzFSSource;
  874. LPCTSTR pszzFtpDest = m_pszzFtpDest;
  875. m_ops = opsPrompt;
  876. while (S_OK == hr)
  877. {
  878. WCHAR szFSSource[MAX_PATH];
  879. WCHAR szFtpDest[MAX_PATH];
  880. hr = _EnumOneHdrop(&pszzFSSource, &pszzFtpDest, szFSSource, ARRAYSIZE(szFSSource), szFtpDest, ARRAYSIZE(szFtpDest));
  881. if (S_OK == hr)
  882. {
  883. szFSSource[lstrlenW(szFSSource)+1] = 0; // Double terminate for SHFileOperation(Delete) in move case
  884. hr = _CopyOneHdrop(szFSSource, szFtpDest);
  885. if (EVAL(m_ppd))
  886. EVAL(SUCCEEDED(m_ppd->SetProgress64(m_uliBytesCompleted.QuadPart, m_uliBytesTotal.QuadPart)));
  887. // Did we fail to copy the file?
  888. if (FAILED(hr) && (HRESULT_FROM_WIN32(ERROR_CANCELLED) != hr))
  889. {
  890. if (!IsValidFtpAnsiFileName(szFSSource) || !IsValidFtpAnsiFileName(szFtpDest))
  891. int nResult = DisplayWininetError(m_hwnd, TRUE, HRESULT_CODE(hr), IDS_FTPERR_TITLE_ERROR, IDS_FTPERR_INVALIDFTPNAME, IDS_FTPERR_WININET, MB_OK, m_ppd);
  892. else
  893. int nResult = DisplayWininetError(m_hwnd, TRUE, HRESULT_CODE(hr), IDS_FTPERR_TITLE_ERROR, IDS_FTPERR_FILECOPY, IDS_FTPERR_WININET, MB_OK, m_ppd);
  894. hr = HRESULT_FROM_WIN32(ERROR_CANCELLED);
  895. }
  896. if (S_FALSE == hr)
  897. {
  898. // _CopyOneHdrop() returning S_FALSE means we hit the end of the iteration,
  899. // in this case, _ConfirmCopy() only meant to skip this one file, so
  900. // change to S_OK to continue with the rest of the files.
  901. hr = S_OK;
  902. }
  903. }
  904. }
  905. Str_SetPtr((LPTSTR *) &m_pszzFSSource, NULL);
  906. Str_SetPtr((LPTSTR *) &m_pszzFtpDest, NULL);
  907. return hr;
  908. }
  909. HRESULT CDropOperation::_ConfirmCopy(LPCWSTR pszLocal, LPCWSTR pszFtpName, BOOL * pfFireChangeNotify)
  910. {
  911. return ConfirmCopy(pszLocal, pszFtpName, &m_ops, m_hwnd, m_pff, m_pfd, NULL, m_cobj, pfFireChangeNotify);
  912. }
  913. /*****************************************************************************\
  914. CopyCB
  915. Callback procedure that copies a single hdrop / map.
  916. \*****************************************************************************/
  917. HRESULT CDropOperation::CopyCB(HINTERNET hint, HINTPROCINFO * phpi, LPVOID pv, BOOL * pfReleaseHint)
  918. {
  919. LPCOPYONEHDROPINFO pcohi = (LPCOPYONEHDROPINFO) pv;
  920. pcohi->progInfo.hint = hint;
  921. HRESULT hr;
  922. InternetSetStatusCallbackWrap(hint, TRUE, FtpProgressInternetStatusCB);
  923. hr = CopyFileSysItem(hint, phpi, pcohi);
  924. if (!pcohi->progInfo.hint)
  925. *pfReleaseHint = FALSE; // We had to close hint to get the cancel.
  926. return hr;
  927. }
  928. HRESULT CDropOperation::_CopyOneHdrop(LPCWSTR pszFSSource, LPCWSTR pszFtpDest)
  929. {
  930. HRESULT hr;
  931. BOOL fFireChangeNotify = TRUE;
  932. pszFtpDest = PathFindFileName(pszFtpDest);
  933. hr = _ConfirmCopy(pszFSSource, pszFtpDest, &fFireChangeNotify);
  934. if (S_OK == hr)
  935. {
  936. WCHAR wzTo[MAX_PATH];
  937. COPYONEHDROPINFO cohi = {0};
  938. cohi.pff = m_pff;
  939. cohi.pszFSSource = pszFSSource;
  940. cohi.pszFtpDest = pszFtpDest;
  941. cohi.pszDir = wzTo;
  942. cohi.dwOperation = COHDI_COPY_FILES;
  943. cohi.ops = m_ops;
  944. cohi.fIsRoot = TRUE;
  945. cohi.pmlc = &m_mlc;
  946. cohi.pidlServer = FtpCloneServerID(m_pff->GetPrivatePidlReference());
  947. cohi.fFireChangeNotify = fFireChangeNotify;
  948. cohi.progInfo.ppd = m_ppd;
  949. cohi.progInfo.uliBytesCompleted.QuadPart = m_uliBytesCompleted.QuadPart;
  950. cohi.progInfo.uliBytesTotal.QuadPart = m_uliBytesTotal.QuadPart;
  951. EVAL(SUCCEEDED(m_pfd->GetDisplayPath(wzTo, ARRAYSIZE(wzTo))));
  952. // TODO: have CopyCB also update the dialog.
  953. hr = m_pfd->WithHint(NULL, m_hwnd, CopyCB, &cohi, NULL, m_pff);
  954. if (SUCCEEDED(hr) && (m_de == DROPEFFECT_MOVE))
  955. {
  956. // We delete the file with SHFileOperation to keep the
  957. // disk free space statistics up to date.
  958. //
  959. // NOTE: If coming from a file name map, maybe it's
  960. // being dragged from the recycle bin, in which case, doing
  961. // an FO_DELETE will put it back in!
  962. SHFILEOPSTRUCT sfo = {0};
  963. sfo.hwnd = NULL, // No HWND so NO UI.
  964. sfo.wFunc = FO_DELETE;
  965. sfo.pFrom = pszFSSource; // Multiple files in list.
  966. sfo.fFlags = (FOF_SILENT | FOF_NOCONFIRMATION /*| FOF_MULTIDESTFILES*/); // No HWND so NO UI.
  967. int nResult = SHFileOperation(&sfo);
  968. if (0 != nResult)
  969. TraceMsg(TF_ALWAYS, "In CDropOperation::_CopyOneHdrop() and caller wanted MOVE but we couldn't delete the files after the copy.");
  970. }
  971. m_uliBytesCompleted = cohi.progInfo.uliBytesCompleted;
  972. m_uliBytesTotal = cohi.progInfo.uliBytesTotal;
  973. m_ops = cohi.ops;
  974. }
  975. else
  976. {
  977. if (S_FALSE == hr)
  978. {
  979. // _CopyOneHdrop() returning S_FALSE means we hit the end of the iteration,
  980. // in this case, _ConfirmCopy() only meant to skip this one file, so
  981. // change to S_OK to continue with the rest of the files.
  982. hr = S_OK;
  983. }
  984. }
  985. return hr;
  986. }
  987. /*****************************************************************************
  988. FUNCTION: SetEffect
  989. DESCRIPTION:
  990. Set the appropriate drop effect feedback.
  991. In the absence of keyboard modifiers, use CTRL (copy), unless
  992. DROPEFFECT_COPY is not available, in which case we use SHIFT (move).
  993. If anything else is set, then panic out to DROPEFFECT_NONE.
  994. Note that we do *not* use g_cfPreferredDe. The only things
  995. we support are DROPEFFECT_COPY and DROPEFFECT_MOVE, and we always prefer DROPEFFECT_COPY.
  996. NOTE: Ignoring g_cfPreferredDe messes up cut/paste, though.
  997. \*****************************************************************************/
  998. HRESULT CFtpDrop::SetEffect(DROPEFFECT * pde)
  999. {
  1000. DWORD de; // Preferred drop effect
  1001. // Don't even think about effects that we don't support
  1002. *pde &= m_grfksAvail;
  1003. switch (m_grfks & (MK_SHIFT | MK_CONTROL))
  1004. {
  1005. case 0: // No modifier, use COPY if possible
  1006. if (*pde & DROPEFFECT_COPY)
  1007. {
  1008. case MK_CONTROL:
  1009. de = DROPEFFECT_COPY;
  1010. }
  1011. else
  1012. {
  1013. case MK_SHIFT:
  1014. de = DROPEFFECT_MOVE;
  1015. }
  1016. break;
  1017. default:
  1018. de = 0;
  1019. break; // Cannot link
  1020. }
  1021. *pde &= de;
  1022. TraceMsg(TF_FTPDRAGDROP, "CFtpDrop::SetEffect(DROPEFFECT=%08x) m_grfksAvail=%08x", *pde, m_grfksAvail);
  1023. return S_OK;
  1024. }
  1025. BOOL CFtpDrop::_IsFTPOperationAllowed(IDataObject * pdto)
  1026. {
  1027. #ifdef FEATURE_FTP_TO_FTP_COPY
  1028. BOOL fIsFTPOperationAllowed = TRUE;
  1029. // There are a few things we don't allow.
  1030. // Is the Drop FTP Location the same
  1031. // folder that the dragged items are already in?
  1032. if (0)
  1033. {
  1034. // TODO:
  1035. }
  1036. return fIsFTPOperationAllowed;
  1037. #else // FEATURE_FTP_TO_FTP_COPY
  1038. // Disallow all FTP Operations
  1039. return !_HasData(pdto, &g_dropTypes[DROP_FTP_PRIVATE]);
  1040. #endif // FEATURE_FTP_TO_FTP_COPY
  1041. }
  1042. /*****************************************************************************\
  1043. GetEffectsAvail
  1044. Look at the object to see what drop effects are available.
  1045. If we have a file group descriptor or an HDROP,
  1046. then file contents are available. (We assume that if you have
  1047. a FGD, then a Contents isn't far behind.)
  1048. In a perfect world, we would also validate the contents of
  1049. each file in the group descriptor, to ensure that the contents
  1050. are droppable. We skimp on that because it's too expensive.
  1051. \*****************************************************************************/
  1052. DWORD CFtpDrop::GetEffectsAvail(IDataObject * pdto)
  1053. {
  1054. DWORD grfksAvail = 0;
  1055. // Is this from an Ftp Shell Extension?
  1056. if (_IsFTPOperationAllowed(pdto))
  1057. {
  1058. // No or it's allowed, then we will accept it. We reject everything
  1059. // else because we can't do Ftp1->Ftp2 copying without
  1060. // using the local machine as a temp location. (Ftp1->Local->Ftp2)
  1061. if (_HasData(pdto, &g_dropTypes[DROP_Hdrop]) ||
  1062. _HasData(pdto, &g_dropTypes[DROP_FGDW]) ||
  1063. _HasData(pdto, &g_dropTypes[DROP_FGDA]))
  1064. {
  1065. TraceMsg(TF_FTPDRAGDROP, "CFtpDrop::GetEffectsAvail() SUCCEEDED");
  1066. grfksAvail = DROPEFFECT_COPY + DROPEFFECT_MOVE;
  1067. }
  1068. else
  1069. {
  1070. TraceMsg(TF_FTPDRAGDROP, "CFtpDrop::GetEffectsAvail() FAILED");
  1071. #ifdef DEBUG
  1072. STGMEDIUM sm;
  1073. HRESULT hres = pdto->GetData(&g_dropTypes[DROP_URL], &sm);
  1074. if (SUCCEEDED(hres))
  1075. {
  1076. TraceMsg(TF_FTPDRAGDROP, "CFtpDrop::GetEffectsAvail(%08x) URL: %hs", pdto, GlobalLock(sm.hGlobal));
  1077. GlobalUnlock(sm.hGlobal);
  1078. ReleaseStgMedium(&sm);
  1079. }
  1080. else
  1081. {
  1082. TraceMsg(TF_FTPDRAGDROP, "CFtpDrop::GetEffectsAvail(%08x) No URL", pdto);
  1083. }
  1084. #endif // DEBUG
  1085. }
  1086. }
  1087. return grfksAvail;
  1088. }
  1089. /*****************************************************************************\
  1090. GetEffect
  1091. Return the drop effect to use.
  1092. If this is a nondefault drag/drop, then put up a menu. Else,
  1093. just go with the default.
  1094. m_de = default effect
  1095. m_pde -> possible effects (and receives result)
  1096. \*****************************************************************************/
  1097. DROPEFFECT CFtpDrop::GetEffect(POINTL pt)
  1098. {
  1099. TraceMsg(TF_FTPDRAGDROP, "CFtpDrop::GetEffect() m_de=%08x. m_grfks=%08x", m_de, m_grfks);
  1100. if (m_de && (m_grfks & MK_RBUTTON))
  1101. {
  1102. HMENU hmenuMain = LoadMenu(g_hinst, MAKEINTRESOURCE(IDM_DROPCONTEXT));
  1103. HMENU hmenu = GetSubMenu(hmenuMain, 0);
  1104. DROPEFFECT de;
  1105. ASSERT(*m_pde & m_de);
  1106. SetMenuDefaultItem(hmenu, m_de, 0);
  1107. if (!(*m_pde & DROPEFFECT_COPY))
  1108. DeleteMenu(hmenu, DROPEFFECT_COPY, MF_BYCOMMAND);
  1109. if (!(*m_pde & DROPEFFECT_MOVE))
  1110. DeleteMenu(hmenu, DROPEFFECT_MOVE, MF_BYCOMMAND);
  1111. // _UNOBVIOUS_: Defview knows special things about itself.
  1112. // If the drop target originated from Shell32.dll, then
  1113. // it leaves the image of the dropped object on the screen
  1114. // while the menu is up, which is nice. Otherwise, it removes
  1115. // the image of the dropped object before the drop target
  1116. // receives its IDropTarget::Drop.
  1117. // Which means that outside shell extensions can't take
  1118. // advantage of the "pretty drop UI" feature.
  1119. // _UNOBVIOUS_: Have to force foregroundness, else the input
  1120. // gets messed up.
  1121. if (m_hwnd)
  1122. SetForegroundWindow(m_hwnd);
  1123. de = TrackPopupMenuEx(hmenu,
  1124. TPM_RETURNCMD | TPM_RIGHTBUTTON | TPM_VERTICAL |
  1125. TPM_LEFTALIGN | TPM_TOPALIGN, pt.x, pt.y,
  1126. m_hwnd, 0);
  1127. DestroyMenu(hmenuMain);
  1128. m_de = de;
  1129. }
  1130. *m_pde = m_de;
  1131. TraceMsg(TF_FTPDRAGDROP, "CFtpDrop::GetEffect(%08x) -> %08x", this, m_de);
  1132. return m_de;
  1133. }
  1134. /****************************************************\
  1135. FUNCTION: _StartBackgroundInteration
  1136. DESCRIPTION:
  1137. \****************************************************/
  1138. HRESULT CFtpDrop::_StartBackgroundInteration(void)
  1139. {
  1140. CDropOperation * pDropOperation;
  1141. HRESULT hr = CDropOperation_Create(m_pff, m_hwnd, m_pszzFSSource, m_pszzFtpDest, &pDropOperation, m_de, m_ops, m_cobj);
  1142. // Did it succeed?
  1143. if (SUCCEEDED(hr))
  1144. {
  1145. // Yes, so NULL out m_pszzFSSource, m_pszzFtpDest because we gave them our copies.
  1146. // Ugly but allocation is uglier.
  1147. m_pszzFSSource = NULL;
  1148. m_pszzFtpDest = NULL;
  1149. EVAL(SUCCEEDED(hr = pDropOperation->DoOperation(TRUE)));
  1150. pDropOperation->Release();
  1151. }
  1152. return hr;
  1153. }
  1154. /****************************************************\
  1155. FUNCTION: _DoCountIteration
  1156. DESCRIPTION:
  1157. \****************************************************/
  1158. HRESULT CFtpDrop::_DoCountIteration(void)
  1159. {
  1160. HRESULT hr = S_OK;
  1161. LPCTSTR pszzFSSource = m_pszzFSSource;
  1162. LPCTSTR pszzFtpDest = m_pszzFtpDest;
  1163. while (S_OK == hr)
  1164. {
  1165. TCHAR szFSSource[MAX_PATH];
  1166. TCHAR szFtpDest[MAX_PATH];
  1167. hr = _EnumOneHdrop(&pszzFSSource, &pszzFtpDest, szFSSource, ARRAYSIZE(szFSSource), szFtpDest, ARRAYSIZE(szFtpDest));
  1168. if (S_OK == hr)
  1169. m_cobj++;
  1170. }
  1171. if (hr == S_FALSE)
  1172. hr = S_OK; // Enumerated to completion
  1173. return hr;
  1174. }
  1175. /****************************************************\
  1176. FUNCTION: _GetFSSourcePaths
  1177. DESCRIPTION:
  1178. \****************************************************/
  1179. HRESULT CFtpDrop::_GetFSSourcePaths(HGLOBAL hdrop, BOOL * pfAnsi)
  1180. {
  1181. LPDROPFILES pdrop = (LPDROPFILES) GlobalLock(hdrop);
  1182. HRESULT hr = E_INVALIDARG;
  1183. *pfAnsi = TRUE;
  1184. if (EVAL(pdrop))
  1185. {
  1186. // Now to decide whether it is an old-style drop or a new-style
  1187. // drop. And if it's a new-style drop, to get the character set.
  1188. if (LOWORD(pdrop->pFiles) == sizeof(DROPFILES16))
  1189. {
  1190. // Old style
  1191. Str_StrAndThunkA((LPTSTR *) &m_pszzFSSource, (LPCSTR) pvByteIndexCb(pdrop, LOWORD(pdrop->pFiles)), TRUE);
  1192. }
  1193. else
  1194. {
  1195. if (pdrop->fWide)
  1196. {
  1197. Str_StrAndThunkW((LPTSTR *) &m_pszzFSSource, (LPCWSTR) pvByteIndexCb(pdrop, pdrop->pFiles), TRUE);
  1198. *pfAnsi = FALSE;
  1199. }
  1200. else
  1201. Str_StrAndThunkA((LPTSTR *) &m_pszzFSSource, (LPCSTR) pvByteIndexCb(pdrop, pdrop->pFiles), TRUE);
  1202. }
  1203. GlobalUnlock(pdrop);
  1204. hr = S_OK;
  1205. }
  1206. return hr;
  1207. }
  1208. /****************************************************\
  1209. FUNCTION: _GetFtpDestPaths
  1210. DESCRIPTION:
  1211. \****************************************************/
  1212. HRESULT CFtpDrop::_GetFtpDestPaths(HGLOBAL hmap, BOOL fAnsi)
  1213. {
  1214. HRESULT hr = E_INVALIDARG;
  1215. LPVOID pmap = NULL;
  1216. // If we can't get a map, then just use the source file names.
  1217. ASSERT(!m_pszzFtpDest);
  1218. if (hmap)
  1219. {
  1220. pmap = GlobalLock(hmap);
  1221. if (pmap)
  1222. {
  1223. if (fAnsi)
  1224. Str_StrAndThunkA((LPTSTR *) &m_pszzFtpDest, (LPCSTR) pmap, TRUE);
  1225. else
  1226. Str_StrAndThunkW((LPTSTR *) &m_pszzFtpDest, (LPCWSTR) pmap, TRUE);
  1227. GlobalUnlock(pmap);
  1228. }
  1229. }
  1230. if (!m_pszzFtpDest)
  1231. {
  1232. // Just copy the Paths
  1233. Str_StrAndThunk((LPTSTR *) &m_pszzFtpDest, m_pszzFSSource, TRUE);
  1234. }
  1235. if (m_pszzFtpDest)
  1236. hr = S_OK;
  1237. return hr;
  1238. }
  1239. /*****************************************************************************\
  1240. CopyHdrop
  1241. Copy an HDROP data object.
  1242. Note also that when we use HDROP, we must also consult the
  1243. FileNameMap otherwise dragging out of the recycle bin directly
  1244. into an FTP folder will create files with the wrong name!
  1245. Note further that the returned effect of an HDROP is always
  1246. DROPEFFECT_COPY, because we will do the work of deleting the
  1247. source files when finished.
  1248. \*****************************************************************************/
  1249. HRESULT CFtpDrop::CopyHdrop(IDataObject * pdto, STGMEDIUM *psm)
  1250. {
  1251. BOOL fAnsi;
  1252. HRESULT hr = _GetFSSourcePaths(psm->hGlobal, &fAnsi);
  1253. if (EVAL(SUCCEEDED(hr)))
  1254. {
  1255. STGMEDIUM sm;
  1256. // ZIP fails this.
  1257. // Get the File name map, too, if one exists
  1258. if (fAnsi)
  1259. hr = pdto->GetData(&g_dropTypes[DROP_FNMA], &sm);
  1260. else
  1261. hr = pdto->GetData(&g_dropTypes[DROP_FNMW], &sm);
  1262. if (FAILED(hr)) // Failure is ok
  1263. sm.hGlobal = 0;
  1264. hr = _GetFtpDestPaths(sm.hGlobal, fAnsi);
  1265. if (EVAL(SUCCEEDED(hr)))
  1266. {
  1267. *m_pde = DROPEFFECT_COPY;
  1268. // Count up how many things there are in the hdrop,
  1269. // so that our confirmation dialog knows what the deal is.
  1270. // We can ignore the error; it'll show up again when we copy.
  1271. m_cobj = 0;
  1272. hr = _DoCountIteration();
  1273. ASSERT(SUCCEEDED(hr));
  1274. TraceMsg(TF_FTPDRAGDROP, "CFtpDrop_CopyHdrop: %d file(s)", m_cobj);
  1275. // Now walk the lists with the appropriate enumerator.
  1276. hr = _StartBackgroundInteration();
  1277. ASSERT(SUCCEEDED(hr));
  1278. }
  1279. if (sm.hGlobal)
  1280. ReleaseStgMedium(&sm);
  1281. }
  1282. return hr;
  1283. }
  1284. /*****************************************************************************\
  1285. _CopyHglobal
  1286. Copy a file contents received as an hglobal.
  1287. If a FD_FILESIZE is provided, use it. Otherwise, just use the size
  1288. of the hglobal.
  1289. \*****************************************************************************/
  1290. HRESULT CFtpDrop::_CopyHglobal(IStream * pstm, DWORD dwFlags, DWORD dwFileSizeHigh, DWORD dwFileSizeLow, LPVOID pvSrc, ULARGE_INTEGER *pqw)
  1291. {
  1292. LPVOID pv;
  1293. HGLOBAL hglob = pvSrc;
  1294. HRESULT hres;
  1295. pqw->HighPart = 0;
  1296. pv = GlobalLock(hglob);
  1297. if (EVAL(pv))
  1298. {
  1299. UINT cb = (UINT) GlobalSize(hglob);
  1300. if (dwFlags & FD_FILESIZE)
  1301. {
  1302. if (cb > dwFileSizeLow)
  1303. cb = dwFileSizeHigh;
  1304. }
  1305. hres = pstm->Write(pv, cb, &pqw->LowPart);
  1306. if (SUCCEEDED(hres))
  1307. {
  1308. if (pqw->LowPart != cb)
  1309. hres = STG_E_MEDIUMFULL;
  1310. }
  1311. GlobalUnlock(pv);
  1312. }
  1313. else
  1314. hres = E_INVALIDARG;
  1315. return hres;
  1316. }
  1317. /*****************************************************************************
  1318. FUNCTION: _GetRelativePidl
  1319. DESCRIPTION:
  1320. pszFullPath may come in this format: "dir1\dir2\dir3\file.txt". We
  1321. need to create *ppidl such that it will contain 4 itemIDs in this case and
  1322. the last one (file.txt) will have the correct attributes and file size.
  1323. \*****************************************************************************/
  1324. CFtpDir * CFtpDrop::_GetRelativePidl(LPCWSTR pszFullPath, DWORD dwFileAttributes, DWORD dwFileSizeHigh, DWORD dwFileSizeLow, LPITEMIDLIST * ppidl)
  1325. {
  1326. HRESULT hr = S_OK;
  1327. WCHAR szFullPath[MAX_PATH];
  1328. LPWSTR pszFileName;
  1329. LPITEMIDLIST pidlFull;
  1330. CFtpDir * pfd = m_pfd; // Assume the Dir to create isn't in a subdir.
  1331. // Find the File Name
  1332. StrCpyNW(szFullPath, pszFullPath, ARRAYSIZE(szFullPath)); // Make a copy because the caller's is read only.
  1333. pszFileName = PathFindFileName(szFullPath); // Find where the file begins.
  1334. FilePathToUrlPathW(szFullPath); // Convert from "dir1\dir2\file.txt" to "dir1/dir2/file.txt"
  1335. *ppidl = NULL;
  1336. hr = CreateFtpPidlFromDisplayPath(szFullPath, m_pff->GetCWireEncoding(), NULL, &pidlFull, TRUE, FALSE);
  1337. if (SUCCEEDED(hr))
  1338. {
  1339. LPITEMIDLIST pidlFile = ILFindLastID(pidlFull);
  1340. SYSTEMTIME st;
  1341. FILETIME ft;
  1342. GetSystemTime(&st);
  1343. SystemTimeToFileTime(&st, &ft);
  1344. FtpPidl_SetAttributes(pidlFile, dwFileAttributes);
  1345. FtpPidl_SetFileSize(pidlFile, dwFileSizeHigh, dwFileSizeLow);
  1346. FtpItemID_SetFileTime(pidlFile, ft);
  1347. // Is the file in a subdir?
  1348. if (!ILIsEmpty(pidlFull) && !ILIsEmpty(_ILNext(pidlFull)))
  1349. {
  1350. // Yes, so generate a CFtpDir to the subdir.
  1351. LPITEMIDLIST pidlPath = ILClone(pidlFull);
  1352. if (pidlPath)
  1353. {
  1354. ILRemoveLastID(pidlPath);
  1355. pfd = m_pfd->GetSubFtpDir(m_pff, pidlPath, FALSE);
  1356. ILFree(pidlPath);
  1357. }
  1358. }
  1359. if (pfd)
  1360. *ppidl = ILClone(pidlFile);
  1361. ILFree(pidlFull);
  1362. }
  1363. return pfd;
  1364. }
  1365. /*****************************************************************************
  1366. FUNCTION: CopyAsStream
  1367. DESCRIPTION:
  1368. Copy a file contents received as a <mumble> to a stream.
  1369. \*****************************************************************************/
  1370. HRESULT CFtpDrop::CopyAsStream(LPCWSTR pszName, DWORD dwFileAttributes, DWORD dwFlags, DWORD dwFileSizeHigh, DWORD dwFileSizeLow, STREAMCOPYPROC pfn, LPVOID pv)
  1371. {
  1372. BOOL fFireChangeNotify;
  1373. HRESULT hr = ConfirmCopy(pszName, pszName, &m_ops, m_hwnd, m_pff, m_pfd, m_pde, m_cobj, &fFireChangeNotify);
  1374. if (SUCCEEDED(hr))
  1375. {
  1376. LPITEMIDLIST pidlRelative;
  1377. CFtpDir * pfd = _GetRelativePidl(pszName, dwFileAttributes, dwFileSizeHigh, dwFileSizeLow, &pidlRelative);
  1378. if (pfd)
  1379. {
  1380. LPITEMIDLIST pidlFull = ILCombine(pfd->GetPidlReference(), pidlRelative);
  1381. if (pidlFull)
  1382. {
  1383. IStream * pstm;
  1384. ULARGE_INTEGER uliTemp = {0};
  1385. hr = CFtpStm_Create(pfd, pidlFull, GENERIC_WRITE, &pstm, uliTemp, uliTemp, NULL, FALSE);
  1386. if (SUCCEEDED(hr))
  1387. {
  1388. ULARGE_INTEGER uli = {dwFileSizeLow, dwFileSizeHigh};
  1389. hr = pfn(pstm, dwFlags, dwFileSizeHigh, dwFileSizeLow, pv, &uli);
  1390. if (SUCCEEDED(hr))
  1391. {
  1392. // Only fire change notify if we didn't replace a file on
  1393. // browser only. (Because we hack the defview and it doesn't
  1394. // check for duplicates)
  1395. if (fFireChangeNotify)
  1396. {
  1397. FtpPidl_SetFileSize(pidlRelative, uli.HighPart, uli.LowPart);
  1398. // This time date stamp may be incorrect.
  1399. FtpChangeNotify(m_hwnd, SHCNE_CREATE, m_pff, pfd, pidlRelative, NULL, TRUE);
  1400. }
  1401. }
  1402. else
  1403. {
  1404. ASSERT(0); // Is there an orphaned file we need to delete?
  1405. DisplayWininetError(m_hwnd, TRUE, HRESULT_CODE(hr), IDS_FTPERR_TITLE_ERROR, IDS_FTPERR_DROPFAIL, IDS_FTPERR_WININET, MB_OK, NULL);
  1406. hr = HRESULT_FROM_WIN32(ERROR_CANCELLED);
  1407. }
  1408. pstm->Release();
  1409. }
  1410. else
  1411. {
  1412. DisplayWininetError(m_hwnd, TRUE, HRESULT_CODE(hr), IDS_FTPERR_TITLE_ERROR, IDS_FTPERR_DROPFAIL, IDS_FTPERR_WININET, MB_OK, NULL);
  1413. hr = HRESULT_FROM_WIN32(ERROR_CANCELLED);
  1414. }
  1415. ILFree(pidlFull);
  1416. }
  1417. else
  1418. hr = E_OUTOFMEMORY;
  1419. if (pfd != m_pfd)
  1420. pfd->Release();
  1421. ILFree(pidlRelative);
  1422. }
  1423. else
  1424. hr = E_FAIL;
  1425. }
  1426. return hr;
  1427. }
  1428. /*****************************************************************************\
  1429. CopyStream
  1430. Copy a file contents received as a stream.
  1431. We ignore the file size in the fgd.
  1432. \*****************************************************************************/
  1433. HRESULT CFtpDrop::CopyStream(IStream * pstm, DWORD dwFlags, DWORD dwFileSizeHigh, DWORD dwFileSizeLow, LPVOID pvSrc, ULARGE_INTEGER *pqw)
  1434. {
  1435. IStream * pstmSrc = (IStream *) pvSrc;
  1436. ULARGE_INTEGER qwMax = {0xFFFFFFFF, 0xFFFFFFFF};
  1437. HRESULT hres;
  1438. hres = pstmSrc->CopyTo(pstm, qwMax, 0, pqw);
  1439. ASSERT(SUCCEEDED(hres));
  1440. return hres;
  1441. }
  1442. /*****************************************************************************\
  1443. FUNCTION: CFtpDrop::CopyStorage
  1444. DESCRIPTION:
  1445. Copy a file contents provided as an IStorage. Gack.
  1446. We have to do this only because of Exchange.
  1447. Since there is no way to tell OLE to create a .doc file
  1448. into an existing stream, we need to create the .doc file
  1449. on disk, and then copy the file into the stream, then delete
  1450. the .doc file.
  1451. Note that CDropOperation::DoOperation() (_CopyOneHdrop) will do the ConfirmCopy
  1452. and the FtpDropNotifyCreate(), too! However, we want to fake
  1453. it out and fool it into thinking we are doing a DROPEFFECT_COPY,
  1454. so that it doesn't delete the "source" file. *We* will delete
  1455. the source file, because we created it. (No need to tell the
  1456. shell about disk size changes that don't affect it.)
  1457. \*****************************************************************************/
  1458. HRESULT CFtpDrop::CopyStorage(LPCWSTR pszFile, IStorage * pstgIn)
  1459. {
  1460. IStorage * pstgOut;
  1461. HRESULT hr = StgCreateDocfile(0, (STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_DIRECT | STGM_CREATE), 0, &pstgOut);
  1462. if (SUCCEEDED(hr))
  1463. {
  1464. STATSTG stat;
  1465. hr = pstgOut->Stat(&stat, STATFLAG_DEFAULT);
  1466. if (EVAL(SUCCEEDED(hr)))
  1467. {
  1468. TCHAR szFSSource[MAX_PATH+3];
  1469. TCHAR szFtpDest[MAX_PATH+3];
  1470. SHUnicodeToTChar(stat.pwcsName, szFSSource, ARRAYSIZE(szFSSource));
  1471. StrCpyN(szFtpDest, pszFile, ARRAYSIZE(szFtpDest));
  1472. szFSSource[lstrlen(szFSSource)+1] = 0; // Add the termination of the list of strings.
  1473. szFtpDest[lstrlen(szFtpDest)+1] = 0; // Add the termination of the list of strings.
  1474. hr = pstgIn->CopyTo(0, 0, 0, pstgOut);
  1475. pstgOut->Commit(STGC_OVERWRITE);
  1476. pstgOut->Release(); // Must release before copying
  1477. pstgOut = NULL;
  1478. if (SUCCEEDED(hr))
  1479. {
  1480. DROPEFFECT deTrue = m_de;
  1481. m_de = DROPEFFECT_COPY;
  1482. CDropOperation * pDropOperation;
  1483. hr = CDropOperation_Create(m_pff, m_hwnd, szFSSource, szFtpDest, &pDropOperation, m_de, m_ops, m_ops);
  1484. // Did it succeed?
  1485. if (SUCCEEDED(hr))
  1486. {
  1487. // Do the operation asynchroniously because the caller may call
  1488. // this over an over.
  1489. EVAL(SUCCEEDED(hr = pDropOperation->DoOperation(FALSE)));
  1490. pDropOperation->Release();
  1491. }
  1492. // Did an error occure and no UI has been displayed yet?
  1493. if (FAILED(hr) && (HRESULT_FROM_WIN32(ERROR_CANCELLED) != hr))
  1494. {
  1495. DisplayWininetError(m_hwnd, TRUE, HRESULT_CODE(hr), IDS_FTPERR_TITLE_ERROR, IDS_FTPERR_FILECOPY, IDS_FTPERR_WININET, MB_OK, NULL);
  1496. }
  1497. m_de = deTrue;
  1498. DeleteFile(szFSSource);
  1499. }
  1500. else
  1501. DisplayWininetError(m_hwnd, TRUE, HRESULT_CODE(hr), IDS_FTPERR_TITLE_ERROR, IDS_FTPERR_DROPFAIL, IDS_FTPERR_WININET, MB_OK, NULL);
  1502. SHFree(stat.pwcsName);
  1503. }
  1504. else
  1505. DisplayWininetError(m_hwnd, TRUE, HRESULT_CODE(hr), IDS_FTPERR_TITLE_ERROR, IDS_FTPERR_DROPFAIL, IDS_FTPERR_WININET, MB_OK, NULL);
  1506. }
  1507. else
  1508. DisplayWininetError(m_hwnd, TRUE, HRESULT_CODE(hr), IDS_FTPERR_TITLE_ERROR, IDS_FTPERR_DROPFAIL, IDS_FTPERR_WININET, MB_OK, NULL);
  1509. return hr;
  1510. }
  1511. /*****************************************************************************\
  1512. CopyFCont
  1513. Copy a file contents.
  1514. \*****************************************************************************/
  1515. HRESULT CFtpDrop::CopyFCont(LPCWSTR pszName, DWORD dwFileAttributes, DWORD dwFlags, DWORD dwFileSizeHigh, DWORD dwFileSizeLow, STGMEDIUM *psm)
  1516. {
  1517. HRESULT hres;
  1518. switch (psm->tymed)
  1519. {
  1520. case TYMED_HGLOBAL:
  1521. hres = CopyAsStream(pszName, dwFileAttributes, dwFlags, dwFileSizeHigh, dwFileSizeLow, _CopyHglobal, psm->hGlobal);
  1522. break;
  1523. case TYMED_ISTREAM:
  1524. hres = CopyAsStream(pszName, dwFileAttributes, dwFlags, dwFileSizeHigh, dwFileSizeLow, CopyStream, psm->pstm);
  1525. break;
  1526. case TYMED_ISTORAGE: // Exchange
  1527. hres = CopyStorage(pszName, psm->pstg);
  1528. break;
  1529. default:
  1530. ASSERT(0);
  1531. // Shouldn't have gotten this.
  1532. hres = E_INVALIDARG;
  1533. break;
  1534. }
  1535. return hres;
  1536. }
  1537. HRESULT CFtpDrop::_GetFileDescriptor(LONG nIndex, LPFILEGROUPDESCRIPTORW pfgdW, LPFILEGROUPDESCRIPTORA pfgdA, BOOL fUnicode, LPFILEDESCRIPTOR pfd)
  1538. {
  1539. if (fUnicode)
  1540. {
  1541. LPFILEDESCRIPTORW pfdW = &pfgdW->fgd[nIndex];
  1542. CopyMemory(pfd, pfdW, (sizeof(*pfdW) - sizeof(pfdW->cFileName))); // Copy Everything except the name.
  1543. SHUnicodeToTChar(pfdW->cFileName, pfd->cFileName, ARRAYSIZE(pfd->cFileName));
  1544. }
  1545. else
  1546. {
  1547. LPFILEDESCRIPTORA pfdA = &pfgdA->fgd[nIndex];
  1548. CopyMemory(pfd, pfdA, (sizeof(*pfdA) - sizeof(pfdA->cFileName))); // Copy Everything except the name.
  1549. SHAnsiToTChar(pfdA->cFileName, pfd->cFileName, ARRAYSIZE(pfd->cFileName));
  1550. }
  1551. return S_OK;
  1552. }
  1553. HRESULT CFtpDrop::_CreateFGDDirectory(LPFILEDESCRIPTOR pFileDesc)
  1554. {
  1555. HRESULT hr = S_OK;
  1556. WCHAR szDirName[MAX_PATH];
  1557. LPTSTR pszDirToCreate = PathFindFileName(pFileDesc->cFileName);
  1558. FTPCREATEFOLDERSTRUCT fcfs = {szDirName, m_pff};
  1559. CFtpDir * pfd = m_pfd; // Assume the Dir to create isn't in a subdir.
  1560. SHTCharToUnicode(pszDirToCreate, szDirName, ARRAYSIZE(szDirName));
  1561. pszDirToCreate[0] = 0; // Separate Dir to create from SubDir where to create it.
  1562. // Is the dir to create in subdir?
  1563. if (pFileDesc->cFileName[0])
  1564. {
  1565. // Yes, so let's get that CFtpDir pointer so WithHint below will get us there.
  1566. LPITEMIDLIST pidlPath;
  1567. FilePathToUrlPathW(pFileDesc->cFileName);
  1568. hr = CreateFtpPidlFromDisplayPath(pFileDesc->cFileName, m_pff->GetCWireEncoding(), NULL, &pidlPath, TRUE, TRUE);
  1569. if (SUCCEEDED(hr))
  1570. {
  1571. pfd = m_pfd->GetSubFtpDir(m_pff, pidlPath, FALSE);
  1572. if (!pfd)
  1573. {
  1574. hr = E_OUTOFMEMORY;
  1575. }
  1576. ILFree(pidlPath);
  1577. }
  1578. }
  1579. if (SUCCEEDED(hr))
  1580. {
  1581. hr = pfd->WithHint(NULL, m_hwnd, CreateNewFolderCB, (LPVOID) &fcfs, NULL, m_pff);
  1582. if (SUCCEEDED(hr))
  1583. {
  1584. }
  1585. else
  1586. {
  1587. // TODO: Display error UI?
  1588. }
  1589. }
  1590. if (m_pfd != pfd)
  1591. {
  1592. // We allocated pfd, so now let's free it.
  1593. pfd->Release();
  1594. }
  1595. return hr;
  1596. }
  1597. /*****************************************************************************\
  1598. CopyFGD
  1599. Copy a file group descriptor.
  1600. File group descriptors are used to source gizmos that are file-like
  1601. but aren't stored on disk as such. E.g., an embedded file in a
  1602. mail message, a GIF image in a web page, an OLE scrap, or a file
  1603. on a remote FTP site.
  1604. _UNOBVIOUS_: If you do a GetData on TYMED_HGLOBAL | TYMED_ISTREAM,
  1605. Exchange will nonetheless give you a TYMED_ISTORAGE even though
  1606. you didn't ask for it. So we need to support IStorage in order
  1607. to make Exchange look less broken. (Maybe I shouldn't cover for
  1608. them. Or maybe I should send them a bill.)
  1609. \*****************************************************************************/
  1610. HRESULT CFtpDrop::CopyFGD(IDataObject * pdto, STGMEDIUM *psm, BOOL fUnicode)
  1611. {
  1612. LPFILEGROUPDESCRIPTORA pfgdA = NULL;
  1613. LPFILEGROUPDESCRIPTORW pfgdW = NULL;
  1614. HRESULT hr = E_INVALIDARG;
  1615. // WARNING:
  1616. // shell32.dll from Win95, WinNT 4, IE 3, IE 4, and IE 4.01 have
  1617. // a bug that cause recursive file download not to work for
  1618. // subdirectories on WinNT unless we implement FILEGROUPDESCRIPTORW.
  1619. if (fUnicode)
  1620. pfgdW = (LPFILEGROUPDESCRIPTORW) GlobalLock((LPFILEGROUPDESCRIPTORW *) psm->hGlobal);
  1621. else
  1622. pfgdA = (LPFILEGROUPDESCRIPTORA) GlobalLock((FILEGROUPDESCRIPTORA *) psm->hGlobal);
  1623. if (EVAL(pfgdA || pfgdW))
  1624. {
  1625. FORMATETC fe = {g_dropTypes[DROP_FCont].cfFormat, 0, DVASPECT_CONTENT, 0, (TYMED_ISTREAM | TYMED_HGLOBAL | TYMED_ISTORAGE)};
  1626. // Exchange
  1627. DWORD dwSize = m_cobj = (pfgdW ? pfgdW->cItems : pfgdA->cItems);
  1628. TraceMsg(TF_FTPDRAGDROP, "CFtpDrop::CopyFGD: %d files", m_cobj);
  1629. hr = S_OK; // Watch out for vacuous null case
  1630. for (; ((UINT)fe.lindex < dwSize); fe.lindex++)
  1631. {
  1632. FILEDESCRIPTOR fileDescriptor = {0};
  1633. if (EVAL(SUCCEEDED(_GetFileDescriptor(fe.lindex, pfgdW, pfgdA, fUnicode, &fileDescriptor))))
  1634. {
  1635. // Is this a folder?
  1636. if ((FD_ATTRIBUTES & fileDescriptor.dwFlags) &&
  1637. FILE_ATTRIBUTE_DIRECTORY & fileDescriptor.dwFileAttributes)
  1638. {
  1639. // Yes, so let's create it. We currently don't copy folder
  1640. // info. (ACLs or other attributes)
  1641. hr = _CreateFGDDirectory(&fileDescriptor);
  1642. }
  1643. else
  1644. {
  1645. // No, so it's a file. Let's get the stream and then upload that to the FTP server.
  1646. STGMEDIUM sm;
  1647. hr = pdto->GetData(&fe, &sm);
  1648. if (SUCCEEDED(hr))
  1649. {
  1650. hr = CopyFCont(fileDescriptor.cFileName, fileDescriptor.dwFileAttributes, fileDescriptor.dwFlags, fileDescriptor.nFileSizeHigh, fileDescriptor.nFileSizeLow, &sm);
  1651. ReleaseStgMedium(&sm);
  1652. if (FAILED(hr))
  1653. {
  1654. break;
  1655. }
  1656. }
  1657. else
  1658. {
  1659. ASSERT(0);
  1660. break;
  1661. }
  1662. }
  1663. }
  1664. }
  1665. if (pfgdW)
  1666. GlobalUnlock(pfgdW);
  1667. if (pfgdA)
  1668. GlobalUnlock(pfgdA);
  1669. }
  1670. return hr;
  1671. }
  1672. /*****************************************************************************\
  1673. _Copy
  1674. Copy the data object into the shell folder.
  1675. HDROPs are preferred, because we can use FtpPutFile to shove
  1676. them onto the FTP site without getting our hands dirty.
  1677. Failing that, we use FileGroupDescriptor, which lets us
  1678. get at pseudo-files.
  1679. Note also that if you use HDROP, you need to support FileNameMap
  1680. otherwise dragging out of the recycle bin directly into an FTP
  1681. folder will create files with the wrong name!
  1682. If a single file is cancelled, should I return DROPEFFECT_NONE?
  1683. \*****************************************************************************/
  1684. HRESULT CFtpDrop::_Copy(IDataObject * pdto)
  1685. {
  1686. STGMEDIUM sm;
  1687. HRESULT hr;
  1688. if (SUCCEEDED(hr = pdto->GetData(&g_dropTypes[DROP_Hdrop], &sm)))
  1689. {
  1690. hr = CopyHdrop(pdto, &sm);
  1691. ReleaseStgMedium(&sm);
  1692. }
  1693. else
  1694. {
  1695. BOOL fSupportsUnicode = SUCCEEDED(hr = pdto->GetData(&g_dropTypes[DROP_FGDW], &sm));
  1696. if (fSupportsUnicode || EVAL(SUCCEEDED(hr = pdto->GetData(&g_dropTypes[DROP_FGDA], &sm))))
  1697. {
  1698. hr = CopyFGD(pdto, &sm, fSupportsUnicode);
  1699. ReleaseStgMedium(&sm);
  1700. }
  1701. }
  1702. // Normally we would set the PASTESUCCEEDED info back into
  1703. // the IDataObject but we don't because we do an optimized
  1704. // MOVE by doing a DELETE after the COPY operation.
  1705. // We do this because we do the operation on a background thread
  1706. // in order to be asynch and we don't want to extend the lifetime
  1707. // of the IDataObject that long. Therefore we push
  1708. // DROPEFFECT_COPY back into the caller to tell them that
  1709. // we did an optimized move and to not delete the items.
  1710. //
  1711. // TODO: We need to test the CopyFGD() code above and
  1712. // maybe use PasteSucceeded(DROPEFFECT_MOVE) in
  1713. // that case.
  1714. if (SUCCEEDED(hr) && (m_de == DROPEFFECT_MOVE))
  1715. {
  1716. // Always set "Copy" because we did an optimized move
  1717. // because we deleted the files our selfs.
  1718. DataObj_SetPasteSucceeded(pdto, DROPEFFECT_COPY);
  1719. }
  1720. return hr;
  1721. }
  1722. //===========================
  1723. // *** IDropTarget Interface ***
  1724. //===========================
  1725. /*****************************************************************************
  1726. IDropTarget::DragEnter
  1727. *****************************************************************************/
  1728. HRESULT CFtpDrop::DragEnter(IDataObject * pdto, DWORD grfKeyState, POINTL pt, DROPEFFECT * pde)
  1729. {
  1730. HRESULT hr;
  1731. m_grfks = grfKeyState; // Remember last key state
  1732. m_grfksAvail = GetEffectsAvail(pdto);
  1733. hr = SetEffect(pde);
  1734. ASSERT(SUCCEEDED(hr));
  1735. TraceMsg(TF_FTPDRAGDROP, "CFtpDrop::DragEnter(grfKeyState=%08x, DROPEFFECT=%08x) m_grfks=%08x. m_grfksAvail=%08x hres=%#08lx", grfKeyState, *pde, m_grfks, m_grfksAvail, hr);
  1736. return hr;
  1737. }
  1738. /*****************************************************************************
  1739. IDropTarget::DragOver
  1740. *****************************************************************************/
  1741. HRESULT CFtpDrop::DragOver(DWORD grfKeyState, POINTL pt, DROPEFFECT * pde)
  1742. {
  1743. HRESULT hr;
  1744. m_grfks = grfKeyState; // Remember last key state
  1745. hr = SetEffect(pde);
  1746. ASSERT(SUCCEEDED(hr));
  1747. TraceMsg(TF_FTPDRAGDROP, "CFtpDrop::DragOver(grfKeyState=%08x, DROPEFFECT=%08x) m_grfks=%08x. SetEffect() returned hres=%#08lx", grfKeyState, *pde, m_grfks, hr);
  1748. return hr;
  1749. }
  1750. /*****************************************************************************
  1751. IDropTarget::DragLeave
  1752. *****************************************************************************/
  1753. HRESULT CFtpDrop::DragLeave(void)
  1754. {
  1755. TraceMsg(TF_FTPDRAGDROP, "CFtpDrop::DragLeave() ");
  1756. return S_OK;
  1757. }
  1758. /*****************************************************************************\
  1759. IDropTarget::Drop
  1760. Note that the incoming pdto is not necessarily the same as the
  1761. one we saw on DragEnter. OLE will first give us a "preliminary"
  1762. data object to play with, but on the drop, it will give us a
  1763. fully marshalled object.
  1764. Fortunately, we don't care, because we didn't cache the object.
  1765. Note that we don't pass the real pde to SetEffect, because
  1766. we don't want to lose the list of all possible effects before
  1767. GetEffect uses it.
  1768. \*****************************************************************************/
  1769. HRESULT CFtpDrop::Drop(IDataObject * pdo, DWORD grfKeyState, POINTL pt, DROPEFFECT * pde)
  1770. {
  1771. HRESULT hr;
  1772. m_ops = opsPrompt; // Start out in prompt mode
  1773. m_grfksAvail = GetEffectsAvail(pdo);
  1774. m_pde = pde;
  1775. m_de = *pde;
  1776. hr = SetEffect(&m_de);
  1777. TraceMsg(TF_FTPDRAGDROP, "CFtpDrop::Drop(grfKeyState=%08x, DROPEFFECT=%08x) m_grfksAvail=%08x. m_de=%08x. SetEffect() returned hres=%#08lx", grfKeyState, *pde, m_grfksAvail, m_de, hr);
  1778. if (EVAL(SUCCEEDED(hr)))
  1779. {
  1780. if (GetEffect(pt))
  1781. {
  1782. hr = _Copy(pdo);
  1783. }
  1784. else
  1785. hr = S_FALSE; // Indicate cancel.
  1786. }
  1787. if (!(SUCCEEDED(hr)))
  1788. {
  1789. // Error message already has been displayed.
  1790. *pde = 0;
  1791. }
  1792. return hr;
  1793. }
  1794. /*****************************************************************************\
  1795. CFtpDrop_Create
  1796. \*****************************************************************************/
  1797. HRESULT CFtpDrop_Create(CFtpFolder * pff, HWND hwnd, CFtpDrop ** ppfdt)
  1798. {
  1799. HRESULT hres = E_OUTOFMEMORY;
  1800. CFtpDrop * pfdt = new CFtpDrop();
  1801. *ppfdt = pfdt;
  1802. if (pfdt)
  1803. {
  1804. pfdt->m_hwnd = hwnd;
  1805. // Copy the CFtpFolder * value
  1806. pfdt->m_pff = pff;
  1807. if (pff)
  1808. pff->AddRef();
  1809. // Copy the CFtpDir * value
  1810. ASSERT(!pfdt->m_pfd);
  1811. pfdt->m_pfd = pff->GetFtpDir();
  1812. hres = pfdt->m_pfd ? S_OK : E_FAIL;
  1813. if (FAILED(hres)) // Will fail if the caller is CFtpMenu::_RemoveContextMenuItems() and it's OK.
  1814. ATOMICRELEASE(*ppfdt);
  1815. }
  1816. ASSERT_POINTER_MATCHES_HRESULT(*ppfdt, hres);
  1817. return hres;
  1818. }
  1819. /****************************************************\
  1820. Constructor
  1821. \****************************************************/
  1822. CFtpDrop::CFtpDrop() : m_cRef(1)
  1823. {
  1824. DllAddRef();
  1825. // This needs to be allocated in Zero Inited Memory.
  1826. // Assert that all Member Variables are inited to Zero.
  1827. ASSERT(!m_pff);
  1828. ASSERT(!m_pfd);
  1829. ASSERT(!m_hwnd);
  1830. ASSERT(!m_grfks);
  1831. ASSERT(!m_grfksAvail);
  1832. ASSERT(!m_pde);
  1833. ASSERT(!m_cobj);
  1834. LEAK_ADDREF(LEAK_CFtpDrop);
  1835. }
  1836. /****************************************************\
  1837. Destructor
  1838. \****************************************************/
  1839. CFtpDrop::~CFtpDrop()
  1840. {
  1841. IUnknown_Set(&m_pff, NULL);
  1842. IUnknown_Set(&m_pfd, NULL);
  1843. DllRelease();
  1844. LEAK_DELREF(LEAK_CFtpDrop);
  1845. }
  1846. //===========================
  1847. // *** IUnknown Interface ***
  1848. //===========================
  1849. ULONG CFtpDrop::AddRef()
  1850. {
  1851. m_cRef++;
  1852. return m_cRef;
  1853. }
  1854. ULONG CFtpDrop::Release()
  1855. {
  1856. ASSERT(m_cRef > 0);
  1857. m_cRef--;
  1858. if (m_cRef > 0)
  1859. return m_cRef;
  1860. delete this;
  1861. return 0;
  1862. }
  1863. HRESULT CFtpDrop::QueryInterface(REFIID riid, void **ppvObj)
  1864. {
  1865. if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IDropTarget))
  1866. {
  1867. *ppvObj = SAFECAST(this, IDropTarget*);
  1868. }
  1869. else
  1870. {
  1871. TraceMsg(TF_FTPQI, "CFtpDrop::QueryInterface() failed.");
  1872. *ppvObj = NULL;
  1873. return E_NOINTERFACE;
  1874. }
  1875. AddRef();
  1876. return S_OK;
  1877. }