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.

841 lines
27 KiB

  1. // ==++==
  2. //
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. //
  5. // ==--==
  6. //+---------------------------------------------------------------------------
  7. //
  8. // Microsoft Windows
  9. // File: fuslogvw.c
  10. //
  11. // Contents:
  12. //
  13. // Classes:
  14. //
  15. // Functions:
  16. //
  17. // History: 25 Mar 97 t-alans (Alan Shi) Created
  18. // 12 Jan 00 AlanShi (Alan Shi) Copied from cdllogvw
  19. // 30 May 00 AlanShi (Alan Shi) Modified to show date/time
  20. // 01 Dec 00 AlanShi (Alan Shi) Added application name field
  21. //
  22. //----------------------------------------------------------------------------
  23. #include <windows.h>
  24. #include <shlwapi.h>
  25. #include <shellapi.h>
  26. #include <wininet.h>
  27. #include <commctrl.h>
  28. #include "cdlids.h"
  29. #include "wininet.h"
  30. #define URL_SEARCH_PATTERN "?ClickOnceErrorLog!exe="
  31. #define FILESPEC_SEARCH_PATTERN TEXT("?ClickOnceErrorLog!exe=")
  32. #define DELIMITER_CHAR '!'
  33. #define MAX_CACHE_ENTRY_INFO_SIZE 2048
  34. #define MAX_DATE_LEN 64
  35. #define MAX_RES_TEXT_LEN 1024
  36. #define XSP_APP_CACHE_DIR TEXT("Temporary ASP.NET Files")
  37. #define XSP_FUSION_LOG_DIR TEXT("Bind Logs")
  38. #define REG_KEY_FUSION_SETTINGS TEXT("Software\\Microsoft\\Fusion\\Installer\\1.0.0.0\\")
  39. #define REG_VAL_FUSION_LOG_PATH TEXT("LogPath")
  40. #define REG_VAL_FUSION_LOG_FAILURES TEXT("LogFailures")
  41. #define PAD_DIGITS_FOR_STRING(x) (((x) > 9) ? TEXT("") : TEXT("0"))
  42. typedef enum tagLogLocation {
  43. LOG_DEFAULT,
  44. LOG_XSP,
  45. LOG_CUSTOM
  46. } LogLocation;
  47. LogLocation g_LogLocation;
  48. TCHAR g_szCustomLogPath[MAX_PATH];
  49. TCHAR g_szXSPLogPath[MAX_PATH];
  50. HINSTANCE g_hInst;
  51. typedef HRESULT(*PFNGETCORSYSTEMDIRECTORY)(LPWSTR, DWORD, LPDWORD);
  52. LRESULT CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
  53. void ViewLogEntry(HWND hwnd);
  54. void RefreshLogView(HWND hwnd, LogLocation logLocation);
  55. void RefreshCustomView(HWND hwnd, LPCTSTR szPath);
  56. void RefreshWininetView(HWND hwnd);
  57. void DeleteLogEntry(HWND hwnd);
  58. void DeleteAllLogs(HWND hwnd);
  59. void FormatDateBuffer(FILETIME *pftLastMod, LPSTR szBuf);
  60. void InitListView(HWND hwndLV);
  61. void InitText(HWND hwnd);
  62. void AddLogItem(HWND hwndLV, LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo);
  63. void AddLogItemCustom(HWND hwndLV, WIN32_FIND_DATA *pfindData);
  64. void InitCustomLogPaths();
  65. BOOL InsertCustomLogEntry(LPTSTR szFilePath, HWND hwndLV);
  66. BOOL GetCorSystemDirectory(LPTSTR szCorSystemDir);
  67. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  68. PSTR szCmdLine, int iCmdShow)
  69. {
  70. g_hInst = hInstance;
  71. DialogBox(hInstance, MAKEINTRESOURCE(IDD_CDLLOGVIEW), NULL, DlgProc);
  72. return 0;
  73. }
  74. LRESULT CALLBACK DlgProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  75. {
  76. HWND hwndLV;
  77. HWND hwndRBDefault;
  78. LPNMHDR pnmh = NULL;
  79. LONG lResult;
  80. LONG lState;
  81. HKEY hkey;
  82. DWORD dwLogFailures = 0;
  83. DWORD dwSize;
  84. DWORD dwType;
  85. switch (iMsg) {
  86. case WM_INITDIALOG:
  87. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  88. InitListView(hwndLV);
  89. hwndRBDefault = GetDlgItem(hwnd, IDC_RADIO_DEFAULT);
  90. SendMessage(hwndRBDefault, BM_SETCHECK, BST_CHECKED, 0);
  91. g_LogLocation = LOG_DEFAULT;
  92. InitCustomLogPaths();
  93. InitText(hwnd);
  94. RefreshLogView(hwnd, g_LogLocation);
  95. lResult = RegOpenKeyEx(HKEY_CURRENT_USER, REG_KEY_FUSION_SETTINGS, 0, KEY_READ, &hkey);
  96. if (lResult == ERROR_SUCCESS) {
  97. dwSize = sizeof(DWORD);
  98. lResult = RegQueryValueEx(hkey, REG_VAL_FUSION_LOG_FAILURES, NULL,
  99. &dwType, (LPBYTE)&dwLogFailures, &dwSize);
  100. RegCloseKey(hkey);
  101. }
  102. if (dwLogFailures) {
  103. SendMessage(GetDlgItem(hwnd, IDC_CB_ENABLELOG), BM_SETCHECK, 1, 0);
  104. }
  105. else {
  106. SendMessage(GetDlgItem(hwnd, IDC_CB_ENABLELOG), BM_SETCHECK, 0, 0);
  107. }
  108. // Test for read/write access, and grey out if can't change
  109. lResult = RegOpenKeyEx(HKEY_CURRENT_USER, REG_KEY_FUSION_SETTINGS, 0, KEY_ALL_ACCESS, &hkey);
  110. if (lResult == ERROR_SUCCESS) {
  111. RegCloseKey(hkey);
  112. }
  113. else {
  114. EnableWindow(GetDlgItem(hwnd, IDC_CB_ENABLELOG), FALSE);
  115. }
  116. return TRUE;
  117. case WM_COMMAND:
  118. switch (LOWORD(wParam)) {
  119. case IDCANCEL:
  120. EndDialog(hwnd, 0);
  121. break;
  122. case IDC_CB_VIEWLOG:
  123. ViewLogEntry(hwnd);
  124. break;
  125. case IDC_CB_REFRESH:
  126. RefreshLogView(hwnd, g_LogLocation);
  127. break;
  128. case IDC_CB_DELETE:
  129. DeleteLogEntry(hwnd);
  130. break;
  131. case IDC_CB_DELETE_ALL:
  132. DeleteAllLogs(hwnd);
  133. break;
  134. case IDC_RADIO_DEFAULT:
  135. if (g_LogLocation == LOG_DEFAULT) {
  136. // No change
  137. break;
  138. }
  139. g_LogLocation = LOG_DEFAULT;
  140. RefreshLogView(hwnd, g_LogLocation);
  141. break;
  142. case IDC_RADIO_XSP:
  143. if (g_LogLocation == LOG_XSP) {
  144. // No change
  145. break;
  146. }
  147. g_LogLocation = LOG_XSP;
  148. RefreshLogView(hwnd, g_LogLocation);
  149. break;
  150. case IDC_RADIO_CUSTOM:
  151. if (g_LogLocation == LOG_CUSTOM) {
  152. // No change
  153. break;
  154. }
  155. g_LogLocation = LOG_CUSTOM;
  156. RefreshLogView(hwnd, g_LogLocation);
  157. break;
  158. /*
  159. case IDC_CB_ENABLELOG:
  160. lResult = RegOpenKeyEx(HKEY_CURRENT_USER, REG_KEY_FUSION_SETTINGS, 0, KEY_ALL_ACCESS, &hkey);
  161. if (lResult == ERROR_SUCCESS) {
  162. lState = SendMessage(GetDlgItem(hwnd, IDC_CB_ENABLELOG),
  163. BM_GETCHECK, 0, 0);
  164. dwLogFailures = (lState == BST_CHECKED) ? (1) : (0);
  165. RegSetValueEx(hkey, REG_VAL_FUSION_LOG_FAILURES, 0,
  166. REG_DWORD, (BYTE*)&dwLogFailures, sizeof(dwLogFailures));
  167. RegCloseKey(hkey);
  168. }
  169. break;
  170. */
  171. }
  172. return TRUE;
  173. case WM_NOTIFY:
  174. if (wParam == IDC_LV_LOGMESSAGES) {
  175. pnmh = (LPNMHDR)lParam;
  176. if (pnmh->code == LVN_ITEMACTIVATE) {
  177. // Double click (or otherwise activated)
  178. ViewLogEntry(hwnd);
  179. }
  180. }
  181. return TRUE;
  182. }
  183. return FALSE;
  184. }
  185. void DeleteLogEntry(HWND hwnd)
  186. {
  187. LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo = NULL;
  188. DWORD dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  189. HWND hwndLV;
  190. LRESULT lIndex = 0;
  191. LRESULT lLength = 0;
  192. static char pBuffer[MAX_CACHE_ENTRY_INFO_SIZE];
  193. char szUrl[INTERNET_MAX_URL_LENGTH];
  194. char szDispNameBuf[INTERNET_MAX_URL_LENGTH];
  195. char szEXEBuf[MAX_PATH];
  196. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  197. lIndex = ListView_GetSelectionMark(hwndLV);
  198. ListView_GetItemText(hwndLV, lIndex, 0, szEXEBuf, MAX_PATH);
  199. ListView_GetItemText(hwndLV, lIndex, 2, szDispNameBuf, INTERNET_MAX_URL_LENGTH);
  200. if (g_LogLocation == LOG_DEFAULT) {
  201. wnsprintf(szUrl, INTERNET_MAX_URL_LENGTH, "%s%s!name=%s", URL_SEARCH_PATTERN, szEXEBuf, szDispNameBuf);
  202. pCacheEntryInfo = (LPINTERNET_CACHE_ENTRY_INFO)pBuffer;
  203. dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  204. if (DeleteUrlCacheEntry(szUrl)) {
  205. RefreshLogView(hwnd, g_LogLocation);
  206. }
  207. else {
  208. MessageBox(hwnd, "Error: Unable to delete cache file!",
  209. "Log View Error", MB_OK | MB_ICONERROR);
  210. }
  211. }
  212. else {
  213. wnsprintf(szUrl, INTERNET_MAX_URL_LENGTH, "%s\\%s\\%s%s!name=%s.htm",
  214. ((g_LogLocation == LOG_XSP) ? (g_szXSPLogPath) : (g_szCustomLogPath)),
  215. szEXEBuf, FILESPEC_SEARCH_PATTERN, szEXEBuf, szDispNameBuf);
  216. if (!DeleteFile(szUrl)) {
  217. MessageBox(hwnd, "Error: Unable to delete cache file!",
  218. "Log View Error", MB_OK | MB_ICONERROR);
  219. }
  220. RefreshLogView(hwnd, g_LogLocation);
  221. }
  222. }
  223. void DeleteAllLogs(HWND hwnd)
  224. {
  225. HWND hwndLV;
  226. char szDispNameBuf[INTERNET_MAX_URL_LENGTH];
  227. char szEXEBuf[MAX_PATH];
  228. char szUrl[INTERNET_MAX_URL_LENGTH];
  229. int iCount;
  230. int i;
  231. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  232. iCount = ListView_GetItemCount(hwndLV);
  233. for (i = 0; i < iCount; i++) {
  234. ListView_GetItemText(hwndLV, i, 0, szEXEBuf, MAX_PATH);
  235. ListView_GetItemText(hwndLV, i, 2, szDispNameBuf, INTERNET_MAX_URL_LENGTH);
  236. if (g_LogLocation == LOG_DEFAULT) {
  237. wnsprintf(szUrl, INTERNET_MAX_URL_LENGTH, "%s%s!name=%s", URL_SEARCH_PATTERN, szEXEBuf, szDispNameBuf);
  238. DeleteUrlCacheEntry(szUrl);
  239. }
  240. else {
  241. wnsprintf(szUrl, INTERNET_MAX_URL_LENGTH, "%s\\%s\\%s%s!name=%s.htm",
  242. ((g_LogLocation == LOG_XSP) ? (g_szXSPLogPath) : (g_szCustomLogPath)),
  243. szEXEBuf, FILESPEC_SEARCH_PATTERN, szEXEBuf, szDispNameBuf);
  244. if (!DeleteFile(szUrl)) {
  245. MessageBox(hwnd, "Error: Unable to delete cache file!",
  246. "Log View Error", MB_OK | MB_ICONERROR);
  247. }
  248. }
  249. }
  250. RefreshLogView(hwnd, g_LogLocation);
  251. }
  252. void ViewLogEntry(HWND hwnd)
  253. {
  254. LRESULT lIndex = 0;
  255. LRESULT lLength = 0;
  256. HWND hwndLV;
  257. DWORD dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  258. LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo = NULL;
  259. char szUrl[INTERNET_MAX_URL_LENGTH];
  260. char szDispNameBuf[INTERNET_MAX_URL_LENGTH];
  261. char szEXEBuf[MAX_PATH];
  262. static char pBuffer[MAX_CACHE_ENTRY_INFO_SIZE];
  263. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  264. lIndex = ListView_GetSelectionMark(hwndLV);
  265. ListView_GetItemText(hwndLV, lIndex, 0, szEXEBuf, MAX_PATH);
  266. ListView_GetItemText(hwndLV, lIndex, 2, szDispNameBuf, INTERNET_MAX_URL_LENGTH);
  267. if (g_LogLocation == LOG_DEFAULT) {
  268. wnsprintf(szUrl, INTERNET_MAX_URL_LENGTH, "%s%s!name=%s", URL_SEARCH_PATTERN, szEXEBuf, szDispNameBuf);
  269. pCacheEntryInfo = (LPINTERNET_CACHE_ENTRY_INFO)pBuffer;
  270. dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  271. if (GetUrlCacheEntryInfo(szUrl, pCacheEntryInfo, &dwBufferSize)) {
  272. if (pCacheEntryInfo->lpszLocalFileName != NULL) {
  273. if (ShellExecute(NULL, "open", pCacheEntryInfo->lpszLocalFileName,
  274. NULL, NULL, SW_SHOWNORMAL ) <= (HINSTANCE)32) {
  275. // ShellExecute returns <= 32 if error occured
  276. MessageBox(hwnd, TEXT("Error: Unable to open cache file!"),
  277. TEXT("Log View Error"), MB_OK | MB_ICONERROR);
  278. }
  279. }
  280. else {
  281. MessageBox(hwnd, TEXT("Error: No file name available!"),
  282. TEXT("Log View Error"), MB_OK | MB_ICONERROR);
  283. }
  284. }
  285. }
  286. else {
  287. wnsprintf(szUrl, INTERNET_MAX_URL_LENGTH, "%s\\%s\\%s%s!name=%s.htm",
  288. ((g_LogLocation == LOG_XSP) ? (g_szXSPLogPath) : (g_szCustomLogPath)),
  289. szEXEBuf, FILESPEC_SEARCH_PATTERN, szEXEBuf, szDispNameBuf);
  290. if (ShellExecute(NULL, "open", szUrl,
  291. NULL, NULL, SW_SHOWNORMAL ) <= (HINSTANCE)32) {
  292. // ShellExecute returns <= 32 if error occured
  293. MessageBox(hwnd, TEXT("Error: Unable to open cache file!"),
  294. TEXT("Log View Error"), MB_OK | MB_ICONERROR);
  295. }
  296. }
  297. }
  298. void RefreshLogView(HWND hwnd, LogLocation logLocation)
  299. {
  300. HWND hwndLV;
  301. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  302. switch (logLocation) {
  303. case LOG_DEFAULT:
  304. RefreshWininetView(hwnd);
  305. break;
  306. case LOG_XSP:
  307. if (lstrlen(g_szXSPLogPath)) {
  308. RefreshCustomView(hwnd, g_szXSPLogPath);
  309. }
  310. else {
  311. ListView_DeleteAllItems(hwndLV);
  312. }
  313. break;
  314. case LOG_CUSTOM:
  315. if (lstrlen(g_szCustomLogPath)) {
  316. RefreshCustomView(hwnd, g_szCustomLogPath);
  317. }
  318. else {
  319. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  320. ListView_DeleteAllItems(hwndLV);
  321. }
  322. break;
  323. }
  324. }
  325. void RefreshCustomView(HWND hwnd, LPCTSTR szPath)
  326. {
  327. HANDLE hFile = INVALID_HANDLE_VALUE;
  328. TCHAR szSearchSpec[MAX_PATH];
  329. TCHAR szFileName[MAX_PATH];
  330. HWND hwndLV;
  331. WIN32_FIND_DATA findData;
  332. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  333. ListView_DeleteAllItems(hwndLV);
  334. #ifdef UNICODE
  335. wnsprintfW(szSearchSpec, MAX_PATH, L"%ws\\*.*", szPath);
  336. #else
  337. wnsprintfA(szSearchSpec, MAX_PATH, "%s\\*.*", szPath);
  338. #endif
  339. hFile = FindFirstFile(szSearchSpec, &findData);
  340. if (hFile == INVALID_HANDLE_VALUE) {
  341. goto Exit;
  342. }
  343. if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
  344. (lstrcmp(findData.cFileName, TEXT("."))) &&
  345. (lstrcmp(findData.cFileName, TEXT("..")))) {
  346. #ifdef UNICODE
  347. wnsprintfW(szFileName, MAX_PATH, L"%ws\\%ws", szPath, findData.cFileName);
  348. #else
  349. wnsprintfA(szFileName, MAX_PATH, "%s\\%s", szPath, findData.cFileName);
  350. #endif
  351. InsertCustomLogEntry(szFileName, hwndLV);
  352. }
  353. while (FindNextFile(hFile, &findData)) {
  354. if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
  355. (lstrcmp(findData.cFileName, TEXT("."))) &&
  356. (lstrcmp(findData.cFileName, TEXT("..")))) {
  357. #ifdef UNICODE
  358. wnsprintfW(szFileName, MAX_PATH, L"%ws\\%ws", szPath, findData.cFileName);
  359. #else
  360. wnsprintfA(szFileName, MAX_PATH, "%s\\%s", szPath, findData.cFileName);
  361. #endif
  362. InsertCustomLogEntry(szFileName, hwndLV);
  363. }
  364. }
  365. Exit:
  366. return;
  367. }
  368. BOOL InsertCustomLogEntry(LPTSTR szFilePath, HWND hwndLV)
  369. {
  370. BOOL bRet = TRUE;
  371. HANDLE hFile = INVALID_HANDLE_VALUE;
  372. TCHAR szSearchSpec[MAX_PATH];
  373. WIN32_FIND_DATA findData;
  374. #ifdef UNICODE
  375. wnsprintfW(szSearchSpec, MAX_PATH, L"%ws\\*.htm" szFilePath);
  376. #else
  377. wnsprintfA(szSearchSpec, MAX_PATH, "%s\\*.htm", szFilePath);
  378. #endif
  379. hFile = FindFirstFile(szSearchSpec, &findData);
  380. if (hFile == INVALID_HANDLE_VALUE) {
  381. bRet = FALSE;
  382. goto Exit;
  383. }
  384. if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
  385. AddLogItemCustom(hwndLV, &findData);
  386. }
  387. while (FindNextFile(hFile, &findData)) {
  388. if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  389. continue;
  390. }
  391. AddLogItemCustom(hwndLV, &findData);
  392. }
  393. Exit:
  394. if (hFile != INVALID_HANDLE_VALUE) {
  395. FindClose(hFile);
  396. }
  397. return bRet;
  398. }
  399. void AddLogItemCustom(HWND hwndLV, WIN32_FIND_DATA *pfindData)
  400. {
  401. LVITEM lvitem;
  402. LPTSTR szNameTag = NULL;
  403. LPTSTR szExt = NULL;
  404. static TCHAR szBuf[MAX_DATE_LEN];
  405. static TCHAR szExeBuf[MAX_PATH];
  406. memset(&lvitem, 0, sizeof(lvitem));
  407. lvitem.mask = LVIF_TEXT;
  408. FormatDateBuffer(&pfindData->ftLastAccessTime, szBuf);
  409. lstrcpy(szExeBuf, pfindData->cFileName + lstrlen(FILESPEC_SEARCH_PATTERN));
  410. szNameTag = StrStr(szExeBuf, TEXT("!name="));
  411. if (!szNameTag) {
  412. // Fatal!
  413. return;
  414. }
  415. *szNameTag++ = TEXT('\0');
  416. szNameTag += lstrlen(TEXT("name="));
  417. szExt = StrStrI(szNameTag, TEXT(".htm"));
  418. if (szExt) {
  419. *szExt = TEXT('\0');
  420. }
  421. lvitem.iItem = 0;
  422. lvitem.iSubItem = 0;
  423. lvitem.pszText = szExeBuf;
  424. lvitem.iItem = ListView_InsertItem(hwndLV, &lvitem);
  425. lvitem.iSubItem = 1;
  426. lvitem.pszText = szNameTag;
  427. ListView_SetItem(hwndLV, &lvitem);
  428. lvitem.iSubItem = 2;
  429. lvitem.pszText = szBuf;
  430. ListView_SetItem(hwndLV, &lvitem);
  431. }
  432. void RefreshWininetView(HWND hwnd)
  433. {
  434. HANDLE hUrlCacheEnum;
  435. DWORD dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  436. LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo = NULL;
  437. HWND hwndLV;
  438. static char pBuffer[MAX_CACHE_ENTRY_INFO_SIZE];
  439. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  440. ListView_DeleteAllItems(hwndLV);
  441. pCacheEntryInfo = (LPINTERNET_CACHE_ENTRY_INFO)pBuffer;
  442. hUrlCacheEnum = FindFirstUrlCacheEntry(URL_SEARCH_PATTERN, pCacheEntryInfo,
  443. &dwBufferSize);
  444. if (hUrlCacheEnum != NULL) {
  445. if (pCacheEntryInfo->lpszSourceUrlName != NULL) {
  446. if (StrStrI(pCacheEntryInfo->lpszSourceUrlName, URL_SEARCH_PATTERN)) {
  447. AddLogItem(hwndLV, pCacheEntryInfo);
  448. }
  449. }
  450. dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  451. while (FindNextUrlCacheEntry(hUrlCacheEnum, pCacheEntryInfo,
  452. &dwBufferSize)) {
  453. if (pCacheEntryInfo->lpszSourceUrlName != NULL) {
  454. if (StrStrI(pCacheEntryInfo->lpszSourceUrlName, URL_SEARCH_PATTERN)) {
  455. AddLogItem(hwndLV, pCacheEntryInfo);
  456. }
  457. }
  458. dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  459. }
  460. }
  461. }
  462. void AddLogItem(HWND hwndLV, LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo)
  463. {
  464. LVITEM lvitem;
  465. LPSTR szNameTag = NULL;
  466. static char szBuf[MAX_DATE_LEN];
  467. static char szExeBuf[MAX_PATH];
  468. memset(&lvitem, 0, sizeof(lvitem));
  469. lvitem.mask = LVIF_TEXT;
  470. FormatDateBuffer(&pCacheEntryInfo->LastModifiedTime, szBuf);
  471. lstrcpy(szExeBuf, pCacheEntryInfo->lpszSourceUrlName + lstrlen(URL_SEARCH_PATTERN));
  472. szNameTag = StrStr(szExeBuf, "!name=");
  473. if (!szNameTag) {
  474. // Fatal!
  475. return;
  476. }
  477. *szNameTag++ = TEXT('\0');
  478. szNameTag += lstrlen("name=");
  479. lvitem.iItem = 0;
  480. lvitem.iSubItem = 0;
  481. lvitem.pszText = szExeBuf;
  482. lvitem.iItem = ListView_InsertItem(hwndLV, &lvitem);
  483. lvitem.iSubItem = 1;
  484. lvitem.pszText = szBuf;
  485. ListView_SetItem(hwndLV, &lvitem);
  486. lvitem.iSubItem = 2;
  487. lvitem.pszText = szNameTag;
  488. ListView_SetItem(hwndLV, &lvitem);
  489. }
  490. void FormatDateBuffer(FILETIME *pftLastMod, LPSTR szBuf)
  491. {
  492. SYSTEMTIME systime;
  493. FILETIME ftLocalLastMod;
  494. char szBufDate[MAX_DATE_LEN];
  495. char szBufTime[MAX_DATE_LEN];
  496. FileTimeToLocalFileTime(pftLastMod, &ftLocalLastMod);
  497. FileTimeToSystemTime(&ftLocalLastMod, &systime);
  498. if (!GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, &systime, NULL, szBufDate, MAX_DATE_LEN)) {
  499. return;
  500. }
  501. if (!GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, &systime, NULL, szBufTime, MAX_DATE_LEN)) {
  502. return;
  503. }
  504. wnsprintf(szBuf, MAX_DATE_LEN, "%s @ %s", szBufDate, szBufTime);
  505. }
  506. void InitListView(HWND hwndLV)
  507. {
  508. LVCOLUMN lvcol;
  509. TCHAR szText[MAX_RES_TEXT_LEN];
  510. memset(&lvcol, 0, sizeof(LVCOLUMN));
  511. lvcol.mask = LVCF_TEXT | LVCF_WIDTH;
  512. // Application
  513. lvcol.cx = 300;
  514. if (!LoadString(g_hInst, ID_FUSLOGVW_HEADER_TEXT_APPLICATION, szText, MAX_RES_TEXT_LEN)) {
  515. return;
  516. }
  517. lvcol.pszText = szText;
  518. ListView_InsertColumn(hwndLV, 0, &lvcol);
  519. // Date/Time
  520. if (!LoadString(g_hInst, ID_FUSLOGVW_HEADER_TEXT_DATE_TIME, szText, MAX_RES_TEXT_LEN)) {
  521. return;
  522. }
  523. lvcol.pszText = szText;
  524. lvcol.cx = 154;
  525. ListView_InsertColumn(hwndLV, 1, &lvcol);
  526. // Description
  527. if (!LoadString(g_hInst, ID_FUSLOGVW_HEADER_TEXT_DESCRIPTION, szText, MAX_RES_TEXT_LEN)) {
  528. return;
  529. }
  530. lvcol.cx = 100;
  531. lvcol.pszText = szText;
  532. ListView_InsertColumn(hwndLV, 2, &lvcol);
  533. }
  534. void InitCustomLogPaths()
  535. {
  536. LONG lResult;
  537. HKEY hkey;
  538. // BOOL bRet;
  539. DWORD dwSize;
  540. DWORD dwAttr;
  541. DWORD dwType;
  542. TCHAR szCorSystemDir[MAX_PATH];
  543. // TCHAR szXSPAppCacheDir[MAX_PATH];
  544. g_szCustomLogPath[0] = L'\0';
  545. g_szXSPLogPath[0] = L'\0';
  546. // Custom log path
  547. lResult = RegOpenKeyEx(HKEY_CURRENT_USER, REG_KEY_FUSION_SETTINGS, 0, KEY_READ, &hkey);
  548. if (lResult == ERROR_SUCCESS) {
  549. dwSize = MAX_PATH;
  550. lResult = RegQueryValueEx(hkey, REG_VAL_FUSION_LOG_PATH, NULL,
  551. &dwType, (LPBYTE)g_szCustomLogPath, &dwSize);
  552. if (lResult == ERROR_SUCCESS) {
  553. PathRemoveBackslash(g_szCustomLogPath);
  554. }
  555. RegCloseKey(hkey);
  556. dwAttr = GetFileAttributes(g_szCustomLogPath);
  557. if (dwAttr == -1 || !(dwAttr & FILE_ATTRIBUTE_DIRECTORY)) {
  558. g_szCustomLogPath[0] = L'\0';
  559. }
  560. }
  561. // XSP log path
  562. if (!GetCorSystemDirectory(szCorSystemDir)) {
  563. goto Exit;
  564. }
  565. dwSize = lstrlen(szCorSystemDir);
  566. if (dwSize) {
  567. if (szCorSystemDir[dwSize - 1] == TEXT('\\')) {
  568. szCorSystemDir[dwSize - 1] = TEXT('\0');
  569. }
  570. }
  571. #ifdef UNICODE
  572. wnsprintfW(g_szXSPLogPath, MAX_PATH, L"%ws\\%ws\\%ws", szCorSystemDir,
  573. XSP_APP_CACHE_DIR, XSP_FUSION_LOG_DIR);
  574. #else
  575. wnsprintfA(g_szXSPLogPath, MAX_PATH, "%s\\%s\\%s", szCorSystemDir,
  576. XSP_APP_CACHE_DIR, XSP_FUSION_LOG_DIR);
  577. #endif
  578. dwAttr = GetFileAttributes(g_szXSPLogPath);
  579. if (dwAttr == -1) {
  580. g_szXSPLogPath[0] = TEXT('\0');
  581. }
  582. Exit:
  583. return;
  584. }
  585. void InitText(HWND hwnd)
  586. {
  587. TCHAR szText[MAX_RES_TEXT_LEN];
  588. szText[0] = L'\0';
  589. if (LoadString(g_hInst, ID_FUSLOGVW_DIALOG_TITLE, szText, MAX_RES_TEXT_LEN)) {
  590. SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM) szText);
  591. }
  592. if (LoadString(g_hInst, ID_FUSLOGVW_BUTTON_VIEW_LOG, szText, MAX_RES_TEXT_LEN)) {
  593. SetDlgItemText(hwnd, IDC_CB_VIEWLOG, szText);
  594. }
  595. if (LoadString(g_hInst, ID_FUSLOGVW_BUTTON_DELETE_ENTRY, szText, MAX_RES_TEXT_LEN)) {
  596. SetDlgItemText(hwnd, IDC_CB_DELETE, szText);
  597. }
  598. if (LoadString(g_hInst, ID_FUSLOGVW_BUTTON_DELETE_ALL, szText, MAX_RES_TEXT_LEN)) {
  599. SetDlgItemText(hwnd, IDC_CB_DELETE_ALL, szText);
  600. }
  601. if (LoadString(g_hInst, ID_FUSLOGVW_BUTTON_REFRESH, szText, MAX_RES_TEXT_LEN)) {
  602. SetDlgItemText(hwnd, IDC_CB_REFRESH, szText);
  603. }
  604. if (LoadString(g_hInst, ID_FUSLOGVW_BUTTON_EXIT, szText, MAX_RES_TEXT_LEN)) {
  605. SetDlgItemText(hwnd, IDCANCEL, szText);
  606. }
  607. if (LoadString(g_hInst, ID_FUSLOGVW_RADIO_LOCATION_DEFAULT, szText, MAX_RES_TEXT_LEN)) {
  608. SetDlgItemText(hwnd, IDC_RADIO_DEFAULT, szText);
  609. }
  610. if (LoadString(g_hInst, ID_FUSLOGVW_RADIO_LOCATION_DEFAULT, szText, MAX_RES_TEXT_LEN)) {
  611. SetDlgItemText(hwnd, IDC_RADIO_DEFAULT, szText);
  612. }
  613. /*
  614. if (LoadString(g_hInst, ID_FUSLOGVW_RADIO_LOCATION_ASP_NET, szText, MAX_RES_TEXT_LEN)) {
  615. SetDlgItemText(hwnd, IDC_RADIO_XSP, szText);
  616. }
  617. */
  618. if (LoadString(g_hInst, ID_FUSLOGVW_RADIO_LOCATION_CUSTOM, szText, MAX_RES_TEXT_LEN)) {
  619. SetDlgItemText(hwnd, IDC_RADIO_CUSTOM, szText);
  620. }
  621. if (LoadString(g_hInst, ID_FUSLOGVW_CHECKBOX_ENABLELOG, szText, MAX_RES_TEXT_LEN)) {
  622. SetDlgItemText(hwnd, IDC_CB_ENABLELOG, szText);
  623. }
  624. }
  625. BOOL GetCorSystemDirectory(LPTSTR szCorSystemDir)
  626. {
  627. BOOL fRet = FALSE;
  628. DWORD ccPath = MAX_PATH;
  629. WCHAR szDir[MAX_PATH];
  630. PFNGETCORSYSTEMDIRECTORY pfnGetCorSystemDirectory = NULL;
  631. HMODULE hEEShim = LoadLibrary(TEXT("mscoree.dll"));
  632. if (!hEEShim)
  633. goto exit;
  634. pfnGetCorSystemDirectory = (PFNGETCORSYSTEMDIRECTORY)
  635. GetProcAddress(hEEShim, "GetCORSystemDirectory");
  636. if (!pfnGetCorSystemDirectory
  637. || FAILED(pfnGetCorSystemDirectory(szDir, MAX_PATH, &ccPath)))
  638. goto exit;
  639. #ifdef UNICODE
  640. lstrcpyW(szCorSystemDir, szDir);
  641. #else
  642. if (!WideCharToMultiByte(CP_ACP, 0, szDir, -1, szCorSystemDir, MAX_PATH * sizeof(TCHAR),
  643. NULL, NULL)) {
  644. goto exit;
  645. }
  646. #endif
  647. fRet = TRUE;
  648. exit:
  649. if (!fRet)
  650. {
  651. FreeLibrary(hEEShim);
  652. }
  653. return fRet;
  654. }
  655. int
  656. _stdcall
  657. ModuleEntry(void)
  658. {
  659. int i;
  660. STARTUPINFO si;
  661. LPTSTR pszCmdLine = GetCommandLine();
  662. si.dwFlags = 0;
  663. GetStartupInfoA(&si);
  664. i = WinMain(GetModuleHandle(NULL),
  665. NULL,
  666. pszCmdLine,
  667. (si.dwFlags & STARTF_USESHOWWINDOW) ? si.wShowWindow : SW_SHOWDEFAULT);
  668. ExitProcess(i);
  669. return i; // We never come here
  670. }