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.

247 lines
4.5 KiB

  1. #include "main.h"
  2. #include "resource.h"
  3. // Write log entry()
  4. extern HINSTANCE g_hinst;
  5. extern time_t LogStart;
  6. extern TCHAR LogFileName[MAX_PATH];
  7. extern HANDLE hLogFile;
  8. BOOL bLoggingEnabled = TRUE;
  9. TCHAR szHeader[] = _T("Time,UploadTime,UploadStatus,ProcessTime,ProcessStatus,ThreadExecution,MessageRecieve,MessageSend,ReturnedUrl,ErrorText\r\n");
  10. void
  11. LogMessage(TCHAR *pFormat,...)
  12. {
  13. // Routine to Log Fatal Errors to NT Event Log
  14. TCHAR chMsg[256];
  15. DWORD dwBytesWritten;
  16. va_list pArg;
  17. va_start(pArg, pFormat);
  18. StringCbVPrintf(chMsg, sizeof chMsg,pFormat, pArg);
  19. va_end(pArg);
  20. if (bLoggingEnabled)
  21. {
  22. if (LogStart == 0)
  23. {
  24. // We need to create a new log file
  25. time (&LogStart);
  26. hLogFile = CreateFile (LogFileName,
  27. GENERIC_WRITE,
  28. FILE_SHARE_READ,
  29. NULL,
  30. CREATE_ALWAYS,
  31. FILE_ATTRIBUTE_NORMAL,
  32. NULL);
  33. // write the header
  34. WriteFile(hLogFile,
  35. szHeader,
  36. _tcslen(szHeader) * (DWORD)sizeof TCHAR,
  37. &dwBytesWritten,
  38. NULL);
  39. }
  40. // add a cr\lf combination for file fomrating.
  41. StringCbCat(chMsg, sizeof chMsg,_T("\r\n"));
  42. /* Write to event log. */
  43. if (hLogFile != INVALID_HANDLE_VALUE)
  44. {
  45. WriteFile(hLogFile,
  46. chMsg,
  47. _tcslen(chMsg) * (DWORD)sizeof TCHAR,
  48. &dwBytesWritten,
  49. NULL);
  50. }
  51. }
  52. }
  53. void On_LoggingInit(HWND hwnd)
  54. {
  55. // HWND hComboBox;
  56. // read app reg key for user specified settings.
  57. //GetRegData( );
  58. CheckDlgButton(hwnd, IDC_RADIO1, TRUE);
  59. // Populate the combo box
  60. SetDlgItemText(hwnd, IDC_EDIT1, LogFileName);
  61. }
  62. void On_LogBrowse(HWND hwnd)
  63. {
  64. HWND hParent = hwnd;
  65. // char *WindowTitle;
  66. // determine the language and Load the resource strings.
  67. TCHAR String1[] = _T("Cab Files (*.cab)");
  68. TCHAR String2[] = _T("All Files (*.*)");
  69. static TCHAR szFilterW[400];
  70. // Build the buffer;
  71. TCHAR Pattern1[] = _T("*.cab");
  72. TCHAR Pattern2[] = _T("*.*");
  73. TCHAR * src;
  74. TCHAR *dest;
  75. src = String1;
  76. dest = szFilterW;
  77. while (*src != _T('\0'))
  78. {
  79. *dest = *src;
  80. src ++;
  81. dest ++;
  82. }
  83. src = Pattern1;
  84. *dest = _T('\0');
  85. ++dest;
  86. while (*src != _T('\0'))
  87. {
  88. *dest = *src;
  89. src ++;
  90. dest ++;
  91. }
  92. *dest = _T('\0');
  93. ++dest;
  94. src = String2;
  95. while (*src != _T('\0'))
  96. {
  97. *dest = *src;
  98. src ++;
  99. dest ++;
  100. }
  101. src = Pattern2;
  102. *dest = _T('\0');
  103. ++dest;
  104. while (*src != _T('\0'))
  105. {
  106. *dest = *src;
  107. src ++;
  108. dest ++;
  109. }
  110. *dest = _T('\0');
  111. ++dest;
  112. *dest = _T('\0');
  113. BOOL Return = FALSE;
  114. TCHAR szFileNameW [MAX_PATH] = _T("\0");
  115. TCHAR szDefaultPathW[MAX_PATH] = _T("\0");
  116. OPENFILENAME ofn;
  117. GetWindowsDirectory(szDefaultPathW,MAX_PATH);
  118. ofn.lStructSize = sizeof (OPENFILENAME);
  119. ofn.lpstrFilter = szFilterW;
  120. ofn.lpstrInitialDir = szDefaultPathW;
  121. ofn.lpstrFile = szFileNameW;
  122. ofn.hInstance = NULL;
  123. ofn.hwndOwner = hParent;
  124. ofn.lCustData = NULL;
  125. ofn.Flags = 0;
  126. ofn.lpstrDefExt = _T("*.cab");
  127. ofn.lpstrCustomFilter = NULL;
  128. ofn.nMaxFile = MAX_PATH;
  129. ofn.lpstrFileTitle = NULL;
  130. ofn.lpstrTitle = NULL;
  131. ofn.nFileOffset = 0;
  132. ofn.nFileExtension = 0;
  133. ofn.lpfnHook = NULL;
  134. ofn.lpTemplateName = NULL;
  135. if (GetOpenFileName(&ofn))
  136. {
  137. SetDlgItemText(hwnd, IDC_EDIT5, ofn.lpstrFile);
  138. }
  139. }
  140. void OnLoggingOk(HWND hwnd)
  141. {
  142. if (hLogFile != INVALID_HANDLE_VALUE)
  143. {
  144. CloseHandle(hLogFile);
  145. LogStart = 0;
  146. }
  147. GetDlgItemText(hwnd, IDC_EDIT1, LogFileName, MAX_PATH);
  148. if(IsDlgButtonChecked(hwnd, IDC_RADIO3))
  149. bLoggingEnabled = FALSE;
  150. if (hLogFile != INVALID_HANDLE_VALUE)
  151. {
  152. CloseHandle(hLogFile);
  153. hLogFile = INVALID_HANDLE_VALUE;
  154. LogStart = 0;
  155. }
  156. }
  157. LRESULT CALLBACK LoggingDlgBox(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  158. {
  159. switch (iMsg)
  160. {
  161. case WM_INITDIALOG:
  162. {
  163. On_LoggingInit(hwnd);
  164. return TRUE;
  165. }
  166. case WM_COMMAND:
  167. {
  168. switch (LOWORD(wParam))
  169. {
  170. case IDOK:
  171. OnLoggingOk(hwnd);
  172. EndDialog(hwnd, 0);
  173. // Save the current option settings
  174. return TRUE;
  175. case IDCANCEL:
  176. EndDialog(hwnd, 0);
  177. return TRUE;
  178. /// case ID_APPLY:
  179. //OnOptionsOk(hwnd);
  180. // Save the current option settings
  181. // return TRUE;
  182. // case IDC_BROWSE:
  183. // On_Browse(hwnd);
  184. // return TRUE;
  185. }
  186. break;
  187. }
  188. case WM_NOTIFY:
  189. return DefDlgProc(hwnd, iMsg, wParam, lParam);
  190. }
  191. return 0;
  192. }
  193. void On_ToolsLogging(HWND hwnd)
  194. {
  195. DialogBox(g_hinst,MAKEINTRESOURCE(IDD_LOGGING) ,hwnd, (DLGPROC) LoggingDlgBox);
  196. }