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.

204 lines
7.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: cdllogvw.c
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 25 Mar 97 t-alans (Alan Shi) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <windows.h>
  18. #include <shlwapi.h>
  19. #include <shellapi.h>
  20. #include <wininet.h>
  21. #include "cdlids.h"
  22. #include "wininet.h"
  23. #define URL_SEARCH_PATTERN "?CodeDownloadErrorLog"
  24. #define DELIMITER_CHAR '!'
  25. #define MAX_CACHE_ENTRY_INFO_SIZE 2048
  26. LRESULT CALLBACK DlgProc( HWND, UINT, WPARAM, LPARAM );
  27. void ViewLogEntry( HWND hwnd );
  28. void RefreshLogView( HWND hwnd );
  29. void DeleteLogEntry( HWND hwnd );
  30. HINSTANCE hInst;
  31. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  32. PSTR szCmdLine, int iCmdShow )
  33. {
  34. hInst = hInstance;
  35. DialogBox( hInstance, MAKEINTRESOURCE(IDD_CDLLOGVIEW), NULL, DlgProc );
  36. return( 0 );
  37. }
  38. LRESULT CALLBACK DlgProc( HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam )
  39. {
  40. switch( iMsg ) {
  41. case WM_INITDIALOG:
  42. RefreshLogView( hwnd );
  43. return TRUE;
  44. case WM_COMMAND:
  45. switch( LOWORD( wParam ) ) {
  46. case IDCANCEL:
  47. EndDialog( hwnd, 0 );
  48. break;
  49. case IDC_CB_VIEWLOG:
  50. ViewLogEntry( hwnd );
  51. break;
  52. case IDC_CB_REFRESH:
  53. RefreshLogView( hwnd );
  54. break;
  55. case IDC_CB_DELETE:
  56. DeleteLogEntry( hwnd );
  57. break;
  58. case IDC_LB_LOGMESSAGES:
  59. switch( HIWORD( wParam ) ) {
  60. case LBN_DBLCLK:
  61. ViewLogEntry( hwnd );
  62. break;
  63. }
  64. }
  65. return( TRUE );
  66. }
  67. return( FALSE );
  68. }
  69. void DeleteLogEntry( HWND hwnd )
  70. {
  71. static char szUrlBuffer[INTERNET_MAX_URL_LENGTH];
  72. char szUrl[INTERNET_MAX_URL_LENGTH];
  73. LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo = NULL;
  74. DWORD dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  75. static char pBuffer[MAX_CACHE_ENTRY_INFO_SIZE];
  76. int iIndex = 0;
  77. int iLength = 0;
  78. iIndex = SendDlgItemMessage( hwnd, IDC_LB_LOGMESSAGES,
  79. LB_GETCURSEL, 0, 0 );
  80. iLength = SendDlgItemMessage( hwnd, IDC_LB_LOGMESSAGES,
  81. LB_GETTEXTLEN, iIndex, 0 );
  82. SendDlgItemMessage( hwnd, IDC_LB_LOGMESSAGES,
  83. LB_GETTEXT, iIndex, (LPARAM)szUrl );
  84. pCacheEntryInfo = (LPINTERNET_CACHE_ENTRY_INFO)pBuffer;
  85. dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  86. wnsprintf( szUrlBuffer, sizeof(szUrlBuffer)-1, "%s%c%s", URL_SEARCH_PATTERN, DELIMITER_CHAR, szUrl );
  87. if( DeleteUrlCacheEntry( szUrlBuffer ) ) {
  88. RefreshLogView( hwnd );
  89. } else {
  90. MessageBox( hwnd, "Error: Unable to delete cache file!",
  91. "Log View Error", MB_OK | MB_ICONERROR );
  92. }
  93. }
  94. void ViewLogEntry( HWND hwnd )
  95. {
  96. int iIndex = 0;
  97. int iLength = 0;
  98. static char pBuffer[MAX_CACHE_ENTRY_INFO_SIZE];
  99. DWORD dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  100. LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo = NULL;
  101. char szUrl[INTERNET_MAX_URL_LENGTH];
  102. static char szUrlBuffer[INTERNET_MAX_URL_LENGTH];
  103. iIndex = SendDlgItemMessage( hwnd, IDC_LB_LOGMESSAGES,
  104. LB_GETCURSEL, 0, 0 );
  105. iLength = SendDlgItemMessage( hwnd, IDC_LB_LOGMESSAGES,
  106. LB_GETTEXTLEN, iIndex, 0 );
  107. SendDlgItemMessage( hwnd, IDC_LB_LOGMESSAGES,
  108. LB_GETTEXT, iIndex, (LPARAM)szUrl );
  109. pCacheEntryInfo = (LPINTERNET_CACHE_ENTRY_INFO)pBuffer;
  110. dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  111. wnsprintf( szUrlBuffer, sizeof(szUrlBuffer)-1, "%s%c%s", URL_SEARCH_PATTERN, DELIMITER_CHAR, szUrl );
  112. if( GetUrlCacheEntryInfo( szUrlBuffer, pCacheEntryInfo, &dwBufferSize ) ) {
  113. if( pCacheEntryInfo->lpszLocalFileName != NULL ) {
  114. if( ShellExecute( NULL, "open", pCacheEntryInfo->lpszLocalFileName,
  115. NULL, NULL, SW_SHOWNORMAL ) <= (HINSTANCE)32 ) {
  116. // ShellExecute returns <= 32 if error occured
  117. MessageBox( hwnd, "Error: Unable to open cache file!",
  118. "Log View Error", MB_OK | MB_ICONERROR );
  119. }
  120. } else {
  121. MessageBox( hwnd, "Error: No file name available!",
  122. "Log View Error", MB_OK | MB_ICONERROR );
  123. }
  124. }
  125. }
  126. void RefreshLogView( HWND hwnd )
  127. {
  128. HANDLE hUrlCacheEnum;
  129. DWORD dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  130. LPINTERNET_CACHE_ENTRY_INFO pCacheEntryInfo = NULL;
  131. static char pBuffer[MAX_CACHE_ENTRY_INFO_SIZE];
  132. char *szPtr = NULL;
  133. SendDlgItemMessage( hwnd, IDC_LB_LOGMESSAGES, LB_RESETCONTENT, 0, 0);
  134. pCacheEntryInfo = (LPINTERNET_CACHE_ENTRY_INFO)pBuffer;
  135. hUrlCacheEnum = FindFirstUrlCacheEntry( URL_SEARCH_PATTERN,
  136. pCacheEntryInfo,
  137. &dwBufferSize );
  138. if( hUrlCacheEnum != NULL ) {
  139. if( pCacheEntryInfo->lpszSourceUrlName != NULL ) {
  140. if( StrStrI( pCacheEntryInfo->lpszSourceUrlName, URL_SEARCH_PATTERN ) ) {
  141. SendDlgItemMessage( hwnd, IDC_LB_LOGMESSAGES, LB_ADDSTRING, 0,
  142. (LPARAM)pCacheEntryInfo->lpszSourceUrlName );
  143. }
  144. }
  145. dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  146. while( FindNextUrlCacheEntry( hUrlCacheEnum, pCacheEntryInfo,
  147. &dwBufferSize ) ) {
  148. if( pCacheEntryInfo->lpszSourceUrlName != NULL ) {
  149. if( StrStrI( pCacheEntryInfo->lpszSourceUrlName, URL_SEARCH_PATTERN ) ) {
  150. szPtr = pCacheEntryInfo->lpszSourceUrlName;
  151. while( *szPtr != '\0' && *szPtr != DELIMITER_CHAR ) {
  152. szPtr++;
  153. }
  154. szPtr++;
  155. if( szPtr != NULL ) {
  156. SendDlgItemMessage( hwnd, IDC_LB_LOGMESSAGES, LB_ADDSTRING, 0,
  157. (LPARAM)szPtr);
  158. }
  159. }
  160. }
  161. dwBufferSize = MAX_CACHE_ENTRY_INFO_SIZE;
  162. }
  163. }
  164. }
  165. int
  166. _stdcall
  167. ModuleEntry(void)
  168. {
  169. int i;
  170. STARTUPINFO si;
  171. LPTSTR pszCmdLine = GetCommandLine();
  172. si.dwFlags = 0;
  173. GetStartupInfoA(&si);
  174. i = WinMain(GetModuleHandle(NULL),
  175. NULL,
  176. pszCmdLine,
  177. (si.dwFlags & STARTF_USESHOWWINDOW) ? si.wShowWindow : SW_SHOWDEFAULT);
  178. ExitProcess(i);
  179. return i; // We never come here
  180. }