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.

415 lines
12 KiB

  1. #include "precomp.h"
  2. #include "utils.h"
  3. #define MAX_FILES 700
  4. extern void UpdateProgress(int);
  5. DWORD FolderSize(LPCTSTR pszFolderName)
  6. {
  7. DWORD dwSize = 0;
  8. WIN32_FIND_DATA fileData;
  9. HANDLE hFindFile;
  10. TCHAR szFile[MAX_PATH];
  11. if (pszFolderName == NULL || ISNULL(pszFolderName))
  12. return dwSize;
  13. PathCombine(szFile, pszFolderName, TEXT("*"));
  14. if ((hFindFile = FindFirstFile(szFile, &fileData)) != INVALID_HANDLE_VALUE)
  15. {
  16. do
  17. {
  18. if (!(fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
  19. dwSize += fileData.nFileSizeLow;
  20. } while (FindNextFile(hFindFile, &fileData));
  21. FindClose(hFindFile);
  22. }
  23. return dwSize;
  24. }
  25. HRESULT MySHFileOperation(SHFILEOPSTRUCT &shfStruc, LPDWORD lpdwSizeArray,
  26. DWORD dwTotalSize, DWORD dwTicks)
  27. {
  28. LPCTSTR pFrom;
  29. LPTSTR pTo;
  30. TCHAR szTo[MAX_PATH];
  31. DWORD dwBytesCopied = 0;
  32. DWORD dwTickInterval = 0;
  33. DWORD dwIndex = 0;
  34. int i;
  35. // create the directory(we assume all files are being copied to the same dir here)
  36. PathCreatePath(shfStruc.pTo);
  37. if (dwTicks)
  38. {
  39. dwIndex = 1;
  40. // round up on the update interval
  41. dwTickInterval = dwTotalSize / dwTicks +
  42. ((dwTotalSize % dwTicks == 0) ? 0 : 1);
  43. }
  44. StrCpy(szTo, shfStruc.pTo);
  45. PathAddBackslash(szTo);
  46. pTo = szTo + StrLen(szTo);
  47. for (pFrom = shfStruc.pFrom, i = 0; *pFrom; pFrom += StrLen(pFrom) + 1, i++)
  48. {
  49. StrCpy(pTo, PathFindFileName(pFrom));
  50. // set the file_normal attribute so we can overwrite existing files
  51. SetFileAttributes(szTo, FILE_ATTRIBUTE_NORMAL);
  52. if (!CopyFile(pFrom, szTo, FALSE))
  53. return E_FAIL;
  54. if (dwTicks)
  55. {
  56. dwBytesCopied += lpdwSizeArray[i];
  57. if (dwBytesCopied > (dwTickInterval * dwIndex))
  58. {
  59. dwIndex++;
  60. UpdateProgress(1);
  61. }
  62. }
  63. }
  64. if (dwTicks)
  65. UpdateProgress(1);
  66. return S_OK;
  67. }
  68. HRESULT CopyFilesSrcToDest(LPCTSTR pszSrcPath, LPCTSTR pszSrcFilter, LPCTSTR pszDestPath,
  69. DWORD dwTicks /* = 0 */)
  70. {
  71. HANDLE hFind;
  72. WIN32_FIND_DATA wfdFind;
  73. TCHAR szSrcFile[MAX_PATH];
  74. DWORD dwTotalSize = 0;
  75. LPTSTR lpszFrom;
  76. LPDWORD lpdwSize = NULL;
  77. int nFrom = 0;
  78. int nFiles = 0;
  79. HRESULT res = S_OK;
  80. SHFILEOPSTRUCT shfStruc;
  81. if(ISNULL(pszSrcPath))
  82. return S_OK;
  83. lpszFrom = (LPTSTR) LocalAlloc(LPTR, MAX_BUFFER_SIZE*sizeof(TCHAR));
  84. if (!lpszFrom)
  85. return E_FAIL;
  86. if (dwTicks)
  87. {
  88. lpdwSize = (LPDWORD) LocalAlloc(LPTR, MAX_FILES * sizeof(DWORD));
  89. if (!lpdwSize)
  90. {
  91. LocalFree(lpszFrom);
  92. return E_FAIL;
  93. }
  94. }
  95. ZeroMemory(&shfStruc, sizeof(shfStruc));
  96. shfStruc.hwnd = g_hWizard;
  97. shfStruc.wFunc = FO_COPY;
  98. // remove the trailing backslash character
  99. TCHAR szBuffer[MAX_PATH];
  100. StrCpy(szBuffer, pszSrcPath);
  101. PathRemoveBackslash(szBuffer);
  102. pszSrcPath = szBuffer;
  103. PathCombine(szSrcFile, pszSrcPath, pszSrcFilter);
  104. hFind = FindFirstFile(szSrcFile, &wfdFind);
  105. if (hFind != INVALID_HANDLE_VALUE)
  106. {
  107. do
  108. {
  109. if (!(wfdFind.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  110. && StrCmp(wfdFind.cFileName, TEXT("."))
  111. && StrCmp(wfdFind.cFileName, TEXT("..")))
  112. {
  113. PathCombine(szSrcFile, pszSrcPath, wfdFind.cFileName);
  114. if (((nFrom + lstrlen(szSrcFile) + 1) < MAX_BUFFER_SIZE) &&
  115. ((!dwTicks) || (nFiles < MAX_FILES)))
  116. {
  117. StrCpy(lpszFrom + nFrom, szSrcFile);
  118. nFrom += lstrlen(szSrcFile) + 1;
  119. if (dwTicks)
  120. {
  121. dwTotalSize += (lpdwSize[nFiles] = wfdFind.nFileSizeLow);
  122. nFiles++;
  123. }
  124. }
  125. else
  126. {
  127. shfStruc.pFrom = lpszFrom;
  128. shfStruc.pTo = pszDestPath;
  129. shfStruc.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR;
  130. res |= MySHFileOperation(shfStruc, lpdwSize, dwTotalSize, dwTicks);
  131. ZeroMemory(lpszFrom, MAX_BUFFER_SIZE);
  132. nFrom = 0;
  133. dwTicks = 0;
  134. StrCpy(lpszFrom + nFrom, szSrcFile);
  135. nFrom += lstrlen(szSrcFile) + 1;
  136. }
  137. }
  138. }while (FindNextFile( hFind, &wfdFind));
  139. FindClose(hFind);
  140. if(ISNONNULL(lpszFrom))
  141. {
  142. shfStruc.pFrom = lpszFrom;
  143. shfStruc.pTo = pszDestPath;
  144. shfStruc.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR;
  145. res |= MySHFileOperation(shfStruc, lpdwSize, dwTotalSize, dwTicks);
  146. }
  147. }
  148. LocalFree(lpszFrom);
  149. if (dwTicks) LocalFree(lpdwSize);
  150. return res;
  151. }
  152. void TooBig(HWND hWnd, WORD id)
  153. {
  154. TCHAR szTitle[MAX_PATH], szMsg[MAX_PATH];
  155. LoadString(g_rvInfo.hInst, IDS_TITLE, szTitle, countof(szTitle));
  156. LoadString(g_rvInfo.hInst, id, szMsg, countof(szMsg));
  157. MessageBox(hWnd, szMsg, szTitle, MB_OK | MB_SETFOREGROUND);
  158. SetWindowLongPtr(hWnd, DWLP_MSGRESULT, -1);
  159. }
  160. void SetWindowTextSmart(HWND hwnd, LPCTSTR pcszText)
  161. {
  162. TCHAR szCurrentText[INTERNET_MAX_URL_LENGTH];
  163. if (GetWindowText(hwnd, szCurrentText, countof(szCurrentText)))
  164. {
  165. if (StrCmpI(pcszText, szCurrentText) == 0)
  166. return;
  167. }
  168. SetWindowText(hwnd, pcszText);
  169. }
  170. DWORD ShellExecAndWait(SHELLEXECUTEINFO shInfo)
  171. {
  172. MSG msg;
  173. DWORD dwRet;
  174. if (!ShellExecuteEx(&shInfo))
  175. return (DWORD)E_FAIL;
  176. while (MsgWaitForMultipleObjects(1, &shInfo.hProcess, FALSE, INFINITE, QS_ALLINPUT) != WAIT_OBJECT_0)
  177. {
  178. while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  179. {
  180. TranslateMessage(&msg);
  181. DispatchMessage(&msg);
  182. }
  183. }
  184. GetExitCodeProcess(shInfo.hProcess, &dwRet);
  185. CloseHandle(shInfo.hProcess);
  186. return dwRet;
  187. }
  188. // equivalent of c run time strtok
  189. LPTSTR StrTok(LPTSTR pcszToken, LPCTSTR pcszDelimit)
  190. {
  191. LPTSTR pszRet, pszCur;
  192. int i;
  193. pszCur = pcszToken;
  194. while (*pszCur)
  195. {
  196. i = 0;
  197. while(pcszDelimit[i])
  198. {
  199. if (*pszCur == pcszDelimit[i])
  200. break;
  201. i++;
  202. }
  203. if (!pcszDelimit[i])
  204. break;
  205. pszCur++;
  206. }
  207. pszRet = ((*pszCur) ? pszCur : NULL);
  208. if (pszRet != NULL)
  209. {
  210. while (*pszCur)
  211. {
  212. i = 0;
  213. while(pcszDelimit[i])
  214. {
  215. if (*pszCur == pcszDelimit[i])
  216. break;
  217. i++;
  218. }
  219. if (pcszDelimit[i])
  220. break;
  221. pszCur++;
  222. }
  223. if(*pszCur)
  224. *pszCur = TEXT('\0');
  225. }
  226. return pszRet;
  227. }
  228. //**********************************************************************
  229. // Automation HookIn : This function copies displayed item names from the
  230. // LV into the Registry key "HKEY_LOCAL_MACHINE\Soft\MS\AutoTemp".
  231. // Taken from setupwbv.cpp
  232. //
  233. //**********************************************************************
  234. void LVGetItems(HWND hwndLV)
  235. {
  236. LV_ITEM lvi;
  237. DWORD dwNumItems, dwIndex;
  238. HKEY hKey;
  239. DWORD dwDisp;
  240. TCHAR szValueName[5];
  241. TCHAR szDisplayName[MAX_PATH];
  242. BOOL bOK = TRUE;
  243. LONG lRet;
  244. dwNumItems = ListView_GetItemCount(hwndLV);
  245. // Create the new key. NOTE: Its volatile.
  246. lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\AutoTemp"), 0,
  247. NULL, REG_OPTION_VOLATILE, KEY_READ|KEY_WRITE,
  248. NULL, &hKey, &dwDisp);
  249. bOK = (lRet == ERROR_SUCCESS);
  250. if (bOK)
  251. {
  252. // If the key already existed, delete it so that old
  253. // data does not carry-over by mistake.
  254. if ( dwDisp == REG_OPENED_EXISTING_KEY )
  255. {
  256. RegCloseKey(hKey);
  257. RegDeleteKey(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\AutoTemp"));
  258. lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\AutoTemp"), 0,
  259. NULL, REG_OPTION_VOLATILE, KEY_READ|KEY_WRITE,
  260. NULL, &hKey, &dwDisp);
  261. bOK = (lRet == ERROR_SUCCESS);
  262. }
  263. if (bOK)
  264. {
  265. for (dwIndex=0; dwIndex < dwNumItems && bOK; dwIndex++)
  266. {
  267. lvi.mask = LVIF_TEXT;
  268. lvi.iItem = (int) dwIndex;
  269. lvi.iSubItem = 0;
  270. ZeroMemory(szDisplayName, sizeof(szDisplayName));
  271. lvi.pszText = szDisplayName;
  272. lvi.cchTextMax = countof(szDisplayName);
  273. ListView_GetItem(hwndLV, &lvi);
  274. // Write the Display name to the Registry.
  275. wnsprintf(szValueName, countof(szValueName), TEXT("%03d"), dwIndex);
  276. lRet = RegSetValueEx(hKey, szValueName, 0, REG_SZ,
  277. (const BYTE *)szDisplayName, (lstrlen(szDisplayName)+1)*sizeof(TCHAR));
  278. bOK = (lRet == ERROR_SUCCESS);
  279. }
  280. // Write the number of values for the automation people to readout.
  281. RegSetValueEx(hKey, TEXT("Number"), 0, REG_DWORD,
  282. (const BYTE *)&dwIndex, sizeof(dwIndex));
  283. // Close the Reg key.
  284. RegCloseKey(hKey);
  285. }
  286. }
  287. }
  288. LPTSTR GetOutputPlatformDir()
  289. {
  290. static TCHAR s_szOutPlatform[MAX_PATH];
  291. if (ISNULL(s_szOutPlatform))
  292. {
  293. switch (g_dwPlatformId)
  294. {
  295. case PLATFORM_WIN32:
  296. default:
  297. StrCpy(s_szOutPlatform, TEXT("WIN32\\"));
  298. break;
  299. }
  300. }
  301. ASSERT(ISNONNULL(s_szOutPlatform));
  302. return s_szOutPlatform;
  303. }
  304. int GetRole(BOOL g_fBranded, BOOL g_fIntranet)
  305. {
  306. int nRetVal = -1;
  307. if (g_fBranded == FALSE && g_fIntranet == FALSE)
  308. nRetVal = ROLE_ICP;
  309. else if (g_fBranded == TRUE && g_fIntranet == FALSE)
  310. nRetVal = ROLE_ISP;
  311. else if (g_fBranded == TRUE && g_fIntranet == TRUE)
  312. nRetVal = ROLE_CORP;
  313. else
  314. ASSERT(FALSE);
  315. return nRetVal;
  316. }
  317. // Loop thru Favorites/Links under the section FavoritesEx/URL and check if it has any associated icon file.
  318. BOOL IsIconsInFavs(LPCTSTR pcszSection, LPCTSTR pcszCustIns)
  319. {
  320. TCHAR szTemp[MAX_PATH];
  321. TCHAR szNameKey[MAX_PATH];
  322. TCHAR szIconKey[MAX_PATH];
  323. TCHAR szNameFormat[MAX_PATH];
  324. TCHAR szIconFormat[MAX_PATH];
  325. if (StrCmpI(pcszSection, IS_FAVORITESEX) == 0)
  326. {
  327. StrCpy(szNameFormat, IK_TITLE_FMT);
  328. StrCpy(szIconFormat, IK_ICON_FMT);
  329. }
  330. else // IS_URL
  331. {
  332. StrCpy(szNameFormat, IK_QUICKLINK_NAME);
  333. StrCpy(szIconFormat, IK_QUICKLINK_ICON);
  334. }
  335. for(int nCount = 1; ; nCount++)
  336. {
  337. wnsprintf(szNameKey, countof(szNameKey), szNameFormat, nCount);
  338. wnsprintf(szIconKey, countof(szIconKey), szIconFormat, nCount);
  339. if (GetPrivateProfileString(pcszSection, szNameKey, TEXT(""), szTemp, countof(szTemp), pcszCustIns) != 0)
  340. {
  341. if (GetPrivateProfileString(pcszSection, szIconKey, TEXT(""), szTemp, countof(szTemp), pcszCustIns) != 0)
  342. return TRUE;
  343. }
  344. else
  345. break;
  346. }
  347. return FALSE;
  348. }