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.

1178 lines
39 KiB

  1. //
  2. // UTILS.CPP
  3. //
  4. #include "precomp.h"
  5. static BOOL isAnimBitmapFileValidHelper(HWND hDlg, UINT nID, LPTSTR pszBuffer, PUINT pcch, UINT nIDTooBig,
  6. UINT nIDTooSmall, long lBmpMinWidth, long lBmpMaxWidth);
  7. static BOOL isBitmapFileValidHelper(HWND hDlg, UINT nID, LPTSTR pszBuffer, PUINT pcch,
  8. int cx, int cy, UINT nIDTooBig, UINT nIDTooSmall, DWORD dwFlags);
  9. static BOOL browseForFileHelper(HWND hDlg, LPTSTR pszFileName, DWORD cchSize, DWORD dwFilterMasks,
  10. LPCTSTR pcszTitle);
  11. static BOOL browseForFolderHelper(HWND hDlg, LPTSTR pszFileName, LPCTSTR pcszDesc);
  12. static void exportRegTree2InfHelper(HKEY hk, LPCTSTR pszHive, LPCTSTR pszKey, HANDLE hInf, BOOL fUseLdids);
  13. static void exportRegValue2InfHelper(HKEY hkSubKey, LPCTSTR pcszValue, LPCTSTR pcszRootKey, LPCTSTR pcszSubKey, HANDLE hInf, BOOL fUseLdids);
  14. static void exportRegKey2InfHelper(HKEY hkSubKey, LPCTSTR pcszRootKey, LPCTSTR pcszSubKey, HANDLE hInf, BOOL fUseLdids);
  15. static void signFileHelper(LPCTSTR pcszFilename, LPCTSTR pcszDir, LPCTSTR pcszIns, LPTSTR pszUnsignedFiles, LPCTSTR pcszCustInf, BOOL fTest);
  16. BOOL WINAPI CheckField(HWND hDlg, int nIDDlgItem, DWORD dwFlags, LPARAM lParam /*= 0*/)
  17. {
  18. TCHAR szField[INTERNET_MAX_URL_LENGTH];
  19. HWND hCtrl;
  20. UINT nID, nStartPos;
  21. hCtrl = GetDlgItem(hDlg, nIDDlgItem);
  22. if (hCtrl == NULL)
  23. return FALSE;
  24. szField[0] = TEXT('\0');
  25. GetWindowText(hCtrl, szField, countof(szField));
  26. StrRemoveWhitespace(szField);
  27. nID = nStartPos = 0;
  28. if (HasFlag(dwFlags, FC_NONNULL)) {
  29. if (szField[0] == TEXT('\0')) {
  30. nID = IDS_CF_EMPTY_FIELD;
  31. nStartPos = 0;
  32. }
  33. }
  34. else
  35. if (szField[0] == TEXT('\0'))
  36. return TRUE;
  37. if (nID == 0 && HasFlag(dwFlags, FC_URL))
  38. if (!PathIsURL(szField)) {
  39. nID = IDS_CF_INVALID_URL;
  40. nStartPos = 0;
  41. }
  42. if (nID == 0 && HasFlag(dwFlags, FC_NOSPACE)) {
  43. LPCTSTR pszChar;
  44. for (pszChar = szField; *pszChar; pszChar = CharNext(pszChar))
  45. if (IsSpace(*pszChar)) {
  46. nID = IDS_CF_INVALID_SPACE;
  47. nStartPos = 0;
  48. }
  49. }
  50. if (nID == 0 && HasFlag(dwFlags, FC_NOCOLON)) {
  51. if (StrChr(szField, TEXT(':'))) {
  52. nID = IDS_CF_INVALID_COLON;
  53. nStartPos = 0;
  54. }
  55. }
  56. if (nID == 0 && HasFlag(dwFlags, FC_NUMBER)) {
  57. int nLen = StrLen(szField);
  58. for (int nIndex = 0; nIndex < nLen; nIndex++) {
  59. if (!(szField[nIndex] >= TEXT('0') && szField[nIndex] <= TEXT('9'))) {
  60. nID = IDS_CF_INVALID_NUMBER;
  61. nStartPos = nIndex;
  62. break;
  63. }
  64. }
  65. }
  66. if (!(nID == 0 && HasFlag(dwFlags, FC_URL)) &&
  67. (nID == 0 || HasFlag(dwFlags, FC_URL)) && HasFlag(dwFlags, FC_PATH)) {
  68. LPCTSTR pszError;
  69. DWORD dwResult = PIVP_VALID;
  70. ASSERT(HasFlag(dwFlags, FC_URL) ? nID != 0 : TRUE);
  71. nID = nStartPos = 0;
  72. SetFlag(&dwFlags, FC_PATH, FALSE);
  73. if (HasFlag(dwFlags, FC_FILE))
  74. {
  75. if (HasFlag(dwFlags, FC_EXISTS))
  76. SetFlag((LPDWORD)&lParam, PIVP_FILE_ONLY);
  77. }
  78. else if (HasFlag(dwFlags, FC_DIR))
  79. {
  80. if (HasFlag(dwFlags, FC_EXISTS))
  81. SetFlag((LPDWORD)&lParam, PIVP_FOLDER_ONLY);
  82. }
  83. dwResult = PathIsValidPathEx(szField, (DWORD) lParam, &pszError);
  84. // check for extended character in the field
  85. if (dwResult == PIVP_VALID) {
  86. if (HasFlag(dwFlags, FC_FILE))
  87. {
  88. SetFlag((LPDWORD)&lParam, PIVP_FILE_ONLY, FALSE);
  89. if (HasFlag(dwFlags, FC_NOEXCHAR))
  90. SetFlag((LPDWORD)&lParam, (PIVP_FILENAME_ONLY | PIVP_EXCHAR_INVALID));
  91. else
  92. SetFlag((LPDWORD)&lParam, (PIVP_FILENAME_ONLY | PIVP_0x5C_INVALID));
  93. dwResult = PathIsValidPathEx(PathFindFileName(szField), (DWORD) lParam, &pszError);
  94. }
  95. else if (HasFlag(dwFlags, FC_DIR))
  96. {
  97. if (HasFlag(dwFlags, FC_NOEXCHAR))
  98. dwResult = PathIsValidPathEx(szField, PIVP_EXCHAR_INVALID, &pszError);
  99. }
  100. }
  101. if (dwResult != PIVP_VALID) {
  102. static struct {
  103. DWORD dwError;
  104. UINT nID;
  105. } rgMap[] = {
  106. { PIVP_CHAR, IDS_CF_CHAR },
  107. { PIVP_WILD, IDS_CF_WILD },
  108. { PIVP_RELATIVE, IDS_CF_RELATIVE },
  109. { PIVP_FIRST_CHAR, IDS_CF_FIRST_CHAR },
  110. { PIVP_PRESLASH, IDS_CF_PRESLASH },
  111. { PIVP_SPACE, IDS_CF_SPACE },
  112. { PIVP_FWDSLASH, IDS_CF_FWDSLASH },
  113. { PIVP_COLON, IDS_CF_COLON },
  114. { PIVP_DRIVE, IDS_CF_DRIVE },
  115. { PIVP_SEPARATOR, IDS_CF_SEPARATOR },
  116. { PIVP_DBCS, IDS_CF_DBCS },
  117. { PIVP_0x5C, IDS_CF_0x5C },
  118. { PIVP_DOESNT_EXIST, IDS_CF_DOESNT_EXIST },
  119. { PIVP_NOT_FILE, IDS_CF_NOT_FILE },
  120. { PIVP_NOT_FOLDER, IDS_CF_NOT_FOLDER },
  121. { PIVP_EXCHAR, IDS_CF_EXCHAR },
  122. { 0, IDS_CF_UNKNOWN }
  123. };
  124. ASSERT(pszError >= szField);
  125. for (UINT i = 0; i < countof(rgMap)-1; i++)
  126. if (dwResult == rgMap[i].dwError)
  127. break;
  128. ASSERT(i < countof(rgMap));
  129. nID = rgMap[i].nID;
  130. nStartPos = (pszError != NULL ? (int)(pszError - szField) : 0);
  131. }
  132. }
  133. if (nID != 0) {
  134. ErrorMessageBox(hDlg, nID);
  135. Edit_SetSel(hCtrl, nStartPos, -1);
  136. SetFocus(hCtrl);
  137. return FALSE;
  138. }
  139. return TRUE;
  140. }
  141. BOOL WINAPI IsAnimBitmapFileValidA(HWND hDlg, UINT nID, LPSTR pszBuffer, PUINT pcch, UINT nIDTooBig,
  142. UINT nIDTooSmall, long lBmpMinWidth, long lBmpMaxWidth)
  143. {
  144. LPTSTR pszBuf;
  145. BOOL fRet;
  146. USES_CONVERSION;
  147. if ((pcch != NULL) && (*pcch != 0))
  148. pszBuf = (LPTSTR)LocalAlloc(LPTR, (*pcch) * sizeof(TCHAR));
  149. else
  150. pszBuf = (LPTSTR)LocalAlloc(LPTR, MAX_PATH * sizeof(TCHAR));
  151. if (pszBuf == NULL)
  152. fRet = FALSE;
  153. else
  154. {
  155. A2Tbux(pszBuffer, pszBuf);
  156. fRet = isAnimBitmapFileValidHelper(hDlg, nID, pszBuf, pcch, nIDTooBig, nIDTooSmall, lBmpMinWidth, lBmpMaxWidth);
  157. T2Abux(pszBuf, pszBuffer);
  158. LocalFree(pszBuf);
  159. }
  160. return fRet;
  161. }
  162. BOOL WINAPI IsAnimBitmapFileValidW(HWND hDlg, UINT nID, LPWSTR pwszBuffer, PUINT pcch, UINT nIDTooBig,
  163. UINT nIDTooSmall, long lBmpMinWidth, long lBmpMaxWidth)
  164. {
  165. LPTSTR pszBuf;
  166. BOOL fRet;
  167. USES_CONVERSION;
  168. if ((pcch != NULL) && (*pcch != 0))
  169. pszBuf = (LPTSTR)LocalAlloc(LPTR, (*pcch) * sizeof(TCHAR));
  170. else
  171. pszBuf = (LPTSTR)LocalAlloc(LPTR, MAX_PATH * sizeof(TCHAR));
  172. if (pszBuf == NULL)
  173. fRet = FALSE;
  174. else
  175. {
  176. W2Tbux(pwszBuffer, pszBuf);
  177. fRet = isAnimBitmapFileValidHelper(hDlg, nID, pszBuf, pcch, nIDTooBig, nIDTooSmall, lBmpMinWidth, lBmpMaxWidth);
  178. T2Wbux(pszBuf, pwszBuffer);
  179. LocalFree(pszBuf);
  180. }
  181. return fRet;
  182. }
  183. BOOL WINAPI IsBitmapFileValidA(HWND hDlg, UINT nID, LPSTR pszBuffer, PUINT pcch, int cx, int cy,
  184. UINT nIDTooBig, UINT nIDTooSmall, DWORD dwFlags /*= 0 */)
  185. {
  186. LPTSTR pszBuf;
  187. BOOL fRet;
  188. USES_CONVERSION;
  189. if ((pcch != NULL) && (*pcch != 0))
  190. pszBuf = (LPTSTR)LocalAlloc(LPTR, (*pcch) * sizeof(TCHAR));
  191. else
  192. pszBuf = (LPTSTR)LocalAlloc(LPTR, MAX_PATH * sizeof(TCHAR));
  193. if (pszBuf == NULL)
  194. fRet = FALSE;
  195. else
  196. {
  197. A2Tbux(pszBuffer, pszBuf);
  198. fRet = isBitmapFileValidHelper(hDlg, nID, pszBuf, pcch, cx, cy, nIDTooBig, nIDTooSmall, dwFlags);
  199. T2Abux(pszBuf, pszBuffer);
  200. LocalFree(pszBuf);
  201. }
  202. return fRet;
  203. }
  204. BOOL WINAPI IsBitmapFileValidW(HWND hDlg, UINT nID, LPWSTR pwszBuffer, PUINT pcch, int cx, int cy,
  205. UINT nIDTooBig, UINT nIDTooSmall, DWORD dwFlags /*= 0 */)
  206. {
  207. LPTSTR pszBuf;
  208. BOOL fRet;
  209. USES_CONVERSION;
  210. if ((pcch != NULL) && (*pcch != 0))
  211. pszBuf = (LPTSTR)LocalAlloc(LPTR, (*pcch) * sizeof(TCHAR));
  212. else
  213. pszBuf = (LPTSTR)LocalAlloc(LPTR, MAX_PATH * sizeof(TCHAR));
  214. if (pszBuf == NULL)
  215. fRet = FALSE;
  216. else
  217. {
  218. W2Tbux(pwszBuffer, pszBuf);
  219. fRet = isBitmapFileValidHelper(hDlg, nID, pszBuf, pcch, cx, cy, nIDTooBig, nIDTooSmall, dwFlags);
  220. T2Wbux(pszBuf, pwszBuffer);
  221. LocalFree(pszBuf);
  222. }
  223. return fRet;
  224. }
  225. void WINAPI SetLBWidth(HWND hLb)
  226. {
  227. HDC hDc = GetDC( hLb );
  228. LONG wMax = 0;
  229. SIZE sText;
  230. POINT point;
  231. int i;
  232. int nItems = (int) SendMessage( hLb, LB_GETCOUNT, 0, 0 );
  233. for (i = 0; i < nItems ; i++ )
  234. {
  235. TCHAR szText[MAX_PATH];
  236. SendMessage(hLb, LB_GETTEXT, i, (LPARAM) szText);
  237. GetTextExtentPoint32( hDc, szText, StrLen(szText), &sText );
  238. if (sText.cx > wMax) wMax = sText.cx;
  239. }
  240. point.y=0;
  241. point.x=wMax;
  242. LPtoDP(hDc,&point,1); //TODO: this is still not exactly what we want--why does it have extra space???!!
  243. SendMessage( hLb, LB_SETHORIZONTALEXTENT, point.x, 0 );
  244. ReleaseDC(hLb, hDc);
  245. }
  246. BOOL WINAPI BrowseForFileA(HWND hDlg, LPSTR pszFileName, DWORD cchSize, DWORD dwFilterMasks, LPCSTR pcszTitle /* = NULL */)
  247. {
  248. LPTSTR pszBuf = (LPTSTR)LocalAlloc(LPTR, cchSize * sizeof(TCHAR));
  249. BOOL fRet;
  250. USES_CONVERSION;
  251. if (pszBuf == NULL)
  252. fRet = FALSE;
  253. else
  254. {
  255. A2Tbux(pszFileName, pszBuf);
  256. fRet = browseForFileHelper(hDlg, pszBuf, cchSize, dwFilterMasks,
  257. (pcszTitle == NULL) ? NULL : A2CT(pcszTitle));
  258. T2Abux(pszBuf, pszFileName);
  259. LocalFree(pszBuf);
  260. }
  261. return fRet;
  262. }
  263. BOOL WINAPI BrowseForFileW(HWND hDlg, LPWSTR pwszFileName, DWORD cchSize, DWORD dwFilterMasks, LPCWSTR pcwszTitle /*= NULL */)
  264. {
  265. LPTSTR pszBuf = (LPTSTR)LocalAlloc(LPTR, cchSize * sizeof(TCHAR));
  266. BOOL fRet;
  267. USES_CONVERSION;
  268. if (pszBuf == NULL)
  269. fRet = FALSE;
  270. else
  271. {
  272. W2Tbux(pwszFileName, pszBuf);
  273. fRet = browseForFileHelper(hDlg, pszBuf, cchSize, dwFilterMasks,
  274. (pcwszTitle == NULL) ? NULL : W2CT(pcwszTitle));
  275. T2Wbux(pszBuf, pwszFileName);
  276. LocalFree(pszBuf);
  277. }
  278. return fRet;
  279. }
  280. BOOL WINAPI BrowseForFolderA(HWND hDlg, LPSTR pszFileName, LPCSTR pcszDesc /*= NULL */)
  281. {
  282. TCHAR szFileName[MAX_PATH];
  283. BOOL fRet;
  284. USES_CONVERSION;
  285. fRet = browseForFolderHelper(hDlg, szFileName, (pcszDesc == NULL) ? NULL : A2CT(pcszDesc));
  286. T2Abux(szFileName, pszFileName);
  287. return fRet;
  288. }
  289. BOOL WINAPI BrowseForFolderW(HWND hDlg, LPWSTR pwszFileName, LPCWSTR pcwszDesc /* = NULL */)
  290. {
  291. TCHAR szFileName[MAX_PATH];
  292. BOOL fRet;
  293. USES_CONVERSION;
  294. fRet = browseForFolderHelper(hDlg, szFileName, (pcwszDesc == NULL) ? NULL : W2CT(pcwszDesc));
  295. T2Wbux(szFileName, pwszFileName);
  296. return fRet;
  297. }
  298. void WINAPI ExportRegTree2InfA(HKEY hkSubKey, LPCSTR pcszRootKey, LPCSTR pcszSubKey, HANDLE hInf, BOOL fUseLdids /*= FALSE */)
  299. {
  300. USES_CONVERSION;
  301. exportRegTree2InfHelper(hkSubKey, A2CT(pcszRootKey), A2CT(pcszSubKey), hInf, fUseLdids);
  302. }
  303. void WINAPI ExportRegTree2InfW(HKEY hkSubKey, LPCWSTR pcwszRootKey, LPCWSTR pcwszSubKey, HANDLE hInf, BOOL fUseLdids /*= FALSE */)
  304. {
  305. USES_CONVERSION;
  306. exportRegTree2InfHelper(hkSubKey, W2CT(pcwszRootKey), W2CT(pcwszSubKey), hInf, fUseLdids);
  307. }
  308. void WINAPI ExportRegKey2InfA(HKEY hkSubKey, LPCSTR pcszRootKey, LPCSTR pcszSubKey, HANDLE hInf, BOOL fUseLdids /*= FALSE */)
  309. {
  310. USES_CONVERSION;
  311. exportRegKey2InfHelper(hkSubKey, A2CT(pcszRootKey), A2CT(pcszSubKey), hInf, fUseLdids);
  312. }
  313. void WINAPI ExportRegKey2InfW(HKEY hkSubKey, LPCWSTR pcwszRootKey, LPCWSTR pcwszSubKey, HANDLE hInf, BOOL fUseLdids /*= FALSE */)
  314. {
  315. USES_CONVERSION;
  316. exportRegKey2InfHelper(hkSubKey, W2CT(pcwszRootKey), W2CT(pcwszSubKey), hInf, fUseLdids);
  317. }
  318. void WINAPI ExportRegValue2InfA(HKEY hkSubKey, LPCSTR pcszValue, LPCSTR pcszRootKey, LPCSTR pcszSubKey, HANDLE hInf, BOOL fUseLdids /* = FALSE */)
  319. {
  320. USES_CONVERSION;
  321. exportRegValue2InfHelper(hkSubKey, A2CT(pcszValue), A2CT(pcszRootKey), A2CT(pcszSubKey), hInf, fUseLdids);
  322. }
  323. void WINAPI ExportRegValue2InfW(HKEY hkSubKey, LPCWSTR pcwszValue, LPCWSTR pcwszRootKey, LPCWSTR pcwszSubKey, HANDLE hInf, BOOL fUseLdids /* = FALSE */)
  324. {
  325. USES_CONVERSION;
  326. exportRegValue2InfHelper(hkSubKey, W2CT(pcwszValue), W2CT(pcwszRootKey), W2CT(pcwszSubKey), hInf, fUseLdids);
  327. }
  328. void AppendCommaHex(LPTSTR pszBuf, BYTE bData, DWORD dwFlags)
  329. {
  330. CHAR szData[2] = "0";
  331. CHAR c1;
  332. USES_CONVERSION;
  333. if (dwFlags & 0x0001)
  334. StrCat(pszBuf, TEXT(","));
  335. c1 = (CHAR)('0' + ((bData >> 4) & 0x0f));
  336. if (c1 > '9')
  337. c1 += 'A' - '9' - 1;
  338. *szData = c1;
  339. StrCat(pszBuf, A2T(szData));
  340. c1 = (CHAR)('0' + (bData & 0x0f));
  341. if (c1 > '9')
  342. c1 += 'A' - '9' - 1;
  343. *szData = c1;
  344. StrCat(pszBuf, A2T(szData));
  345. }
  346. void WINAPI SignFileA(LPCSTR pcszFilename, LPCSTR pcszDir, LPCSTR pcszIns, LPSTR pszUnsignedFiles /* = NULL */, LPCSTR pcszCustInf /* = NULL */, BOOL fTest /* = FALSE */)
  347. {
  348. LPTSTR pszBuf = NULL;
  349. USES_CONVERSION;
  350. // allocate enough to for one file along with carriage return, new line and null termination
  351. // we'll manually append to the end of unsigned files to save on thunking
  352. if (pszUnsignedFiles != NULL)
  353. pszBuf = (LPTSTR)LocalAlloc(LPTR, (MAX_PATH + 3)*sizeof(TCHAR));
  354. signFileHelper(A2CT(pcszFilename), A2CT(pcszDir), A2CT(pcszIns), pszBuf,
  355. (pcszCustInf == NULL) ? NULL : A2CT(pcszCustInf), fTest);
  356. if (pszBuf != NULL)
  357. {
  358. StrCatA(pszUnsignedFiles, T2A(pszBuf));
  359. LocalFree(pszBuf);
  360. }
  361. }
  362. void WINAPI SignFileW(LPCWSTR pcwszFilename, LPCWSTR pcwszDir, LPCWSTR pcwszIns, LPWSTR pwszUnsignedFiles /* = NULL */, LPCWSTR pcwszCustInf /* = NULL */, BOOL fTest /* = FALSE */)
  363. {
  364. LPTSTR pszBuf = NULL;
  365. USES_CONVERSION;
  366. // allocate enough to for one file along with carriage return, new line and null termination
  367. // we'll manually append to the end of unsigned files to save on thunking
  368. if (pwszUnsignedFiles != NULL)
  369. pszBuf = (LPTSTR)LocalAlloc(LPTR, (MAX_PATH + 3)*sizeof(TCHAR));
  370. signFileHelper(W2CT(pcwszFilename), W2CT(pcwszDir), W2CT(pcwszIns), pszBuf,
  371. (pcwszCustInf == NULL) ? NULL : W2CT(pcwszCustInf), fTest);
  372. if (pszBuf != NULL)
  373. {
  374. StrCatW(pwszUnsignedFiles, T2W(pszBuf));
  375. LocalFree(pszBuf);
  376. }
  377. }
  378. void MoveFileToWorkDir(LPCTSTR pcszFile, LPCTSTR pcszSrcDir, LPCTSTR pcszWorkDir, BOOL fHTM /* = FALSE */)
  379. {
  380. TCHAR szFile[MAX_PATH];
  381. PathCombine(szFile, pcszWorkDir, pcszFile);
  382. if (!PathFileExists(szFile))
  383. {
  384. PathCombine(szFile, pcszSrcDir, pcszFile);
  385. if (PathFileExists(szFile))
  386. {
  387. CopyFileToDir(szFile, pcszWorkDir);
  388. if (fHTM)
  389. CopyHtmlImgs(szFile, pcszWorkDir, NULL, NULL);
  390. }
  391. }
  392. if (fHTM)
  393. DeleteHtmlImgs(szFile, pcszSrcDir, NULL, NULL);
  394. DeleteFileInDir(pcszFile, pcszSrcDir);
  395. }
  396. static BOOL isAnimBitmapFileValidHelper(HWND hDlg, UINT nID, LPTSTR pszBuffer, PUINT pcch, UINT nIDTooBig,
  397. UINT nIDTooSmall, long lBmpMinWidth, long lBmpMaxWidth)
  398. {
  399. TCHAR szFile[MAX_PATH];
  400. HANDLE hBmp;
  401. HWND hCtrl;
  402. BITMAP bmLarge;
  403. UINT nLen,
  404. nIDError = 0;
  405. if (!CheckField(hDlg, nID, FC_FILE | FC_EXISTS))
  406. return FALSE;
  407. nLen = GetDlgItemText(hDlg, nID, szFile, ARRAYSIZE(szFile));
  408. //----- Set "out" and "in-out parameters" -----
  409. if (pszBuffer != NULL)
  410. if (pcch != NULL) {
  411. StrCpyN(pszBuffer, szFile, *pcch);
  412. *pcch = nLen;
  413. }
  414. else
  415. StrCpy(pszBuffer, szFile); // no checking for size
  416. if (nLen == 0)
  417. return TRUE; // consider valid
  418. hCtrl = GetDlgItem(hDlg, nID);
  419. //----- Check that this is a bitmap -----
  420. hBmp = LoadImage(NULL, szFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
  421. if (hBmp == NULL) {
  422. ErrorMessageBox(hDlg, IDS_INVALIDBITMAP);
  423. SendMessage(hCtrl, EM_SETSEL, 0, -1);
  424. SetFocus(hCtrl);
  425. return FALSE;
  426. }
  427. //----- Check the dimensions -----
  428. GetObject(hBmp, sizeof(BITMAP), &bmLarge);
  429. DeleteObject(hBmp);
  430. if (bmLarge.bmWidth > lBmpMaxWidth)
  431. nIDError = nIDTooBig;
  432. else if (bmLarge.bmWidth < lBmpMinWidth)
  433. nIDError = nIDTooSmall;
  434. else if (bmLarge.bmBitsPixel > 8)
  435. nIDError = IDS_TOOMANYCOLORS;
  436. if (nIDError != 0)
  437. {
  438. ErrorMessageBox(hDlg, nIDError);
  439. SendMessage(hCtrl, EM_SETSEL, 0, -1);
  440. SetFocus(hCtrl);
  441. return FALSE;
  442. }
  443. return TRUE;
  444. }
  445. // isBitmapFileValidHelper
  446. // Verifies that file is a valid bitmap. Also optionally checks the dimenstions of this
  447. // bitmap if in-parameters cx and cy are not 0s.
  448. //
  449. // Returns: obvious;
  450. //
  451. // Used by: in dialog procedures mostly in OnOK sort of handlers
  452. //
  453. static BOOL isBitmapFileValidHelper(HWND hDlg, UINT nID, LPTSTR pszBuffer, PUINT pcch,
  454. int cx, int cy, UINT nIDTooBig, UINT nIDTooSmall,
  455. DWORD dwFlags /* = 0 */)
  456. {
  457. TCHAR szFile[MAX_PATH] = TEXT("");
  458. BITMAP bm;
  459. HANDLE hBmp;
  460. HWND hCtrl;
  461. UINT nLen,
  462. nIDError = 0;
  463. if (!CheckField(hDlg, nID, FC_FILE | FC_EXISTS))
  464. return FALSE;
  465. nLen = GetDlgItemText(hDlg, nID, szFile, ARRAYSIZE(szFile));
  466. //----- Set "out" and "in-out parameters" -----
  467. if (pszBuffer != NULL)
  468. if (pcch != NULL) {
  469. StrCpyN(pszBuffer, szFile, *pcch);
  470. *pcch = nLen;
  471. }
  472. else
  473. StrCpy(pszBuffer, szFile); // no checking for size
  474. if (nLen == 0)
  475. return TRUE; // consider valid
  476. // backdoor
  477. if ((GetKeyState(VK_SHIFT) & 0x8000) > 0)
  478. return TRUE;
  479. hCtrl = GetDlgItem(hDlg, nID);
  480. //----- Check that this is a bitmap -----
  481. // Note. The docs say that LR_LOADFROMFILE is not supported on NT?
  482. hBmp = LoadImage(NULL, szFile, IMAGE_BITMAP, 0, 0,
  483. LR_LOADFROMFILE | LR_CREATEDIBSECTION);
  484. if (hBmp == NULL) {
  485. ErrorMessageBox(hDlg, IDS_INVALIDBITMAP);
  486. SendMessage(hCtrl, EM_SETSEL, 0, -1);
  487. SetFocus(hCtrl);
  488. return FALSE;
  489. }
  490. if (cx == 0 && cy == 0) {
  491. DeleteObject(hBmp);
  492. return TRUE;
  493. }
  494. GetObject(hBmp, sizeof(BITMAP), &bm);
  495. DeleteObject(hBmp); // no longer needed
  496. //----- Check the dimensions if interested -----
  497. if (dwFlags & BMP_EXACT)
  498. {
  499. if ((bm.bmWidth > cx) || (bm.bmHeight > cy))
  500. nIDError = nIDTooBig;
  501. else if ((bm.bmWidth < cx) || (bm.bmHeight < cy))
  502. nIDError = nIDTooSmall;
  503. }
  504. else
  505. {
  506. LONG cxBigTolerance, cyBigTolerance,
  507. cxSmallTolerance = 0, cySmallTolerance = 0;
  508. // Note. The current tolearne is 10%.
  509. ASSERT(cx > 0 && cy > 0);
  510. if (dwFlags & BMP_SMALLER)
  511. {
  512. cxBigTolerance = cx;
  513. cyBigTolerance = cy;
  514. }
  515. else
  516. {
  517. cxBigTolerance = cx + cx/10;
  518. cyBigTolerance = cy + cy/10;
  519. cxSmallTolerance = cx - cx/10;
  520. cySmallTolerance = cy - cy/10;
  521. }
  522. ASSERT(cxSmallTolerance >= 0 && cySmallTolerance >= 0);
  523. if (bm.bmWidth > cxBigTolerance || bm.bmHeight > cyBigTolerance)
  524. nIDError = nIDTooBig;
  525. else if (!(dwFlags & BMP_SMALLER) &&
  526. (bm.bmWidth < cxSmallTolerance || bm.bmHeight < cySmallTolerance))
  527. nIDError = nIDTooSmall;
  528. }
  529. if ((nIDError==0) && (bm.bmBitsPixel > 8))
  530. nIDError = IDS_TOOMANYCOLORS;
  531. if (nIDError != 0) {
  532. ErrorMessageBox(hDlg, nIDError);
  533. SendMessage(hCtrl, EM_SETSEL, 0, -1);
  534. SetFocus(hCtrl);
  535. return FALSE;
  536. }
  537. return TRUE;
  538. }
  539. typedef struct tagFILTERS
  540. {
  541. DWORD dwFilterMask;
  542. UINT uFilterId;
  543. UINT uDescId;
  544. } FILTERS;
  545. // order that filters show up in browse dialog is based on order in this array
  546. static FILTERS s_afFilters[] =
  547. {
  548. { GFN_CDF, IDS_CDF_FILTER, IDS_COMP_CDF },
  549. { GFN_ICO, IDS_ICO_FILTER, IDS_COMP_ICO },
  550. { GFN_PICTURE, IDS_IMAGES_FILTER, IDS_COMP_IMAGES },
  551. { GFN_LOCALHTM, IDS_HTMLDOC_FILTER, IDS_COMP_FILEHTML },
  552. { GFN_MYCOMP, IDS_MYCOMP_FILTER, IDS_COMP_MYCOMP },
  553. { GFN_CONTROLP, IDS_CONTROLP_FILTER, IDS_COMP_CONTROLP },
  554. { GFN_CERTIFICATE, IDS_CERTIFICATE_FILTER, IDS_COMP_CERT },
  555. { GFN_BMP, IDS_BMP_FILTER, IDS_COMP_FILEBMP },
  556. { GFN_ADM, IDS_ADM_FILTER, IDS_COMP_ADM },
  557. { GFN_INS, IDS_INS_FILTER, IDS_COMP_INSFILE },
  558. { GFN_PVK, IDS_PVK_FILTER, IDS_COMP_PVK },
  559. { GFN_SPC, IDS_SPC_FILTER, IDS_COMP_SPC },
  560. { GFN_SCRIPT, IDS_SCRIPT_FILTER, IDS_COMP_SCRIPT },
  561. { GFN_TXT, IDS_TXT_FILTER, IDS_COMP_TXT },
  562. { GFN_EXE, IDS_EXE_FILTER, IDS_COMP_EXE },
  563. { GFN_CAB, IDS_CAB_FILTER, IDS_COMP_CAB },
  564. { GFN_RULES, IDS_RULES_FILTER, IDS_COMP_RULES },
  565. { GFN_ISP, IDS_ISP_FILTER, IDS_COMP_ISP },
  566. { GFN_WAV, IDS_WAV_FILTER, IDS_COMP_WAV },
  567. { GFN_GIF, IDS_GIF_FILTER, IDS_COMP_GIF }
  568. };
  569. static BOOL browseForFileHelper(HWND hDlg, LPTSTR pszFileName, DWORD cchSize, DWORD dwFilterMasks,
  570. LPCTSTR pcszTitle /* = NULL */)
  571. {
  572. OPENFILENAME ofn;
  573. TCHAR szTitle[MAX_PATH];
  574. TCHAR szBrowseDir[MAX_PATH];
  575. TCHAR szFilter[MAX_PATH];
  576. static TCHAR szDefaultDir[MAX_PATH];
  577. if (pszFileName == NULL)
  578. return FALSE;
  579. ZeroMemory((PVOID) &ofn, sizeof(ofn));
  580. // initialize the relevant fields in ofn
  581. ofn.lStructSize = sizeof(ofn);
  582. ofn.hwndOwner = hDlg;
  583. ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
  584. if (pcszTitle == NULL || ISNULL(pcszTitle))
  585. {
  586. if (LoadString(g_hInst, IDS_BROWSE, szTitle, ARRAYSIZE(szTitle)))
  587. ofn.lpstrTitle = szTitle;
  588. }
  589. else
  590. ofn.lpstrTitle = pcszTitle;
  591. // initialize the InitialDir field
  592. if (*pszFileName)
  593. {
  594. StrCpy(szBrowseDir, pszFileName);
  595. if (PathIsUNCServer(szBrowseDir) ||
  596. ((PathIsDirectory(szBrowseDir) || PathRemoveFileSpec(szBrowseDir)) && PathFileExists(szBrowseDir)))
  597. ofn.lpstrInitialDir = szBrowseDir;
  598. }
  599. else if (*szDefaultDir)
  600. {
  601. ofn.lpstrInitialDir = szDefaultDir;
  602. }
  603. else {
  604. if (!FAILED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, szBrowseDir))) //default to my docs
  605. ofn.lpstrInitialDir = szBrowseDir;
  606. }
  607. *pszFileName = TEXT('\0');
  608. ofn.lpstrFile = pszFileName;
  609. ofn.nMaxFile = cchSize;
  610. // set the filter
  611. if (dwFilterMasks)
  612. {
  613. LPTSTR pszFilter;
  614. INT cchFilter, cchRead;
  615. // load the description for the filter
  616. pszFilter = szFilter;
  617. cchFilter = ARRAYSIZE(szFilter) - 1; // room for the final second nul char
  618. for (int i = 0; i < ARRAYSIZE(s_afFilters); i++)
  619. {
  620. if (dwFilterMasks & s_afFilters[i].dwFilterMask)
  621. {
  622. cchRead = LoadString(g_hDLLInst, s_afFilters[i].uDescId, pszFilter, cchFilter);
  623. cchFilter -= cchRead + 1;
  624. // filter description
  625. if ((cchRead != 0) && (cchFilter != 0))
  626. {
  627. pszFilter += cchRead;
  628. *pszFilter++ = TEXT('\0');
  629. }
  630. cchRead = LoadString(g_hDLLInst, s_afFilters[i].uFilterId, pszFilter, cchFilter);
  631. cchFilter -= cchRead + 1;
  632. // filter extensions
  633. if ((cchRead != 0) && (cchFilter != 0))
  634. {
  635. pszFilter += cchRead;
  636. *pszFilter++ = TEXT('\0');
  637. }
  638. }
  639. }
  640. // double nul terminate the string.
  641. *pszFilter = TEXT('\0');
  642. ofn.lpstrFilter = szFilter;
  643. }
  644. BOOL bRetVal = GetOpenFileName(&ofn);
  645. //save the dir so we return here.
  646. StrCpy(szDefaultDir,ofn.lpstrFile);
  647. PathRemoveFileSpec(szDefaultDir);
  648. return bRetVal;
  649. }
  650. static BOOL browseForFolderHelper(HWND hDlg, LPTSTR pszFileName, LPCTSTR pcszDesc)
  651. {
  652. LPITEMIDLIST pId;
  653. BROWSEINFO bInfo;
  654. ZeroMemory(&bInfo, sizeof(bInfo));
  655. bInfo.hwndOwner = hDlg;
  656. bInfo.pidlRoot = NULL;
  657. bInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_RETURNFSANCESTORS;
  658. bInfo.pszDisplayName = pszFileName;
  659. if (pcszDesc)
  660. bInfo.lpszTitle = pcszDesc;
  661. pId = SHBrowseForFolder(&bInfo);
  662. if (!pId)
  663. return FALSE;
  664. SHGetPathFromIDList(pId, pszFileName);
  665. // BUGBUG: <oliverl> shoule we free pId?
  666. return TRUE;
  667. }
  668. void WINAPI ErrorMessageBox(HWND hWnd, UINT idErrorStr, DWORD dwFlags /* = 0 */)
  669. {
  670. TCHAR szTitle[MAX_PATH],
  671. szMsg[MAX_PATH];
  672. if (LoadString(g_hDLLInst, IDS_TITLE, szTitle, ARRAYSIZE(szTitle)) == 0)
  673. LoadString(g_hInst, IDS_TITLE, szTitle, ARRAYSIZE(szTitle));
  674. if (LoadString(g_hDLLInst, idErrorStr, szMsg, ARRAYSIZE(szMsg)) == 0)
  675. LoadString(g_hInst, idErrorStr, szMsg, ARRAYSIZE(szMsg));
  676. MessageBox(hWnd, szMsg, szTitle,
  677. dwFlags ? dwFlags : MB_OK | MB_SETFOREGROUND | MB_ICONEXCLAMATION);
  678. }
  679. static void exportRegTree2InfHelper(HKEY hk, LPCTSTR pszHive, LPCTSTR pszKey, HANDLE hInf, BOOL fUseLdids)
  680. // Export all the value names and sub-keys under pcszSubKey to hInf as AddReg lines
  681. {
  682. TCHAR szSubKey[MAX_PATH],
  683. szFullSubKey[MAX_PATH];
  684. DWORD dwIndex = 0;
  685. DWORD dwSub = countof(szSubKey);
  686. exportRegKey2InfHelper(hk, pszHive, pszKey, hInf, fUseLdids);
  687. while (RegEnumKeyEx(hk, dwIndex, szSubKey, &dwSub, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
  688. HKEY hkSub;
  689. if (RegOpenKeyEx(hk, szSubKey, 0, KEY_ENUMERATE_SUB_KEYS | KEY_READ, &hkSub) == ERROR_SUCCESS) {
  690. wnsprintf(szFullSubKey, ARRAYSIZE(szFullSubKey), TEXT("%s\\%s"), pszKey, szSubKey);
  691. exportRegTree2InfHelper(hkSub, pszHive, szFullSubKey, hInf, fUseLdids);
  692. WriteStringToFile(hInf, (LPCVOID) TEXT("\r\n"), 2);
  693. RegCloseKey(hkSub);
  694. }
  695. dwIndex++;
  696. dwSub = countof(szSubKey);
  697. }
  698. }
  699. static const TCHAR c_szSzType[] = TEXT("%s,\"%s\",%s,,\"%s\"");
  700. static const TCHAR c_szDwordType[] = TEXT("%s,\"%s\",%s,0x10001");
  701. static const TCHAR c_szBinaryType[] = TEXT("%s,\"%s\",%s,1");
  702. static void exportRegValue2InfHelper(HKEY hkSubKey, LPCTSTR pcszValue, LPCTSTR pcszRootKey, LPCTSTR pcszSubKey, HANDLE hInf, BOOL fUseLdids)
  703. {
  704. TCHAR szInfLine[(4 * MAX_URL) + MAX_PATH];
  705. BYTE rgbData[2*MAX_URL];
  706. DWORD cbData,
  707. dwType;
  708. LONG lResult;
  709. int i, j, k;
  710. cbData = 2*MAX_URL;
  711. lResult = RegQueryValueEx(hkSubKey, pcszValue, NULL, &dwType, rgbData, &cbData);
  712. if ((lResult != ERROR_SUCCESS) || ((pcszValue == NULL) && (cbData <= 1)))
  713. return;
  714. switch (dwType) {
  715. case REG_EXPAND_SZ:
  716. // use shlwapi API to get the expanded value, then fall through to write addreg
  717. // entry to inf as REG_SZ
  718. lResult = SHQueryValueEx(hkSubKey, pcszValue, NULL, &dwType, rgbData, &cbData);
  719. if ((lResult != ERROR_SUCCESS) || ((pcszValue == NULL) && (cbData <= 1)))
  720. return;
  721. case REG_SZ:
  722. if (fUseLdids)
  723. PathReplaceWithLDIDs((LPTSTR)rgbData);
  724. wnsprintf(szInfLine, ARRAYSIZE(szInfLine), c_szSzType, pcszRootKey, pcszSubKey,
  725. (pcszValue == NULL) ? TEXT("") : pcszValue, (LPCTSTR)rgbData);
  726. break;
  727. case REG_DWORD:
  728. wnsprintf(szInfLine, ARRAYSIZE(szInfLine), c_szDwordType, pcszRootKey, pcszSubKey, pcszValue);
  729. for (i = 0; i < 4; i++)
  730. AppendCommaHex(szInfLine, rgbData[i], 1);
  731. break;
  732. case REG_BINARY:
  733. default:
  734. wnsprintf(szInfLine, ARRAYSIZE(szInfLine), c_szBinaryType, pcszRootKey, pcszSubKey, pcszValue);
  735. for (i = 0, j = k = StrLen(szInfLine);
  736. i < (int)cbData && k < countof(szInfLine); i++, j += 3, k += 3) {
  737. AppendCommaHex(szInfLine, rgbData[i], 1);
  738. if (j >= 240) {
  739. StrCat(szInfLine, TEXT("\\\r\n"));
  740. j = 0;
  741. k += 3;
  742. }
  743. }
  744. break;
  745. }
  746. StrCat(szInfLine, TEXT("\r\n"));
  747. WriteStringToFile(hInf, szInfLine, StrLen(szInfLine));
  748. }
  749. static void exportRegKey2InfHelper(HKEY hkSubKey, LPCTSTR pcszRootKey, LPCTSTR pcszSubKey, HANDLE hInf, BOOL fUseLdids)
  750. // Export all the value names under pcszSubKey to hInf as AddReg lines
  751. {
  752. DWORD dwIndex;
  753. TCHAR szValue[MAX_PATH];
  754. DWORD cchValue, dwType;
  755. for (dwIndex = 0, cchValue = countof(szValue);
  756. RegEnumValue(hkSubKey, dwIndex, szValue, &cchValue, NULL, &dwType, NULL, NULL) == ERROR_SUCCESS;
  757. dwIndex++, cchValue = countof(szValue))
  758. exportRegValue2InfHelper(hkSubKey, szValue, pcszRootKey, pcszSubKey, hInf, fUseLdids);
  759. }
  760. /////////////////////////////////////////////////////////////////////////////
  761. // Private routines (non-exported)
  762. static void signFileHelper(LPCTSTR pcszFilename, LPCTSTR pcszDir, LPCTSTR pcszIns, LPTSTR pszUnsignedFiles, LPCTSTR pcszCustInf, BOOL fTest)
  763. {
  764. DWORD dwExitCode=0, dwLen;
  765. static BOOL s_fFirst = TRUE;
  766. TCHAR szDesc[MAX_PATH];
  767. TCHAR szPVKPath[MAX_PATH];
  768. TCHAR szSPCPath[MAX_PATH];
  769. TCHAR szInfoUrl[INTERNET_MAX_URL_LENGTH];
  770. TCHAR szTimeUrl[INTERNET_MAX_URL_LENGTH];
  771. TCHAR szDest[MAX_PATH];
  772. TCHAR szCmd[INTERNET_MAX_URL_LENGTH + MAX_PATH];
  773. // note that pcszDir is only passed in as NULL if we're test signing something
  774. if (!InsGetString(IS_CABSIGN, IK_PVK, szPVKPath, countof(szPVKPath), pcszIns) ||
  775. !InsGetString(IS_CABSIGN, IK_SPC, szSPCPath, countof(szSPCPath), pcszIns))
  776. return;
  777. if (s_fFirst && !fTest)
  778. {
  779. s_fFirst = FALSE;
  780. if (pcszCustInf != NULL)
  781. {
  782. if (InsGetString(IS_CABSIGN, RV_COMPANYNAME, szDesc, countof(szDesc), pcszIns))
  783. {
  784. HKEY hKey;
  785. if(RegOpenKeyEx(HKEY_CURRENT_USER, RK_TRUSTKEY, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
  786. {
  787. TCHAR szKey[MAX_PATH];
  788. TCHAR szValue[MAX_PATH];
  789. DWORD dwValueKey,dwValue;
  790. int iEntry=0;
  791. dwValueKey=countof(szKey);
  792. dwValue=sizeof(szValue);
  793. ZeroMemory(szCmd, sizeof(szCmd));
  794. if(RegEnumValue(hKey, 0, szKey, &dwValueKey, NULL, NULL, (BYTE *) szValue, &dwValue) == ERROR_SUCCESS)
  795. {
  796. do
  797. {
  798. if(StrCmpI(szValue, szDesc) == 0)
  799. {
  800. wnsprintf(szInfoUrl, ARRAYSIZE(szInfoUrl), CABSIGN_INF_ADD, szKey, szValue);
  801. StrCat(szCmd, szInfoUrl);
  802. }
  803. iEntry++;
  804. dwValueKey=countof(szKey);
  805. dwValue=sizeof(szValue);
  806. } while (RegEnumValue(hKey, iEntry, szKey, &dwValueKey, NULL, NULL, (BYTE *) szValue, &dwValue) != ERROR_NO_MORE_ITEMS);
  807. }
  808. RegCloseKey(hKey);
  809. if (ISNONNULL(szCmd))
  810. {
  811. InsDeleteSection(TEXT("IEAK.Company.reg"), pcszCustInf);
  812. WritePrivateProfileSection(TEXT("IEAK.Company.reg"), szCmd, pcszCustInf);
  813. InsFlushChanges(pcszCustInf);
  814. }
  815. }
  816. }
  817. }
  818. if (pcszDir != NULL)
  819. {
  820. PathCombine(szDest, pcszDir, PathFindFileName(szPVKPath));
  821. CopyFile(szPVKPath, szDest, FALSE);
  822. PathCombine(szDest, pcszDir, PathFindFileName(szSPCPath));
  823. CopyFile(szSPCPath, szDest, FALSE);
  824. }
  825. }
  826. InsGetString(IS_CABSIGN, IK_NAME, szDesc, countof(szDesc), pcszIns);
  827. if (pcszDir != NULL)
  828. PathCombine(szDest, pcszDir, TEXT("SIGNCODE.EXE"));
  829. else
  830. {
  831. StrCpy(szDest, pcszFilename);
  832. PathRemoveFileSpec(szDest);
  833. CopyFileToDir(szPVKPath, szDest);
  834. CopyFileToDir(szSPCPath, szDest);
  835. PathAppend(szDest, TEXT("signcode.exe"));
  836. }
  837. wnsprintf(szCmd, countof(szCmd), TEXT("\"%s\" -spc \"%s\" -v \"%s\" -n \"%s\""),
  838. szDest, PathFindFileName(szSPCPath), PathFindFileName(szPVKPath), szDesc);
  839. if ((pcszDir != NULL) &&
  840. InsGetString(IS_CABSIGN, IK_CSURL, szInfoUrl, countof(szInfoUrl), pcszIns))
  841. {
  842. dwLen = StrLen(szCmd);
  843. wnsprintf(szCmd + dwLen, countof(szCmd) - dwLen, TEXT(" -i \"%s\""), szInfoUrl);
  844. }
  845. if ((pcszDir != NULL) &&
  846. InsGetString(IS_CABSIGN, IK_CSTIME, szTimeUrl, countof(szTimeUrl), pcszIns))
  847. {
  848. dwLen = StrLen(szCmd);
  849. wnsprintf(szCmd + dwLen, countof(szCmd) - dwLen, TEXT(" -t \"%s\""), szTimeUrl);
  850. }
  851. dwLen = StrLen(szCmd);
  852. wnsprintf(szCmd + dwLen, countof(szCmd) - dwLen, TEXT(" \"%s\""), PathFindFileName(pcszFilename));
  853. if (pcszDir == NULL)
  854. PathRemoveFileSpec(szDest);
  855. if (!RunAndWait(szCmd, (pcszDir == NULL) ? szDest : pcszDir, SW_HIDE, &dwExitCode)
  856. || (dwExitCode == -1))
  857. {
  858. if (pszUnsignedFiles != NULL)
  859. {
  860. StrCat(pszUnsignedFiles, TEXT("\r\n"));
  861. StrCat(pszUnsignedFiles, pcszFilename);
  862. }
  863. }
  864. if (pcszDir == NULL)
  865. {
  866. DeleteFileInDir(szPVKPath, szDest);
  867. DeleteFileInDir(szSPCPath, szDest);
  868. }
  869. }
  870. void WINAPI DoReboot(HWND hwndUI)
  871. {
  872. TCHAR szMsg[MAX_PATH];
  873. TCHAR szTitle[128];
  874. LoadString(g_hInst, IDS_TITLE, szTitle, ARRAYSIZE(szTitle));
  875. LoadString(g_hDLLInst, IDS_RESTARTYESNO, szMsg, ARRAYSIZE(szMsg));
  876. if (MessageBox(hwndUI, szMsg, szTitle, MB_YESNO) == IDNO)
  877. return;
  878. if (IsOS(OS_NT))
  879. {
  880. HANDLE hToken;
  881. TOKEN_PRIVILEGES tkp;
  882. // get a token from this process
  883. if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
  884. {
  885. // get the LUID for the shutdown privilege
  886. LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
  887. tkp.PrivilegeCount = 1;
  888. tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  889. //get the shutdown privilege for this proces
  890. AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
  891. }
  892. ExitWindowsEx(EWX_REBOOT, 0);
  893. }
  894. else
  895. ExitWindowsEx(EWX_REBOOT, 0);
  896. }
  897. void WINAPI ShowInetcpl(HWND hDlg, DWORD dwPages, DWORD dwMode /*= IEM_ADMIN*/)
  898. {
  899. HKEY hkInetcpl = NULL;
  900. HINSTANCE hInetcpl = NULL;
  901. DWORD dwGeneral = 0, dwSecurity = 0, dwContent = 0,
  902. dwConnect = 0, dwPrograms = 0, dwAdvanced = 0,
  903. dwPrivacy = 0, dwIEAK = 0, dwAutoconfig = 0;
  904. // set restrictions to disable pages we aren't interested in,
  905. // tracking whether or not we set or cleared the restriction
  906. if (SHCreateKeyHKCU(RK_INETCPL, KEY_DEFAULT_ACCESS, &hkInetcpl) == ERROR_SUCCESS)
  907. {
  908. dwGeneral = RegSaveRestoreDWORD(hkInetcpl, REGSTR_VAL_INETCPL_GENERALTAB,
  909. (dwPages & INET_PAGE_GENERAL) ? 0 : 1);
  910. dwSecurity = RegSaveRestoreDWORD(hkInetcpl, REGSTR_VAL_INETCPL_SECURITYTAB,
  911. (dwPages & INET_PAGE_SECURITY) ? 0 : 1);
  912. dwContent = RegSaveRestoreDWORD(hkInetcpl, REGSTR_VAL_INETCPL_CONTENTTAB,
  913. (dwPages & INET_PAGE_CONTENT) ? 0 : 1);
  914. dwConnect = RegSaveRestoreDWORD(hkInetcpl, REGSTR_VAL_INETCPL_CONNECTIONSTAB,
  915. (dwPages & INET_PAGE_CONNECTION) ? 0 : 1);
  916. dwPrivacy = RegSaveRestoreDWORD(hkInetcpl, REGSTR_VAL_INETCPL_PRIVACYTAB,
  917. (dwPages & INET_PAGE_PRIVACY) ? 0 : 1);
  918. dwPrograms = RegSaveRestoreDWORD(hkInetcpl, REGSTR_VAL_INETCPL_PROGRAMSTAB,
  919. (dwPages & INET_PAGE_PROGRAMS) ? 0 : 1);
  920. dwAdvanced = RegSaveRestoreDWORD(hkInetcpl, REGSTR_VAL_INETCPL_ADVANCEDTAB,
  921. (dwPages & INET_PAGE_ADVANCED) ? 0 : 1);
  922. dwIEAK = RegSaveRestoreDWORD(hkInetcpl, REGSTR_VAL_INETCPL_IEAK, 1);
  923. // always set restriction to disable autoconfig exposure in inetcpl if we're not
  924. // running in corp mode
  925. if (!HasFlag(dwMode, IEM_ADMIN))
  926. dwAutoconfig = RegSaveRestoreDWORD(hkInetcpl, TEXT("Autoconfig"), 1);
  927. }
  928. if ((hInetcpl = LoadLibrary(TEXT("inetcpl.cpl"))) != NULL)
  929. {
  930. typedef BOOL (WINAPI * LAUNCHINTERNETCONTROLPANEL)(HWND hDlg);
  931. LAUNCHINTERNETCONTROLPANEL pLaunchInternetControlPanel;
  932. if ((pLaunchInternetControlPanel = (LAUNCHINTERNETCONTROLPANEL)
  933. GetProcAddress(hInetcpl, "LaunchInternetControlPanel")) != NULL)
  934. pLaunchInternetControlPanel(hDlg);
  935. FreeLibrary(hInetcpl);
  936. }
  937. if (hkInetcpl != NULL)
  938. {
  939. // reset the restrictions that we set, in this case we'll be passing in FALSE for those
  940. // we set which will clear the value, and TRUE for those we didn't set which will leave
  941. // them as set
  942. RegSaveRestoreDWORD(hkInetcpl, REGSTR_VAL_INETCPL_GENERALTAB, dwGeneral);
  943. RegSaveRestoreDWORD(hkInetcpl, REGSTR_VAL_INETCPL_SECURITYTAB, dwSecurity);
  944. RegSaveRestoreDWORD(hkInetcpl, REGSTR_VAL_INETCPL_CONTENTTAB, dwContent);
  945. RegSaveRestoreDWORD(hkInetcpl, REGSTR_VAL_INETCPL_CONNECTIONSTAB, dwConnect);
  946. RegSaveRestoreDWORD(hkInetcpl, REGSTR_VAL_INETCPL_PROGRAMSTAB, dwPrograms);
  947. RegSaveRestoreDWORD(hkInetcpl, REGSTR_VAL_INETCPL_PRIVACYTAB, dwPrivacy);
  948. RegSaveRestoreDWORD(hkInetcpl, REGSTR_VAL_INETCPL_ADVANCEDTAB, dwAdvanced);
  949. RegSaveRestoreDWORD(hkInetcpl, REGSTR_VAL_INETCPL_IEAK, dwIEAK);
  950. if (!HasFlag(dwMode, IEM_ADMIN))
  951. RegSaveRestoreDWORD(hkInetcpl, TEXT("Autoconfig"), dwAutoconfig);
  952. }
  953. }