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.

753 lines
24 KiB

  1. /*****************************************************************************\
  2. FILE: ftpdhlp.cpp
  3. DESCRIPTION:
  4. Replace strings in a dialog template with attributes about an FTP
  5. item (ftp server, ftp dir, or ftp file).
  6. \*****************************************************************************/
  7. #include "priv.h"
  8. #include "ftpurl.h"
  9. #include "ftpdhlp.h"
  10. #define SZ_WSPRINTFSTR_S TEXT("%s")
  11. #define SZ_WSPRINTFSTR_U TEXT("%u")
  12. class CSizeHolder
  13. {
  14. public:
  15. BOOL IsAllFolders(void) {return m_fAllFolders;};
  16. void FoundNonFolder(void) {m_fAllFolders = FALSE;};
  17. HRESULT GetError(void) {return m_hr;};
  18. void SetError(HRESULT hr) {m_hr = hr;};
  19. void AddSize(ULONGLONG ullSizeToAdd) { m_ullTotalSize += ullSizeToAdd;};
  20. ULONGLONG GetTotalSize(void) {return m_ullTotalSize;};
  21. CSizeHolder() {m_ullTotalSize = 0; m_fAllFolders = TRUE; m_hr = S_OK;};
  22. ~CSizeHolder() {};
  23. private:
  24. BOOL m_fAllFolders;
  25. HRESULT m_hr;
  26. ULONGLONG m_ullTotalSize;
  27. };
  28. HRESULT CFtpDialogTemplate::_ReinsertDlgText(HWND hwnd, LPCVOID pv, LPCTSTR ptszFormat)
  29. {
  30. TCHAR szDlgTemplate[256];
  31. TCHAR szFinalString[1024]; // wnsprintf maxes at 1024
  32. GetWindowText(hwnd, szDlgTemplate, ARRAYSIZE(szDlgTemplate));
  33. wnsprintf(szFinalString, ARRAYSIZE(szFinalString), szDlgTemplate, pv);
  34. // Are they the same?
  35. if (!StrCmp(szDlgTemplate, szFinalString))
  36. wnsprintf(szFinalString, ARRAYSIZE(szFinalString), ptszFormat, pv); // Yes
  37. SetWindowText(hwnd, szFinalString);
  38. return S_OK;
  39. }
  40. /*****************************************************************************\
  41. FUNCTION: _ReplaceIcon
  42. DESCRIPTION:
  43. \*****************************************************************************/
  44. HRESULT CFtpDialogTemplate::_ReplaceIcon(HWND hwnd, HICON hicon)
  45. {
  46. hicon = (HICON)SendMessage(hwnd, STM_SETICON, (WPARAM)hicon, 0L);
  47. if (hicon)
  48. {
  49. DestroyIcon(hicon);
  50. }
  51. return S_OK;
  52. }
  53. /*****************************************************************************\
  54. FUNCTION: _InitIcon
  55. DESCRIPTION:
  56. _HACKHACK_ We go straight to CFtpIcon to get the pxi
  57. instead of going through CFtpFolder. Same effect, but
  58. saves some memory allocations. What's more important,
  59. we don't necessarily have a psf to play with, so we really
  60. have no choice.
  61. Yes, it's gross.
  62. \*****************************************************************************/
  63. HRESULT CFtpDialogTemplate::_InitIcon(HWND hwnd, CFtpFolder * pff, CFtpPidlList * pflHfpl)
  64. {
  65. IExtractIcon * pxi;
  66. HRESULT hr;
  67. if (pflHfpl && pflHfpl->GetCount() == 1)
  68. {
  69. SHFILEINFO sfi;
  70. hr = FtpPidl_GetFileInfo(pflHfpl->GetPidl(0), &sfi, SHGFI_ICON | SHGFI_LARGEICON);
  71. if (SUCCEEDED(hr))
  72. hr = _ReplaceIcon(hwnd, sfi.hIcon);
  73. }
  74. else
  75. {
  76. hr = CFtpIcon_Create(pff, pflHfpl, IID_IExtractIcon, (LPVOID *)&pxi);
  77. if (SUCCEEDED(hr))
  78. {
  79. TCHAR szPath[MAX_PATH];
  80. int i;
  81. UINT ui;
  82. hr = pxi->GetIconLocation(0, szPath, ARRAYSIZE(szPath), &i, &ui);
  83. if (EVAL(SUCCEEDED(hr)))
  84. {
  85. CHAR szPathAnsi[MAX_PATH];
  86. SHTCharToAnsi(szPath, szPathAnsi, ARRAYSIZE(szPathAnsi));
  87. hr = _ReplaceIcon(hwnd, ExtractIconA(g_hinst, szPathAnsi, i));
  88. }
  89. ASSERT(pxi);
  90. pxi->Release();
  91. }
  92. }
  93. return hr;
  94. }
  95. void GetItemName(CFtpFolder * pff, CFtpPidlList * pflHfpl, LPWSTR pwzName, DWORD cchSize)
  96. {
  97. // Are multiple items selected?
  98. if (1 < pflHfpl->GetCount())
  99. LoadString(HINST_THISDLL, IDS_SEVERAL_SELECTED, pwzName, cchSize);
  100. else
  101. {
  102. LPCITEMIDLIST pidl;
  103. if (0 == pflHfpl->GetCount())
  104. pidl = FtpID_GetLastIDReferense(pff->GetPrivatePidlReference());
  105. else
  106. pidl = FtpID_GetLastIDReferense(pflHfpl->GetPidl(0));
  107. if (pidl)
  108. FtpPidl_GetDisplayName(pidl, pwzName, cchSize);
  109. }
  110. }
  111. BOOL CanEditName(CFtpFolder * pff, CFtpPidlList * pflHfpl)
  112. {
  113. int nNumItems = pflHfpl->GetCount();
  114. BOOL fCanRename = TRUE;
  115. // we can edit except for multiply selected items
  116. if (2 <= nNumItems)
  117. fCanRename = FALSE;
  118. else
  119. {
  120. // If they chose the background properties for a server,
  121. // we won't let the change the server name.
  122. if (0 == nNumItems)
  123. {
  124. LPCITEMIDLIST pidlFolder = pff->GetPrivatePidlReference();
  125. if (pidlFolder && (ILIsEmpty(pidlFolder) || (ILIsEmpty(_ILNext(pidlFolder)))))
  126. {
  127. fCanRename = FALSE;
  128. }
  129. }
  130. else if (1 == nNumItems)
  131. {
  132. // Now I'm worried that pflHfpl->GetPidl(0) is a PIDL pointing to
  133. // an FTP Server.
  134. LPCITEMIDLIST pidl = pflHfpl->GetPidl(0);
  135. if (pidl && !ILIsEmpty(pidl) &&
  136. FtpID_IsServerItemID(pidl) && ILIsEmpty(_ILNext(pidl)))
  137. {
  138. fCanRename = FALSE;
  139. }
  140. }
  141. }
  142. return fCanRename;
  143. }
  144. /*****************************************************************************\
  145. FUNCTION: _InitName
  146. DESCRIPTION:
  147. Get the name of the object in the pflHfpl. If there is more than one
  148. thing, use ellipses.
  149. \*****************************************************************************/
  150. HRESULT CFtpDialogTemplate::_InitName(HWND hwnd, CFtpFolder * pff, CFtpPidlList * pflHfpl)
  151. {
  152. HRESULT hr = S_OK;
  153. WCHAR wzName[MAX_PATH];
  154. GetItemName(pff, pflHfpl, wzName, ARRAYSIZE(wzName));
  155. hr = _ReinsertDlgText(hwnd, wzName, SZ_WSPRINTFSTR_S);
  156. // We only use the static filename when more than one item is selected
  157. // because that is the case that we can't do a rename. Are there
  158. // multiple items selected?
  159. if (m_fEditable && CanEditName(pff, pflHfpl))
  160. {
  161. // Hide because we will use IDC_FILENAME_EDITABLE instead.
  162. ShowEnableWindow(hwnd, FALSE);
  163. }
  164. return hr;
  165. }
  166. /*****************************************************************************\
  167. FUNCTION: _InitNameEditable
  168. DESCRIPTION:
  169. Get the name of the object in the pflHfpl. If there is more than one
  170. thing, use ellipses.
  171. \*****************************************************************************/
  172. HRESULT CFtpDialogTemplate::_InitNameEditable(HWND hwnd, CFtpFolder * pff, CFtpPidlList * pflHfpl)
  173. {
  174. HRESULT hr = S_OK;
  175. TCHAR szName[MAX_PATH];
  176. GetItemName(pff, pflHfpl, szName, ARRAYSIZE(szName));
  177. hr = _ReinsertDlgText(hwnd, szName, SZ_WSPRINTFSTR_S);
  178. // We only use the static filename when more than one item is selected
  179. // because that is the case that we can't do a rename. Are there
  180. // multiple items selected?
  181. if (!m_fEditable || !CanEditName(pff, pflHfpl))
  182. {
  183. // Hide because we will use IDC_FILENAME_EDITABLE instead.
  184. ShowEnableWindow(hwnd, FALSE);
  185. }
  186. return hr;
  187. }
  188. void GetNameFromPidlList(CFtpFolder * pff, CFtpPidlList * pflHfpl, LPWSTR pwzName, DWORD cchSize)
  189. {
  190. LPCITEMIDLIST pidl;
  191. if (0 == pflHfpl->GetCount())
  192. pidl = FtpID_GetLastIDReferense(pff->GetPrivatePidlReference());
  193. else
  194. pidl = FtpID_GetLastIDReferense(pflHfpl->GetPidl(0));
  195. if (pidl)
  196. {
  197. FtpPidl_GetLastItemDisplayName(pidl, pwzName, cchSize);
  198. }
  199. }
  200. /*****************************************************************************\
  201. FUNCTION: _InitType
  202. DESCRIPTION:
  203. Get the type of the pidls identified by pflHfpl.
  204. \*****************************************************************************/
  205. HRESULT CFtpDialogTemplate::_InitType(HWND hwnd, CFtpFolder * pff, CFtpPidlList * pflHfpl)
  206. {
  207. TCHAR szType[MAX_URL_STRING];
  208. szType[0] = 0;
  209. switch (pflHfpl->GetCount())
  210. {
  211. case 0:
  212. {
  213. // Find out if it's a folder or an ftp server root.
  214. LPCITEMIDLIST pidl = FtpID_GetLastIDReferense(pff->GetPrivatePidlReference());
  215. if (pidl)
  216. LoadString(HINST_THISDLL, (FtpID_IsServerItemID(pidl) ? IDS_ITEMTYPE_SERVER : IDS_ITEMTYPE_FOLDER), szType, ARRAYSIZE(szType));
  217. }
  218. break;
  219. case 1:
  220. // Just one item is selected, so get it's type.
  221. FtpPidl_GetFileType(pflHfpl->GetPidl(0), szType, ARRAYSIZE(szType));
  222. break;
  223. default:
  224. // Display "Several Selected" because they can span 1 type.
  225. LoadString(HINST_THISDLL, IDS_SEVERAL_SELECTED, szType, ARRAYSIZE(szType));
  226. break;
  227. }
  228. return _ReinsertDlgText(hwnd, szType, SZ_WSPRINTFSTR_S);
  229. }
  230. /*****************************************************************************\
  231. FUNCTION: _InitLocation
  232. DESCRIPTION:
  233. Get the name of the folder identified by pidl.
  234. \*****************************************************************************/
  235. HRESULT CFtpDialogTemplate::_InitLocation(HWND hwnd, CFtpFolder * pff, CFtpPidlList * pidlList)
  236. {
  237. HRESULT hr = E_FAIL;
  238. TCHAR szUrl[MAX_PATH];
  239. LPITEMIDLIST pidl = GetPidlFromFtpFolderAndPidlList(pff, pidlList);
  240. ASSERT(pidlList && pff);
  241. if (pidl)
  242. {
  243. // If more than one items are selected, then we only want to
  244. // show the common location.
  245. if (1 < pidlList->GetCount())
  246. ILRemoveLastID(pidl);
  247. hr = UrlCreateFromPidl(pidl, SHGDN_FORADDRESSBAR, szUrl, ARRAYSIZE(szUrl), 0, TRUE);
  248. if (SUCCEEDED(hr))
  249. {
  250. hr = _ReinsertDlgText(hwnd, szUrl, SZ_WSPRINTFSTR_S);
  251. }
  252. ILFree(pidl);
  253. }
  254. return hr;
  255. }
  256. /*****************************************************************************\
  257. FUNCTION: _InitSizeTally
  258. DESCRIPTION:
  259. Total up the size of each file referred to in the pidl.
  260. \*****************************************************************************/
  261. int CFtpDialogTemplate::_InitSizeTally(LPVOID pvPidl, LPVOID pvSizeHolder)
  262. {
  263. BOOL fSuccess = TRUE;
  264. LPCITEMIDLIST pidl = (LPCITEMIDLIST) pvPidl;
  265. CSizeHolder * pSizeHolder = (CSizeHolder *) pvSizeHolder;
  266. // Did we get a valid size and is pSizeHolder still valid?
  267. if (SUCCEEDED(pSizeHolder->GetError()))
  268. {
  269. // Yes, so keep accumulating if it's a file.
  270. if (!FtpID_IsServerItemID(pidl) && !FtpItemID_IsDirectory(pidl, FALSE))
  271. {
  272. ULARGE_INTEGER uliPidlFileSize;
  273. uliPidlFileSize.QuadPart = FtpItemID_GetFileSize(pidl);
  274. pSizeHolder->AddSize(uliPidlFileSize.QuadPart);
  275. pSizeHolder->FoundNonFolder(); // Show that at least one was a file.
  276. if (!uliPidlFileSize.QuadPart)
  277. fSuccess = FALSE;
  278. }
  279. }
  280. else
  281. {
  282. pSizeHolder->SetError(E_FAIL);
  283. fSuccess = FALSE;
  284. }
  285. return fSuccess;
  286. }
  287. #define MAX_FILE_SIZE 64
  288. HRESULT GetFileSizeFromULargeInteger(ULARGE_INTEGER uliSize, LPTSTR pszSizeStr, DWORD cchSize)
  289. {
  290. WCHAR wzSizeStr[MAX_FILE_SIZE];
  291. LONGLONG llSize = (LONGLONG) uliSize.QuadPart;
  292. if (StrFormatByteSizeW(llSize, wzSizeStr, ARRAYSIZE(wzSizeStr)))
  293. SHUnicodeToTChar(wzSizeStr, pszSizeStr, cchSize);
  294. else
  295. {
  296. CHAR szStrStrA[MAX_FILE_SIZE];
  297. StrFormatByteSizeA(uliSize.LowPart, szStrStrA, ARRAYSIZE(szStrStrA));
  298. SHAnsiToTChar(szStrStrA, pszSizeStr, cchSize);
  299. }
  300. return S_OK;
  301. }
  302. // From shlwapi.
  303. void Int64ToStr(LONGLONG n, LPTSTR lpBuffer, DWORD cchSize)
  304. {
  305. TCHAR szTemp[40];
  306. LONGLONG iChr = 0;
  307. ASSERT(cchSize > ARRAYSIZE(szTemp));
  308. do
  309. {
  310. szTemp[iChr++] = TEXT('0') + (TCHAR)(n % 10);
  311. n = n / 10;
  312. }
  313. while (n != 0);
  314. do
  315. {
  316. iChr--;
  317. *lpBuffer++ = szTemp[iChr];
  318. }
  319. while (iChr != 0);
  320. *lpBuffer++ = TEXT('\0');
  321. }
  322. /*****************************************************************************\
  323. FUNCTION: _InitSize
  324. DESCRIPTION:
  325. \*****************************************************************************/
  326. HRESULT CFtpDialogTemplate::_InitSize(HWND hwnd, HWND hwndLabel, CFtpFolder * pff, CFtpPidlList * pflHfpl)
  327. {
  328. HRESULT hr;
  329. TCHAR szSizeStr[MAX_FILE_SIZE];
  330. CSizeHolder sizeHolder;
  331. szSizeStr[0] = 0;
  332. // GetCount maybe 0 if we are doing the background folder.
  333. if (0 < pflHfpl->GetCount())
  334. {
  335. pflHfpl->Enum(CFtpDialogTemplate::_InitSizeTally, (LPVOID) &sizeHolder);
  336. if (SUCCEEDED(sizeHolder.GetError()))
  337. {
  338. // Are there files sizes to display?
  339. if (!sizeHolder.IsAllFolders())
  340. {
  341. TCHAR szBytesStr[MAX_FILE_SIZE];
  342. TCHAR szBytesStrFormatted[MAX_FILE_SIZE];
  343. TCHAR szCondencedSizeStr[MAX_FILE_SIZE];
  344. ULARGE_INTEGER uliTotal;
  345. uliTotal.QuadPart = sizeHolder.GetTotalSize();
  346. NUMBERFMT numfmt = {0, 0, 3, TEXT(""), TEXT(","), 0};
  347. EVAL(SUCCEEDED(GetFileSizeFromULargeInteger(uliTotal, szCondencedSizeStr, ARRAYSIZE(szCondencedSizeStr))));
  348. Int64ToStr(uliTotal.QuadPart, szBytesStr, ARRAYSIZE(szBytesStr));
  349. GetNumberFormat(LOCALE_USER_DEFAULT, 0, szBytesStr, &numfmt, szBytesStrFormatted, ARRAYSIZE(szBytesStrFormatted));
  350. wnsprintf(szSizeStr, ARRAYSIZE(szSizeStr), TEXT("%s (%s bytes)"), szCondencedSizeStr, szBytesStrFormatted);
  351. }
  352. }
  353. }
  354. if (szSizeStr[0])
  355. {
  356. hr = _ReinsertDlgText(hwnd, szSizeStr, SZ_WSPRINTFSTR_S);
  357. }
  358. else
  359. {
  360. // If more than one item was selected...
  361. // remove both the label and the value.
  362. ShowEnableWindow(hwnd, FALSE);
  363. if (hwndLabel)
  364. ShowEnableWindow(hwndLabel, FALSE);
  365. hr = S_OK;
  366. }
  367. return hr;
  368. }
  369. // WINVER 0x0500 definition
  370. #ifndef WS_EX_LAYOUTRTL
  371. #define WS_EX_LAYOUTRTL 0x00400000L // Right to left mirroring
  372. #endif
  373. /*****************************************************************************\
  374. FUNCTION: _InitTime
  375. DESCRIPTION:
  376. \*****************************************************************************/
  377. HRESULT CFtpDialogTemplate::_InitTime(HWND hwnd, HWND hwndLabel, CFtpFolder * pff, CFtpPidlList * pflHfpl)
  378. {
  379. TCHAR szDateTime[MAX_PATH];
  380. HRESULT hr = E_FAIL;
  381. DWORD dwFlags = FDTF_SHORTTIME | FDTF_LONGDATE;
  382. LCID locale = GetUserDefaultLCID();
  383. if ((PRIMARYLANGID(LANGIDFROMLCID(locale)) == LANG_ARABIC)
  384. || (PRIMARYLANGID(LANGIDFROMLCID(locale)) == LANG_HEBREW))
  385. {
  386. DWORD dwExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
  387. if ((BOOLIFY(dwExStyle & WS_EX_RTLREADING)) != (BOOLIFY(dwExStyle & WS_EX_LAYOUTRTL)))
  388. dwFlags |= FDTF_RTLDATE;
  389. else
  390. dwFlags |= FDTF_LTRDATE;
  391. }
  392. switch (pflHfpl->GetCount())
  393. {
  394. // one item was selected so get the time for that item.
  395. case 1:
  396. if (!FtpID_IsServerItemID(pflHfpl->GetPidl(0)))
  397. {
  398. FILETIME ftLastModified = FtpPidl_GetFileTime(pflHfpl->GetPidl(0));
  399. Misc_StringFromFileTime(szDateTime, ARRAYSIZE(szDateTime), &ftLastModified, dwFlags);
  400. hr = S_OK;
  401. }
  402. break;
  403. // zero items selected means get the properties for the background folder
  404. case 0:
  405. {
  406. LPCITEMIDLIST pidl = FtpID_GetLastIDReferense(pff->GetPrivatePidlReference());
  407. // The user will get 'N/A' for the 'Server' folder. (i.e. ftp://ohserv/)
  408. if (EVAL(pidl) && !FtpID_IsServerItemID(pidl))
  409. {
  410. FILETIME ftLastModified = FtpPidl_GetFileTime(pidl);
  411. Misc_StringFromFileTime(szDateTime, ARRAYSIZE(szDateTime), &ftLastModified, dwFlags);
  412. hr = S_OK;
  413. }
  414. // Don't free pidl because we have a pointer to someone else's copy.
  415. }
  416. }
  417. if (SUCCEEDED(hr))
  418. {
  419. hr = _ReinsertDlgText(hwnd, szDateTime, SZ_WSPRINTFSTR_S);
  420. }
  421. else
  422. {
  423. // If more than one item was selected...
  424. // remove both the label and the value.
  425. ShowEnableWindow(hwnd, FALSE);
  426. if (hwndLabel)
  427. ShowEnableWindow(hwndLabel, FALSE);
  428. hr = S_OK;
  429. }
  430. return hr;
  431. }
  432. /*****************************************************************************\
  433. FUNCTION: _InitCount
  434. DESCRIPTION:
  435. \*****************************************************************************/
  436. HRESULT CFtpDialogTemplate::_InitCount(HWND hwnd, CFtpFolder * pff, CFtpPidlList * pflHfpl)
  437. {
  438. return _ReinsertDlgText(hwnd, IntToPtr(pflHfpl->GetCount()), SZ_WSPRINTFSTR_U);
  439. }
  440. /*****************************************************************************\
  441. FUNCTION: InitDialog
  442. DESCRIPTION:
  443. \*****************************************************************************/
  444. HRESULT CFtpDialogTemplate::InitDialog(HWND hDlg, BOOL fEditable, UINT id, CFtpFolder * pff, CFtpPidlList * pPidlList)
  445. {
  446. HRESULT hr = S_OK;
  447. int nDlgTemlItem;
  448. m_fEditable = fEditable;
  449. for (nDlgTemlItem = 0; nDlgTemlItem < DLGTEML_MAX; nDlgTemlItem++)
  450. {
  451. HRESULT hrTemp = S_OK;
  452. HWND hwnd = GetDlgItem(hDlg, id + nDlgTemlItem);
  453. HWND hwndLabel = GetDlgItem(hDlg, id + nDlgTemlItem + DLGTEML_LABEL);
  454. if (hwnd)
  455. {
  456. switch (nDlgTemlItem)
  457. {
  458. case DLGTEML_FILENAME: hrTemp = _InitName(hwnd, pff, pPidlList); break;
  459. case DLGTEML_FILENAMEEDITABLE: hrTemp = _InitNameEditable(hwnd, pff, pPidlList); break;
  460. case DLGTEML_FILEICON: hrTemp = _InitIcon(hwnd, pff, pPidlList); break;
  461. case DLGTEML_FILESIZE: hrTemp = _InitSize(hwnd, hwndLabel, pff, pPidlList); break;
  462. case DLGTEML_FILETIME: hrTemp = _InitTime(hwnd, hwndLabel, pff, pPidlList); break;
  463. case DLGTEML_FILETYPE: hrTemp = _InitType(hwnd, pff, pPidlList); break;
  464. case DLGTEML_LOCATION: hrTemp = _InitLocation(hwnd, pff, pPidlList); break;
  465. case DLGTEML_COUNT: hrTemp = _InitCount(hwnd, pff, pPidlList); break;
  466. default:
  467. ASSERT(0); // What are you thinking?
  468. break;
  469. }
  470. }
  471. if (EVAL(SUCCEEDED(hr)))
  472. hr = hrTemp; // Propogate out the worst error.
  473. }
  474. return hr;
  475. }
  476. /*****************************************************************************\
  477. FUNCTION: OnClose
  478. DESCRIPTION:
  479. \*****************************************************************************/
  480. BOOL CFtpDialogTemplate::OnClose(HWND hdlg, HWND hwndBrowser, CFtpFolder * pff, CFtpPidlList * pPidlList)
  481. {
  482. BOOL fCanClose = TRUE;
  483. // If the IDC_FILENAME_EDITABLE field is showing, then the user may have done
  484. // a rename. Check if that happened and if so, do it now.
  485. if (IsWindowVisible(GetDlgItem(hdlg, IDC_FILENAME_EDITABLE)))
  486. {
  487. WCHAR wzOldName[MAX_PATH];
  488. WCHAR wzNewName[MAX_PATH];
  489. GetNameFromPidlList(pff, pPidlList, wzOldName, ARRAYSIZE(wzOldName));
  490. EVAL(GetWindowTextW(GetDlgItem(hdlg, IDC_FILENAME_EDITABLE), wzNewName, ARRAYSIZE(wzNewName)));
  491. // Was the name changed?
  492. if (StrCmpW(wzOldName, wzNewName))
  493. {
  494. // Yes, so change it.
  495. IShellFolder * psfParent = NULL;
  496. CFtpFolder * pffParent = pff;
  497. LPCITEMIDLIST pidlItem;
  498. if (0 == pPidlList->GetCount())
  499. {
  500. // We use pidlTarget mainly because we want to assure that the
  501. // ChangeNotifies are fired with pidlTarget.
  502. LPITEMIDLIST pidlParent = pff->GetPublicTargetPidlClone();
  503. if (pidlParent)
  504. {
  505. ILRemoveLastID(pidlParent);
  506. pidlItem = FtpID_GetLastIDReferense(pff->GetPrivatePidlReference());
  507. IEBindToObject(pidlParent, &psfParent);
  508. ILFree(pidlParent);
  509. }
  510. }
  511. else
  512. {
  513. pidlItem = FtpID_GetLastIDReferense(pPidlList->GetPidl(0));
  514. EVAL(SUCCEEDED(pff->QueryInterface(IID_IShellFolder, (void **) &psfParent)));
  515. }
  516. if (psfParent)
  517. {
  518. if (EVAL(pidlItem))
  519. fCanClose = ((S_OK == psfParent->SetNameOf(hwndBrowser, pidlItem, wzNewName, NULL, NULL)) ? TRUE : FALSE);
  520. psfParent->Release();
  521. }
  522. }
  523. }
  524. return fCanClose;
  525. }
  526. /*****************************************************************************\
  527. FUNCTION: OnDestroy
  528. DESCRIPTION:
  529. \*****************************************************************************/
  530. BOOL CFtpDialogTemplate::OnDestroy(HWND hDlg, BOOL fEditable, UINT id, CFtpFolder* pff, CFtpPidlList* pPidlList)
  531. {
  532. HRESULT hr = S_OK;
  533. int nDlgTemlItem;
  534. for (nDlgTemlItem = 0; nDlgTemlItem < DLGTEML_MAX; nDlgTemlItem++)
  535. {
  536. HRESULT hrTemp = S_OK;
  537. HWND hwnd = GetDlgItem(hDlg, id + nDlgTemlItem);
  538. HWND hwndLabel = GetDlgItem(hDlg, id + nDlgTemlItem + DLGTEML_LABEL);
  539. if (hwnd)
  540. {
  541. switch (nDlgTemlItem)
  542. {
  543. case DLGTEML_FILEICON:
  544. hrTemp = _ReplaceIcon(hwnd, NULL);
  545. break;
  546. case DLGTEML_FILENAME:
  547. case DLGTEML_FILENAMEEDITABLE:
  548. case DLGTEML_FILESIZE:
  549. case DLGTEML_FILETIME:
  550. case DLGTEML_FILETYPE:
  551. case DLGTEML_LOCATION:
  552. case DLGTEML_COUNT:
  553. break;
  554. default:
  555. ASSERT(0); // What are you thinking?
  556. break;
  557. }
  558. }
  559. if (SUCCEEDED(hr))
  560. {
  561. // Propogate out the worst error.
  562. hr = hrTemp;
  563. }
  564. }
  565. return hr;
  566. }
  567. BOOL CFtpDialogTemplate::HasNameChanged(HWND hdlg, CFtpFolder * pff, CFtpPidlList * pPidlList)
  568. {
  569. BOOL fNameChanged = FALSE;
  570. // If the IDC_FILENAME_EDITABLE field is showing, then the user may have done
  571. // a rename. Check if that happened and if so, do it now.
  572. if (IsWindowVisible(GetDlgItem(hdlg, IDC_FILENAME_EDITABLE)))
  573. {
  574. TCHAR szOldName[MAX_PATH];
  575. TCHAR szNewName[MAX_PATH];
  576. GetNameFromPidlList(pff, pPidlList, szOldName, ARRAYSIZE(szOldName));
  577. EVAL(GetWindowText(GetDlgItem(hdlg, IDC_FILENAME_EDITABLE), szNewName, ARRAYSIZE(szNewName)));
  578. // Was the name changed?
  579. if (StrCmp(szOldName, szNewName))
  580. {
  581. // Yes, so change it.
  582. fNameChanged = TRUE;
  583. }
  584. }
  585. return fNameChanged;
  586. }
  587. HRESULT CFtpDialogTemplate::InitDialogWithFindData(HWND hDlg, UINT id, CFtpFolder * pff, const FTP_FIND_DATA * pwfd, LPCWIRESTR pwWirePath, LPCWSTR pwzDisplayPath)
  588. {
  589. FTP_FIND_DATA wfd = *pwfd;
  590. LPITEMIDLIST pidl;
  591. HRESULT hr;
  592. ASSERT(pwfd);
  593. StrCpyNA(wfd.cFileName, pwWirePath, ARRAYSIZE(wfd.cFileName));
  594. hr = FtpItemID_CreateReal(&wfd, pwzDisplayPath, &pidl);
  595. if (SUCCEEDED(hr))
  596. {
  597. CFtpPidlList * pfpl = NULL;
  598. hr = CFtpPidlList_Create(1, (LPCITEMIDLIST *) &pidl, &pfpl);
  599. if (SUCCEEDED(hr))
  600. {
  601. hr = InitDialog(hDlg, FALSE, id, pff, pfpl);
  602. pfpl->Release();
  603. }
  604. ILFree(pidl);
  605. }
  606. return hr;
  607. }