Source code of Windows XP (NT5)
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.

350 lines
13 KiB

  1. /*----------------------------------------------------------------------------
  2. / Title;
  3. / dll.cpp
  4. / Copyright (C) Microsoft Corporation, 1999.
  5. /
  6. / Authors;
  7. / Jude Kavalam (judej)
  8. /
  9. / Notes;
  10. / Entry point for File Conflict Resolution Dialog
  11. /----------------------------------------------------------------------------*/
  12. #include "precomp.h"
  13. #define CX_BIGICON 48
  14. #define CY_BIGICON 48
  15. extern HINSTANCE g_hmodThisDll; // Handle to this DLL itself.
  16. #define ARRAYLEN(a) (sizeof(a) / sizeof((a)[0]))
  17. // Special flag to fix up the callback data when thunking
  18. #define RFC_THUNK_DATA 0x80000000
  19. /////////////////////////////////////////////////////////////////////////////
  20. // Global UNICODE<>ANSI translation helpers
  21. LPWSTR WINAPI AtlA2WHelper(LPWSTR lpw, LPCSTR lpa, int nChars)
  22. {
  23. Assert(lpa != NULL);
  24. Assert(lpw != NULL);
  25. // verify that no illegal character present
  26. // since lpw was allocated based on the size of lpa
  27. // don't worry about the number of chars
  28. lpw[0] = L'\0';
  29. MultiByteToWideChar(CP_ACP, 0, lpa, -1, lpw, nChars);
  30. return lpw;
  31. }
  32. LPSTR WINAPI AtlW2AHelper(LPSTR lpa, LPCWSTR lpw, int nChars)
  33. {
  34. Assert(lpw != NULL);
  35. Assert(lpa != NULL);
  36. // verify that no illegal character present
  37. // since lpa was allocated based on the size of lpw
  38. // don't worry about the number of chars
  39. lpa[0] = '\0';
  40. WideCharToMultiByte(CP_ACP, 0, lpw, -1, lpa, nChars, NULL, NULL);
  41. return lpa;
  42. }
  43. INT_PTR CALLBACK RFCDlgProc(HWND, UINT, WPARAM, LPARAM);
  44. // The caller needs to send an hwnd and fill in the RFCDLGPARAM. Only the icons
  45. // are optional
  46. int WINAPI SyncMgrResolveConflict(HWND hWndParent, RFCDLGPARAM *pdlgParam)
  47. {
  48. int nRet = 0;
  49. HICON hIKeepBoth = NULL, hIKeepLocal = NULL, hIKeepNetwork = NULL;
  50. if (!hWndParent || !pdlgParam)
  51. return -1;
  52. if (IsBadReadPtr(pdlgParam, sizeof(RFCDLGPARAM)))
  53. return -1;
  54. // If we don't have any of the params fail..
  55. if (!pdlgParam->pszFilename || !pdlgParam->pszLocation || !pdlgParam->pszNewName)
  56. return -1;
  57. // If we do not have any of the icons, load the defaults
  58. if (!pdlgParam->hIKeepBoth)
  59. pdlgParam->hIKeepBoth = hIKeepBoth =
  60. (HICON)LoadImage(g_hmodThisDll, MAKEINTRESOURCE(IDI_KEEPBOTH),
  61. IMAGE_ICON, CX_BIGICON, CY_BIGICON,
  62. LR_LOADMAP3DCOLORS);
  63. if (!pdlgParam->hIKeepLocal)
  64. pdlgParam->hIKeepLocal = hIKeepLocal =
  65. (HICON)LoadImage(g_hmodThisDll, MAKEINTRESOURCE(IDI_KEEPLOCAL),
  66. IMAGE_ICON, CX_BIGICON, CY_BIGICON,
  67. LR_LOADMAP3DCOLORS);
  68. if (!pdlgParam->hIKeepNetwork)
  69. pdlgParam->hIKeepNetwork = hIKeepNetwork =
  70. (HICON)LoadImage(g_hmodThisDll, MAKEINTRESOURCE(IDI_KEEPNETWORK),
  71. IMAGE_ICON, CX_BIGICON, CY_BIGICON,
  72. LR_LOADMAP3DCOLORS);
  73. nRet = (int)DialogBoxParam(g_hmodThisDll, MAKEINTRESOURCE(IDD_RESFILECONFLICTS),
  74. hWndParent, RFCDlgProc, (LPARAM)pdlgParam);
  75. // Destroy the icons that were created
  76. if (hIKeepBoth)
  77. DestroyIcon(hIKeepBoth);
  78. if (hIKeepLocal)
  79. DestroyIcon(hIKeepLocal);
  80. if (hIKeepNetwork)
  81. DestroyIcon(hIKeepNetwork);
  82. return nRet;
  83. }
  84. INT_PTR CALLBACK RFCDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  85. {
  86. RFCDLGPARAM * pParam = (RFCDLGPARAM*)GetWindowLongPtr(hDlg, DWLP_USER);
  87. switch (uMsg)
  88. {
  89. case WM_INITDIALOG:
  90. {
  91. SHFILEINFO sfi = {0};
  92. TCHAR szStr[INTERNET_MAX_URL_LENGTH + MAX_PATH];
  93. TCHAR szFmt[MAX_PATH];
  94. HICON hiExclaim;
  95. LPTSTR pszNetUser=NULL, pszNetDate=NULL, pszLocalUser=NULL, pszLocalDate=NULL;
  96. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)lParam);
  97. pParam = (RFCDLGPARAM*)lParam;
  98. if (!pParam)
  99. {
  100. EndDialog(hDlg, -1);
  101. return TRUE;
  102. }
  103. hiExclaim = LoadIcon(NULL, IDI_EXCLAMATION);
  104. SendDlgItemMessage(hDlg, IDI_EXCLAIMICON, STM_SETICON, (WPARAM)hiExclaim, 0L);
  105. // Get the icon from Shell
  106. wsprintf(szStr, TEXT("%ws%ws"), pParam->pszLocation, pParam->pszFilename);
  107. if (SHGetFileInfo(szStr, 0, &sfi, sizeof(sfi), SHGFI_ICON | SHGFI_LARGEICON))
  108. SendDlgItemMessage(hDlg, IDI_DOCICON, STM_SETICON, (WPARAM)sfi.hIcon, 0L);
  109. // Set initial selection
  110. CheckRadioButton(hDlg, IDC_KEEPBOTH, IDC_KEEPNETWORK, IDC_KEEPBOTH);
  111. if (pParam->hIKeepBoth)
  112. SendDlgItemMessage(hDlg, IDB_BIGICON, STM_SETIMAGE, IMAGE_ICON, (LPARAM)pParam->hIKeepBoth);
  113. // Format and set the strings
  114. LoadString(g_hmodThisDll, IDS_NAMEANDLOCATION, szFmt, ARRAYLEN(szFmt));
  115. wsprintf(szStr, szFmt, pParam->pszFilename, pParam->pszLocation);
  116. SetDlgItemText(hDlg,IDC_FILEANDLOCATION,szStr);
  117. if (pParam->pszNewName)
  118. {
  119. SetDlgItemText(hDlg,IDC_NEWFILENAME,pParam->pszNewName);
  120. }
  121. if (pParam->pszNetworkModifiedBy && pParam->pszNetworkModifiedOn &&
  122. lstrlen(pParam->pszNetworkModifiedBy) && lstrlen(pParam->pszNetworkModifiedOn))
  123. {
  124. // we have by and on then use them both
  125. LoadString(g_hmodThisDll, IDS_NETWORKMODIFIED, szFmt, ARRAYLEN(szFmt));
  126. wsprintf(szStr, szFmt, pParam->pszNetworkModifiedBy, pParam->pszNetworkModifiedOn);
  127. }
  128. else if ((pParam->pszNetworkModifiedBy && lstrlen(pParam->pszNetworkModifiedBy)) &&
  129. (!pParam->pszNetworkModifiedOn || !lstrlen(pParam->pszNetworkModifiedOn)))
  130. {
  131. // We have the name but no date
  132. TCHAR szTemp[MAX_PATH];
  133. LoadString(g_hmodThisDll, IDS_UNKNOWNDATE, szTemp, ARRAYLEN(szTemp));
  134. LoadString(g_hmodThisDll, IDS_NETWORKMODIFIED, szFmt, ARRAYLEN(szFmt));
  135. wsprintf(szStr, szFmt, pParam->pszNetworkModifiedBy, szTemp);
  136. }
  137. else if ((!pParam->pszNetworkModifiedBy || !lstrlen(pParam->pszNetworkModifiedBy)) &&
  138. (pParam->pszNetworkModifiedOn && lstrlen(pParam->pszNetworkModifiedOn)))
  139. {
  140. // We have the date but no name
  141. LoadString(g_hmodThisDll, IDS_NETWORKMODIFIED_DATEONLY, szFmt, ARRAYLEN(szFmt));
  142. wsprintf(szStr, szFmt, pParam->pszNetworkModifiedOn);
  143. }
  144. else
  145. // we do not have on or by, use the unknown
  146. LoadString(g_hmodThisDll, IDS_NONETINFO, szStr, ARRAYLEN(szStr));
  147. SetDlgItemText(hDlg,IDC_NETWORKMODIFIED,szStr);
  148. if (pParam->pszLocalModifiedBy && pParam->pszLocalModifiedOn &&
  149. lstrlen(pParam->pszLocalModifiedBy) && lstrlen(pParam->pszLocalModifiedOn))
  150. {
  151. // we have by and on then use them both
  152. LoadString(g_hmodThisDll, IDS_LOCALMODIFIED, szFmt, ARRAYLEN(szFmt));
  153. wsprintf(szStr, szFmt, pParam->pszLocalModifiedBy, pParam->pszLocalModifiedOn);
  154. }
  155. else if ((pParam->pszLocalModifiedBy && lstrlen(pParam->pszLocalModifiedBy)) &&
  156. (!pParam->pszLocalModifiedOn || !lstrlen(pParam->pszLocalModifiedOn)))
  157. {
  158. // We have the name but no date
  159. TCHAR szTemp[MAX_PATH];
  160. LoadString(g_hmodThisDll, IDS_UNKNOWNDATE, szTemp, ARRAYLEN(szTemp));
  161. LoadString(g_hmodThisDll, IDS_LOCALMODIFIED, szFmt, ARRAYLEN(szFmt));
  162. wsprintf(szStr, szFmt, pParam->pszLocalModifiedBy, szTemp);
  163. }
  164. else if ((!pParam->pszLocalModifiedBy || !lstrlen(pParam->pszLocalModifiedBy)) &&
  165. (pParam->pszLocalModifiedOn && lstrlen(pParam->pszLocalModifiedOn)))
  166. {
  167. // We have the date but no name
  168. LoadString(g_hmodThisDll, IDS_LOCALMODIFIED_DATEONLY, szFmt, ARRAYLEN(szFmt));
  169. wsprintf(szStr, szFmt, pParam->pszLocalModifiedOn);
  170. }
  171. else
  172. // we do not have on or by, use the unknown
  173. LoadString(g_hmodThisDll, IDS_NOLOCALINFO, szStr, ARRAYLEN(szStr));
  174. SetDlgItemText(hDlg,IDC_LOCALMODIFIED,szStr);
  175. // If there is no call back function, don't show the view buttons.
  176. if (!pParam->pfnCallBack)
  177. {
  178. HWND hWndButton = GetDlgItem(hDlg, IDC_VIEWLOCAL);
  179. ShowWindow(hWndButton, SW_HIDE);
  180. EnableWindow(hWndButton, FALSE);
  181. hWndButton = GetDlgItem(hDlg, IDC_VIEWNETWORK);
  182. ShowWindow(hWndButton, SW_HIDE);
  183. EnableWindow(hWndButton, FALSE);
  184. }
  185. // Hide the "Apply to all" checkbox if caller doesn't want it.
  186. if (!(RFCF_APPLY_ALL & pParam->dwFlags))
  187. {
  188. HWND hWndButton = GetDlgItem(hDlg, IDC_APPLY_ALL);
  189. ShowWindow(hWndButton, SW_HIDE);
  190. EnableWindow(hWndButton, FALSE);
  191. }
  192. break;
  193. }
  194. case WM_COMMAND:
  195. {
  196. int id = LOWORD(wParam);
  197. switch (id)
  198. {
  199. case IDCANCEL:
  200. EndDialog(hDlg, RFC_CANCEL);
  201. break;
  202. case IDOK:
  203. {
  204. int nRet = RFC_KEEPBOTH;
  205. if (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_KEEPBOTH))
  206. nRet = RFC_KEEPBOTH;
  207. else if (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_KEEPLOCAL))
  208. nRet = RFC_KEEPLOCAL;
  209. else if (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_KEEPNETWORK))
  210. nRet = RFC_KEEPNETWORK;
  211. if (pParam && (RFCF_APPLY_ALL & pParam->dwFlags) &&
  212. BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_APPLY_ALL))
  213. {
  214. nRet |= RFC_APPLY_TO_ALL;
  215. }
  216. EndDialog(hDlg, nRet);
  217. break;
  218. }
  219. case IDC_KEEPBOTH:
  220. case IDC_KEEPLOCAL:
  221. case IDC_KEEPNETWORK:
  222. {
  223. HICON hITemp;
  224. if (!pParam)
  225. break;
  226. if (IDC_KEEPBOTH == id)
  227. hITemp = pParam->hIKeepBoth;
  228. else if (IDC_KEEPLOCAL == id)
  229. hITemp = pParam->hIKeepLocal;
  230. else
  231. hITemp = pParam->hIKeepNetwork;
  232. SendDlgItemMessage(hDlg, IDB_BIGICON, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hITemp);
  233. break;
  234. }
  235. case IDC_VIEWLOCAL:
  236. if (pParam)
  237. pParam->pfnCallBack(hDlg, RFCCM_VIEWLOCAL, 0, (pParam->dwFlags & RFC_THUNK_DATA) ? pParam->lCallerData : (LPARAM)pParam);
  238. break;
  239. case IDC_VIEWNETWORK:
  240. if (pParam)
  241. pParam->pfnCallBack(hDlg, RFCCM_VIEWNETWORK, 0, (pParam->dwFlags & RFC_THUNK_DATA) ? pParam->lCallerData : (LPARAM)pParam);
  242. break;
  243. default:
  244. return FALSE;
  245. }
  246. break;
  247. }
  248. default:
  249. return FALSE;
  250. }
  251. return TRUE;
  252. }
  253. #ifdef _UNICODE
  254. int WINAPI SyncMgrResolveConflictA(HWND hWndParent, RFCDLGPARAMA *pdlgParam)
  255. {
  256. USES_CONVERSION;
  257. RFCDLGPARAMW dlgPW={0};
  258. dlgPW.dwFlags = pdlgParam->dwFlags | RFC_THUNK_DATA;
  259. dlgPW.hIKeepBoth = pdlgParam->hIKeepBoth;
  260. dlgPW.hIKeepLocal = pdlgParam->hIKeepLocal;
  261. dlgPW.hIKeepNetwork = pdlgParam->hIKeepNetwork;
  262. dlgPW.pfnCallBack = pdlgParam->pfnCallBack;
  263. dlgPW.lCallerData = (LPARAM)pdlgParam;
  264. dlgPW.pszFilename = A2CW(pdlgParam->pszFilename);
  265. dlgPW.pszLocation = A2CW(pdlgParam->pszLocation);
  266. dlgPW.pszNewName = A2CW(pdlgParam->pszNewName);
  267. dlgPW.pszNetworkModifiedBy = A2CW(pdlgParam->pszNetworkModifiedBy);
  268. dlgPW.pszNetworkModifiedOn = A2CW(pdlgParam->pszNetworkModifiedOn);
  269. dlgPW.pszLocalModifiedBy = A2CW(pdlgParam->pszLocalModifiedBy);
  270. dlgPW.pszLocalModifiedOn = A2CW(pdlgParam->pszLocalModifiedOn);
  271. return SyncMgrResolveConflictW(hWndParent, &dlgPW);
  272. }
  273. #else
  274. int WINAPI SyncMgrResolveConflictW(HWND hWndParent, RFCDLGPARAMW *pdlgParam)
  275. {
  276. USES_CONVERSION;
  277. RFCDLGPARAMA dlgPA={0};
  278. dlgPA.dwFlags = pdlgParam->dwFlags | RFC_THUNK_DATA;
  279. dlgPA.hIKeepBoth = pdlgParam->hIKeepBoth;
  280. dlgPA.hIKeepLocal = pdlgParam->hIKeepLocal;
  281. dlgPA.hIKeepNetwork = pdlgParam->hIKeepNetwork;
  282. dlgPA.pfnCallBack = pdlgParam->pfnCallBack;
  283. dlgPA.lCallerData = (LPARAM)pdlgParam;
  284. dlgPA.pszFilename = W2CA(pdlgParam->pszFilename);
  285. dlgPA.pszLocation = W2CA(pdlgParam->pszLocation);
  286. dlgPA.pszNewName = W2CA(pdlgParam->pszNewName);
  287. dlgPA.pszNetworkModifiedBy = W2CA(pdlgParam->pszNetworkModifiedBy);
  288. dlgPA.pszNetworkModifiedOn = W2CA(pdlgParam->pszNetworkModifiedOn);
  289. dlgPA.pszLocalModifiedBy = W2CA(pdlgParam->pszLocalModifiedBy);
  290. dlgPA.pszLocalModifiedOn = W2CA(pdlgParam->pszLocalModifiedOn);
  291. return SyncMgrResolveConflictA(hWndParent, &dlgPA);
  292. }
  293. #endif