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.

245 lines
9.6 KiB

  1. /*****************************************************************************\
  2. ftpdlg.cpp - Confirm Dialog box stuff
  3. \*****************************************************************************/
  4. #include "priv.h"
  5. #include "ftpdhlp.h"
  6. /*****************************************************************************\
  7. PFDI
  8. The fields in the fdi are as follows:
  9. pfdd -> dialog descriptor
  10. pszLocal -> ASCIIZ: Name of local file being replaced.
  11. pwfdRemote -> Description of remote file.
  12. cobj = number of objects affected
  13. The dialog template should have the following controls:
  14. IDC_REPLACE_YES - The "Yes" button
  15. IDC_REPLACE_YESTOALL - The "Yes to all" button
  16. IDC_REPLACE_NO - The "No" button
  17. IDC_REPLACE_CANCEL - The "Cancel" button
  18. Of these buttons, IDC_REPLACE_YES and IDC_REPLACE_NO are mandatory.
  19. If the "Yes to all" and "Cancel" buttons are available, the caller
  20. should set the fCanMulti flag in the fdd, in which case the extra
  21. buttons will be removed if cobj = 1.
  22. IDC_FILENAME - A string with a '%hs' replacement field.
  23. The '%hs' will be replaced by the name passed in the pwfdRemote.
  24. IDC_REPLACE_OLDFILE - A string which will be rewritten
  25. IDC_REPLACE_OLDICON - An icon placeholder
  26. The string will be replaced by a description taken from pwfdRemote.
  27. The icon will be an icon for the file.
  28. IDC_REPLACE_NEWFILE - A string which will be rewritten
  29. IDC_REPLACE_NEWICON - An icon placeholder
  30. The string will be replaced by a description taken from pszLocal.
  31. The icon will be an icon for the file.
  32. \*****************************************************************************/
  33. class CFtpConfirmDialog
  34. {
  35. public:
  36. CFtpConfirmDialog(CFtpFolder * pff);
  37. ~CFtpConfirmDialog();
  38. UINT Display(HWND hwnd, LPCVOID pvLocal, LPCWIRESTR pwLocalWirePath, LPCWSTR pwzLocalDisplayPath, UINT fdiiLocal,
  39. LPCVOID pvRemote, LPCWIRESTR pwRemoteWirePath, LPCWSTR pwzRemoteDisplayPath, UINT fdiiRemote, int cobj, BOOL fAllowCancel, DWORD dwItem);
  40. static INT_PTR CALLBACK _FtpConfirmDialogProc(HWND hdlg, UINT wm, WPARAM wParam, LPARAM lParam);
  41. static BOOL _OnCommand(HWND hdlg, WPARAM wParam, LPARAM lParam);
  42. private:
  43. LPCVOID m_pvLocal; // The local file in question
  44. UINT m_fdiiLocal;
  45. LPCVOID m_pvRemote; // The remote file in question
  46. UINT m_fdiiRemote;
  47. int m_cobj; // Number of objects affected
  48. BOOL m_fAllowCancel : 1;
  49. CFtpFolder * m_pff;
  50. DWORD m_dwItem;
  51. LPWIRESTR m_pwLocalWirePath;
  52. LPWSTR m_pwzLocalDisplayPath;
  53. LPWIRESTR m_pwRemoteWirePath;
  54. LPWSTR m_pwzRemoteDisplayPath;
  55. BOOL _OnInitDialog(HWND hDlg);
  56. };
  57. CFtpConfirmDialog::CFtpConfirmDialog(CFtpFolder * pff)
  58. {
  59. m_pff = pff;
  60. m_pwLocalWirePath = NULL;
  61. m_pwzLocalDisplayPath = NULL;
  62. m_pwRemoteWirePath = NULL;
  63. m_pwzRemoteDisplayPath = NULL;
  64. }
  65. CFtpConfirmDialog::~CFtpConfirmDialog()
  66. {
  67. Str_SetPtrA(&m_pwLocalWirePath, NULL);
  68. Str_SetPtrW(&m_pwzLocalDisplayPath, NULL);
  69. Str_SetPtrA(&m_pwRemoteWirePath, NULL);
  70. Str_SetPtrW(&m_pwzRemoteDisplayPath, NULL);
  71. }
  72. /*****************************************************************************\
  73. _FtpDlg_OnInitDialog
  74. \*****************************************************************************/
  75. BOOL CFtpConfirmDialog::_OnInitDialog(HWND hDlg)
  76. {
  77. CFtpDialogTemplate ftpDialogTemplate;
  78. if (m_fdiiLocal == FDII_WFDA)
  79. EVAL(SUCCEEDED(ftpDialogTemplate.InitDialogWithFindData(hDlg, IDC_ITEM, m_pff, (const FTP_FIND_DATA *) m_pvLocal, m_pwLocalWirePath, m_pwzLocalDisplayPath)));
  80. else
  81. EVAL(SUCCEEDED(ftpDialogTemplate.InitDialog(hDlg, FALSE, IDC_ITEM , m_pff, (CFtpPidlList *) m_pvLocal)));
  82. if (m_fdiiLocal == FDII_WFDA)
  83. EVAL(SUCCEEDED(ftpDialogTemplate.InitDialogWithFindData(hDlg, IDC_ITEM2, m_pff, (const FTP_FIND_DATA *) m_pvRemote, m_pwRemoteWirePath, m_pwzRemoteDisplayPath)));
  84. else
  85. EVAL(SUCCEEDED(ftpDialogTemplate.InitDialog(hDlg, FALSE, IDC_ITEM2 , m_pff, (CFtpPidlList *) m_pvRemote)));
  86. return 1;
  87. }
  88. /*****************************************************************************\
  89. _FtpDlg_OnCommand
  90. \*****************************************************************************/
  91. BOOL CFtpConfirmDialog::_OnCommand(HWND hdlg, WPARAM wParam, LPARAM lParam)
  92. {
  93. UINT idc = GET_WM_COMMAND_ID(wParam, lParam);
  94. switch (idc)
  95. {
  96. case IDC_REPLACE_YES:
  97. case IDC_REPLACE_YESTOALL:
  98. EndDialog(hdlg, idc);
  99. return 1;
  100. case IDC_REPLACE_NOTOALL:
  101. EndDialog(hdlg, IDC_REPLACE_NOTOALL);
  102. return 1;
  103. case IDC_REPLACE_CANCEL:
  104. EndDialog(hdlg, IDC_REPLACE_CANCEL);
  105. return 1;
  106. // _UNOBVIOUS_: Shift+No means "No to all", just like the shell.
  107. case IDC_REPLACE_NO:
  108. EndDialog(hdlg, GetKeyState(VK_SHIFT) < 0 ? IDC_REPLACE_NOTOALL : IDC_REPLACE_NO);
  109. return 1;
  110. }
  111. return 0; // Not handled
  112. }
  113. /*****************************************************************************\
  114. _FtpDlg_DlgProc
  115. \*****************************************************************************/
  116. INT_PTR CFtpConfirmDialog::_FtpConfirmDialogProc(HWND hdlg, UINT wm, WPARAM wParam, LPARAM lParam)
  117. {
  118. switch (wm)
  119. {
  120. case WM_INITDIALOG:
  121. return ((CFtpConfirmDialog *)lParam)->_OnInitDialog(hdlg);
  122. case WM_COMMAND:
  123. return CFtpConfirmDialog::_OnCommand(hdlg, wParam, lParam);
  124. }
  125. return 0;
  126. }
  127. UINT CFtpConfirmDialog::Display(HWND hwnd, LPCVOID pvLocal, LPCWIRESTR pwLocalWirePath, LPCWSTR pwzLocalDisplayPath, UINT fdiiLocal,
  128. LPCVOID pvRemote, LPCWIRESTR pwRemoteWirePath, LPCWSTR pwzRemoteDisplayPath, UINT fdiiRemote, int cobj, BOOL fAllowCancel, DWORD dwItem)
  129. {
  130. m_pvLocal = pvLocal;
  131. m_fdiiLocal = fdiiLocal;
  132. m_pvRemote = pvRemote;
  133. m_fdiiRemote = fdiiRemote;
  134. m_cobj = cobj;
  135. m_fAllowCancel = fAllowCancel;
  136. m_dwItem = dwItem;
  137. Str_SetPtrA(&m_pwLocalWirePath, pwLocalWirePath);
  138. Str_SetPtrW(&m_pwzLocalDisplayPath, pwzLocalDisplayPath);
  139. Str_SetPtrA(&m_pwRemoteWirePath, pwRemoteWirePath);
  140. Str_SetPtrW(&m_pwzRemoteDisplayPath, pwzRemoteDisplayPath);
  141. return (UINT) DialogBoxParam(g_hinst, MAKEINTRESOURCE(dwItem), hwnd, CFtpConfirmDialog::_FtpConfirmDialogProc, (LPARAM)this);
  142. }
  143. /*****************************************************************************\
  144. FtpDlg_ConfirmReplace
  145. \*****************************************************************************/
  146. UINT FtpConfirmReplaceDialog(HWND hwnd, LPFTP_FIND_DATA pwfdLocal, LPWIN32_FIND_DATA pwfdRemote,
  147. int cobj, CFtpFolder * pff)
  148. {
  149. CFtpConfirmDialog confirmDialog(pff);
  150. BOOL fAllowCancel = ((cobj > 1) ? 1 : 0);
  151. WCHAR wzLocalDisplayPath[MAX_PATH];
  152. WIRECHAR wRemoteWirePath[MAX_PATH];
  153. CWireEncoding * pWireEncoding = pff->GetCWireEncoding();
  154. EVAL(SUCCEEDED(pWireEncoding->WireBytesToUnicode(NULL, pwfdLocal->cFileName, (pff->IsUTF8Supported() ? WIREENC_USE_UTF8 : WIREENC_NONE), wzLocalDisplayPath, ARRAYSIZE(wzLocalDisplayPath))));
  155. EVAL(SUCCEEDED(pWireEncoding->UnicodeToWireBytes(NULL, pwfdRemote->cFileName, (pff->IsUTF8Supported() ? WIREENC_USE_UTF8 : WIREENC_NONE), wRemoteWirePath, ARRAYSIZE(wRemoteWirePath))));
  156. return confirmDialog.Display(hwnd, (LPCVOID) pwfdLocal, pwfdLocal->cFileName, wzLocalDisplayPath, FDII_WFDA,
  157. pwfdRemote, wRemoteWirePath, pwfdRemote->cFileName, FDII_WFDA, cobj, fAllowCancel, IDD_REPLACE);
  158. }
  159. /*****************************************************************************\
  160. FtpDlg_ConfirmReplace
  161. \*****************************************************************************/
  162. UINT FtpConfirmReplaceDialog(HWND hwnd, LPWIN32_FIND_DATA pwfdLocal, LPFTP_FIND_DATA pwfdRemote,
  163. int cobj, CFtpFolder * pff)
  164. {
  165. CFtpConfirmDialog confirmDialog(pff);
  166. BOOL fAllowCancel = ((cobj > 1) ? 1 : 0);
  167. WIRECHAR wzLocalWirePath[MAX_PATH];
  168. WCHAR wRemoteDisplayPath[MAX_PATH];
  169. CWireEncoding * pWireEncoding = pff->GetCWireEncoding();
  170. EVAL(SUCCEEDED(pWireEncoding->UnicodeToWireBytes(NULL, pwfdLocal->cFileName, (pff->IsUTF8Supported() ? WIREENC_USE_UTF8 : WIREENC_NONE), wzLocalWirePath, ARRAYSIZE(wzLocalWirePath))));
  171. EVAL(SUCCEEDED(pWireEncoding->WireBytesToUnicode(NULL, pwfdRemote->cFileName, (pff->IsUTF8Supported() ? WIREENC_USE_UTF8 : WIREENC_NONE), wRemoteDisplayPath, ARRAYSIZE(wRemoteDisplayPath))));
  172. return confirmDialog.Display(hwnd, (LPCVOID) pwfdLocal, wzLocalWirePath, pwfdLocal->cFileName, FDII_WFDA,
  173. pwfdRemote, pwfdRemote->cFileName, wRemoteDisplayPath, FDII_WFDA, cobj, fAllowCancel, IDD_REPLACE);
  174. }
  175. /*****************************************************************************\
  176. FtpDlg_ConfirmDelete
  177. \*****************************************************************************/
  178. UINT FtpConfirmDeleteDialog(HWND hwnd, CFtpPidlList * pflHfpl, CFtpFolder * pff)
  179. {
  180. CFtpConfirmDialog confirmDialog(pff);
  181. UINT id;
  182. if (pflHfpl->GetCount() > 1)
  183. id = IDD_DELETEMULTI;
  184. else
  185. {
  186. if (FtpPidl_IsDirectory(pflHfpl->GetPidl(0), TRUE))
  187. id = IDD_DELETEFOLDER;
  188. else
  189. id = IDD_DELETEFILE;
  190. }
  191. return confirmDialog.Display(hwnd, (LPCVOID) pflHfpl, NULL, NULL, FDII_HFPL, 0, 0, NULL, NULL, NULL, FALSE, id);
  192. }