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.

327 lines
9.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: fuslogvw.c
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 25 Mar 97 t-alans (Alan Shi) Created
  15. // 12 Jan 00 AlanShi (Alan Shi) Copied from cdllogvw
  16. // 30 May 00 AlanShi (Alan Shi) Modified to show date/time
  17. //
  18. //----------------------------------------------------------------------------
  19. #include <windows.h>
  20. #include <shlwapi.h>
  21. #include <shellapi.h>
  22. #include <wininet.h>
  23. #include <commctrl.h>
  24. #include "cdlids.h"
  25. #include "wininet.h"
  26. #define URL_SEARCH_PATTERN "?FusionBindError!name="
  27. #define DELIMITER_CHAR '!'
  28. #define MAX_CACHE_ENTRY_INFO_SIZE 2048
  29. #define MAX_DATE_LEN 64
  30. #define PAD_DIGITS_FOR_STRING(x) (((x) > 9) ? TEXT("") : TEXT("0"))
  31. const char *ppszMonths[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  32. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  33. LRESULT CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
  34. void ViewLogEntry(HWND hwnd);
  35. void RefreshLogView(HWND hwnd);
  36. void DeleteLogEntry(HWND hwnd);
  37. void DeleteAllLogs(HWND hwnd);
  38. void FormatDateBuffer(FILETIME *pftLastMod, LPSTR szBuf);
  39. void InitListView(HWND hwndLV);
  40. void AddLogItem(HWND hwndLV, LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo);
  41. HINSTANCE hInst;
  42. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  43. PSTR szCmdLine, int iCmdShow)
  44. {
  45. hInst = hInstance;
  46. DialogBox(hInstance, MAKEINTRESOURCE(IDD_CDLLOGVIEW), NULL, DlgProc);
  47. return 0;
  48. }
  49. LRESULT CALLBACK DlgProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  50. {
  51. HWND hwndLV;
  52. LPNMHDR pnmh = NULL;
  53. switch (iMsg) {
  54. case WM_INITDIALOG:
  55. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  56. InitListView(hwndLV);
  57. RefreshLogView(hwnd);
  58. return TRUE;
  59. case WM_COMMAND:
  60. switch (LOWORD(wParam)) {
  61. case IDCANCEL:
  62. EndDialog(hwnd, 0);
  63. break;
  64. case IDC_CB_VIEWLOG:
  65. ViewLogEntry(hwnd);
  66. break;
  67. case IDC_CB_REFRESH:
  68. RefreshLogView(hwnd);
  69. break;
  70. case IDC_CB_DELETE:
  71. DeleteLogEntry(hwnd);
  72. break;
  73. case IDC_CB_DELETE_ALL:
  74. DeleteAllLogs(hwnd);
  75. break;
  76. }
  77. return TRUE;
  78. case WM_NOTIFY:
  79. if (wParam == IDC_LV_LOGMESSAGES) {
  80. pnmh = (LPNMHDR)lParam;
  81. if (pnmh->code == LVN_ITEMACTIVATE) {
  82. // Double click (or otherwise activated)
  83. ViewLogEntry(hwnd);
  84. }
  85. }
  86. return TRUE;
  87. }
  88. return FALSE;
  89. }
  90. void DeleteLogEntry(HWND hwnd)
  91. {
  92. LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo = NULL;
  93. DWORD dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  94. HWND hwndLV;
  95. LRESULT lIndex = 0;
  96. LRESULT lLength = 0;
  97. static char pBuffer[MAX_CACHE_ENTRY_INFO_SIZE];
  98. char szUrl[INTERNET_MAX_URL_LENGTH];
  99. char szBuf[INTERNET_MAX_URL_LENGTH];
  100. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  101. lIndex = ListView_GetSelectionMark(hwndLV);
  102. ListView_GetItemText(hwndLV, lIndex, 0, szBuf, INTERNET_MAX_URL_LENGTH);
  103. lstrcpy(szUrl, URL_SEARCH_PATTERN);
  104. lstrcat(szUrl, szBuf);
  105. pCacheEntryInfo = (LPINTERNET_CACHE_ENTRY_INFO)pBuffer;
  106. dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  107. if (DeleteUrlCacheEntry(szUrl)) {
  108. RefreshLogView(hwnd);
  109. }
  110. else {
  111. MessageBox(hwnd, "Error: Unable to delete cache file!",
  112. "Log View Error", MB_OK | MB_ICONERROR);
  113. }
  114. }
  115. void DeleteAllLogs(HWND hwnd)
  116. {
  117. HWND hwndLV;
  118. LVITEM lvitem;
  119. char szBuf[INTERNET_MAX_URL_LENGTH];
  120. char szUrl[INTERNET_MAX_URL_LENGTH];
  121. int iCount;
  122. int i;
  123. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  124. memset(&lvitem, 0, sizeof(LVITEM));
  125. lvitem.iSubItem = 0;
  126. lvitem.mask = LVIF_TEXT;
  127. lvitem.cchTextMax = INTERNET_MAX_URL_LENGTH;
  128. lvitem.pszText = szBuf;
  129. iCount = ListView_GetItemCount(hwndLV);
  130. for (i = 0; i < iCount; i++) {
  131. szBuf[0] = TEXT('\0');
  132. lvitem.iItem = i;
  133. if (ListView_GetItem(hwndLV, &lvitem)) {
  134. lstrcpy(szUrl, URL_SEARCH_PATTERN);
  135. lstrcat(szUrl, lvitem.pszText);
  136. DeleteUrlCacheEntry(szUrl);
  137. }
  138. }
  139. RefreshLogView(hwnd);
  140. }
  141. void ViewLogEntry(HWND hwnd)
  142. {
  143. LRESULT lIndex = 0;
  144. LRESULT lLength = 0;
  145. HWND hwndLV;
  146. DWORD dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  147. LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo = NULL;
  148. char szUrl[INTERNET_MAX_URL_LENGTH];
  149. char szBuf[INTERNET_MAX_URL_LENGTH];
  150. static char pBuffer[MAX_CACHE_ENTRY_INFO_SIZE];
  151. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  152. lIndex = ListView_GetSelectionMark(hwndLV);
  153. ListView_GetItemText(hwndLV, lIndex, 0, szBuf, INTERNET_MAX_URL_LENGTH);
  154. lstrcpy(szUrl, URL_SEARCH_PATTERN);
  155. lstrcat(szUrl, szBuf);
  156. pCacheEntryInfo = (LPINTERNET_CACHE_ENTRY_INFO)pBuffer;
  157. dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  158. if (GetUrlCacheEntryInfo(szUrl, pCacheEntryInfo, &dwBufferSize)) {
  159. if (pCacheEntryInfo->lpszLocalFileName != NULL) {
  160. if (ShellExecute(NULL, "open", pCacheEntryInfo->lpszLocalFileName,
  161. NULL, NULL, SW_SHOWNORMAL ) <= (HINSTANCE)32) {
  162. // ShellExecute returns <= 32 if error occured
  163. MessageBox(hwnd, "Error: Unable to open cache file!",
  164. "Log View Error", MB_OK | MB_ICONERROR);
  165. }
  166. }
  167. else {
  168. MessageBox(hwnd, "Error: No file name available!",
  169. "Log View Error", MB_OK | MB_ICONERROR);
  170. }
  171. }
  172. }
  173. void RefreshLogView(HWND hwnd)
  174. {
  175. HANDLE hUrlCacheEnum;
  176. DWORD dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  177. LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo = NULL;
  178. HWND hwndLV;
  179. static char pBuffer[MAX_CACHE_ENTRY_INFO_SIZE];
  180. hwndLV = GetDlgItem(hwnd, IDC_LV_LOGMESSAGES);
  181. ListView_DeleteAllItems(hwndLV);
  182. pCacheEntryInfo = (LPINTERNET_CACHE_ENTRY_INFO)pBuffer;
  183. hUrlCacheEnum = FindFirstUrlCacheEntry(URL_SEARCH_PATTERN, pCacheEntryInfo,
  184. &dwBufferSize);
  185. if (hUrlCacheEnum != NULL) {
  186. if (pCacheEntryInfo->lpszSourceUrlName != NULL) {
  187. if (StrStrI(pCacheEntryInfo->lpszSourceUrlName, URL_SEARCH_PATTERN)) {
  188. AddLogItem(hwndLV, pCacheEntryInfo);
  189. }
  190. }
  191. dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  192. while (FindNextUrlCacheEntry(hUrlCacheEnum, pCacheEntryInfo,
  193. &dwBufferSize)) {
  194. if (pCacheEntryInfo->lpszSourceUrlName != NULL) {
  195. if (StrStrI(pCacheEntryInfo->lpszSourceUrlName, URL_SEARCH_PATTERN)) {
  196. AddLogItem(hwndLV, pCacheEntryInfo);
  197. }
  198. }
  199. dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  200. }
  201. }
  202. }
  203. void AddLogItem(HWND hwndLV, LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo)
  204. {
  205. LVITEM lvitem;
  206. static char szBuf[MAX_DATE_LEN];
  207. memset(&lvitem, 0, sizeof(lvitem));
  208. lvitem.mask = LVIF_TEXT;
  209. FormatDateBuffer(&pCacheEntryInfo->LastModifiedTime, szBuf);
  210. lvitem.iItem = 0;
  211. lvitem.iSubItem = 0;
  212. lvitem.pszText = pCacheEntryInfo->lpszSourceUrlName + lstrlen(URL_SEARCH_PATTERN);
  213. lvitem.iItem = ListView_InsertItem(hwndLV, &lvitem);
  214. lvitem.iSubItem = 1;
  215. lvitem.pszText = szBuf;
  216. ListView_SetItem(hwndLV, &lvitem);
  217. }
  218. void FormatDateBuffer(FILETIME *pftLastMod, LPSTR szBuf)
  219. {
  220. SYSTEMTIME systime;
  221. FILETIME ftLocalLastMod;
  222. FileTimeToLocalFileTime(pftLastMod, &ftLocalLastMod);
  223. FileTimeToSystemTime(&ftLocalLastMod, &systime);
  224. wnsprintf(szBuf, MAX_DATE_LEN, "%s%d %s %d @ %s%d:%s%d:%s%d",
  225. PAD_DIGITS_FOR_STRING(systime.wDay), systime.wDay,
  226. ppszMonths[systime.wMonth - 1],
  227. systime.wYear,
  228. PAD_DIGITS_FOR_STRING(systime.wHour), systime.wHour,
  229. PAD_DIGITS_FOR_STRING(systime.wMinute), systime.wMinute,
  230. PAD_DIGITS_FOR_STRING(systime.wSecond), systime.wSecond);
  231. }
  232. void InitListView(HWND hwndLV)
  233. {
  234. LVCOLUMN lvcol;
  235. memset(&lvcol, 0, sizeof(LVCOLUMN));
  236. lvcol.mask = LVCF_TEXT | LVCF_WIDTH;
  237. lvcol.cx = 350;
  238. lvcol.pszText = TEXT("Description");
  239. ListView_InsertColumn(hwndLV, 0, &lvcol);
  240. lvcol.pszText = TEXT("Date/Time");
  241. lvcol.cx = 150;
  242. ListView_InsertColumn(hwndLV, 1, &lvcol);
  243. }
  244. int
  245. _stdcall
  246. ModuleEntry(void)
  247. {
  248. int i;
  249. STARTUPINFO si;
  250. LPTSTR pszCmdLine = GetCommandLine();
  251. si.dwFlags = 0;
  252. GetStartupInfoA(&si);
  253. i = WinMain(GetModuleHandle(NULL),
  254. NULL,
  255. pszCmdLine,
  256. (si.dwFlags & STARTF_USESHOWWINDOW) ? si.wShowWindow : SW_SHOWDEFAULT);
  257. ExitProcess(i);
  258. return i; // We never come here
  259. }