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.

112 lines
2.2 KiB

  1. #include "logfile.h"
  2. /*++
  3. Routine Description:
  4. This function will open a temporary logfile in the %temp% directory
  5. Return:
  6. BOOL TRUE if this completed successfully.
  7. --*/
  8. BOOL OpenLog(VOID)
  9. {
  10. WCHAR szTempPath[MAX_PATH];
  11. WCHAR sztimeClock[128];
  12. WCHAR sztimeDate[128];
  13. ExpandEnvironmentStrings(L"%temp%", szTempPath, MAX_PATH);
  14. //
  15. // g_fpTempFile should be global to main program
  16. wsprintf(g_szTmpFilename, L"%s\\LsviewTemp.log", szTempPath);
  17. g_fpTempFile = _wfopen(g_szTmpFilename,L"w+");
  18. if( g_fpTempFile==NULL )
  19. return FALSE;
  20. _wstrtime(sztimeClock);
  21. _wstrdate(sztimeDate);
  22. wsprintf(szTempPath, L"\n**********Log file generated on: %s %s**********\n", sztimeDate, sztimeClock);
  23. fwprintf(g_fpTempFile, szTempPath);
  24. return TRUE;
  25. }
  26. /*++
  27. Routine Description:
  28. This function will act like printf except it sends its output
  29. to the file opened with OpenLog.
  30. Arguments:
  31. The text and formatting necessary as printf would take.
  32. Return:
  33. NONE.
  34. --*/
  35. VOID LogMsg (IN PWCHAR szMessage,...)
  36. {
  37. va_list vaArgs;
  38. va_start ( vaArgs, szMessage );
  39. vfwprintf ( g_fpTempFile, szMessage, vaArgs );
  40. va_end ( vaArgs );
  41. fflush ( g_fpTempFile );
  42. }
  43. /*++
  44. Routine Description:
  45. This function will move the temporary logfile to the path specified in parameter szFileName
  46. Arguments:
  47. szFileName : Filename to move the temp logfile to
  48. Return:
  49. BOOL TRUE if this completed successfully.
  50. --*/
  51. BOOL LogDiagnosisFile( LPTSTR szFileName )
  52. {
  53. BOOL bMoveSuccess = FALSE;
  54. if( szFileName == NULL )
  55. return FALSE;
  56. CloseLog();
  57. bMoveSuccess = MoveFileEx( g_szTmpFilename, szFileName,
  58. MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH );
  59. if( bMoveSuccess == FALSE )
  60. {
  61. WCHAR szTmp[MAX_PATH];
  62. wsprintf(szTmp, L"Failed to move temp diagnosis file %s to %s. Reason %d", g_szTmpFilename, szFileName, GetLastError());
  63. OutputDebugString(szTmp);
  64. }
  65. OpenLog();
  66. return bMoveSuccess;
  67. }
  68. /*++
  69. Routine Description:
  70. This function will close the logfile.
  71. Arguments:
  72. NONE
  73. Return:
  74. NONE.
  75. --*/
  76. VOID CloseLog(VOID)
  77. {
  78. fclose( g_fpTempFile );
  79. g_fpTempFile = NULL;
  80. }