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.

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