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.

211 lines
5.4 KiB

  1. #ifndef WIN32_LEAN_AND_MEAN
  2. #define WIN32_LEAN_AND_MEAN
  3. #endif
  4. #ifndef _WIN32_WINNT
  5. #define _WIN32_WINNT 0x0500
  6. #endif
  7. #include <windows.h>
  8. #include <tchar.h>
  9. #include <assert.h>
  10. #include <time.h>
  11. #include "common.h"
  12. //--------------------------------------------------------------------------
  13. void MyOutputDebug(TCHAR *fmt, ...)
  14. {
  15. #if defined( DBG ) || defined( _DEBUG )
  16. TCHAR szTime[ 10 ];
  17. TCHAR szDate[ 10 ];
  18. ::_tstrtime( szTime );
  19. ::_tstrdate( szDate );
  20. va_list marker;
  21. TCHAR szBuf[1024];
  22. size_t cbSize = ( sizeof( szBuf ) / sizeof( TCHAR ) ) - 1; // one byte for null
  23. _sntprintf( szBuf, cbSize, TEXT( "%s %s: " ), szDate, szTime );
  24. szBuf[ 1023 ] = '\0';
  25. cbSize -= _tcslen( szBuf );
  26. va_start( marker, fmt );
  27. _vsntprintf( szBuf + _tcslen( szBuf ), cbSize, fmt, marker );
  28. szBuf[ 1023 ] = '\0';
  29. cbSize -= _tcslen( szBuf );
  30. va_end( marker );
  31. _tcsncat(szBuf, TEXT("\r\n"), cbSize );
  32. OutputDebugString(szBuf);
  33. #endif
  34. }
  35. //--------------------------------------------------------------------------
  36. void Log( LPCTSTR fmt, ... )
  37. {
  38. TCHAR szTime[ 10 ];
  39. TCHAR szDate[ 10 ];
  40. ::_tstrtime( szTime );
  41. ::_tstrdate( szDate );
  42. va_list marker;
  43. TCHAR szBuf[1024];
  44. size_t cbSize = ( sizeof( szBuf ) / sizeof( TCHAR ) ) - 1; // one byte for null
  45. _sntprintf( szBuf, cbSize, TEXT( "%s %s: " ), szDate, szTime );
  46. szBuf[ 1023 ] = '\0';
  47. cbSize -= _tcslen( szBuf );
  48. va_start( marker, fmt );
  49. _vsntprintf( szBuf + _tcslen( szBuf ), cbSize, fmt, marker );
  50. szBuf[ 1023 ] = '\0';
  51. cbSize -= _tcslen( szBuf );
  52. va_end( marker );
  53. _tcsncat(szBuf, TEXT("\r\n"), cbSize );
  54. #if defined( DBG ) || defined( _DEBUG )
  55. OutputDebugString(szBuf);
  56. #endif
  57. // write the data out to the log file
  58. //char szBufA[ 1024 ];
  59. //WideCharToMultiByte( CP_ACP, 0, szBuf, -1, szBufA, 1024, NULL, NULL );
  60. TCHAR szLogFile[ MAX_PATH + 1 ];
  61. if( 0 == GetWindowsDirectory( szLogFile, MAX_PATH + 1 ) )
  62. return;
  63. _tcsncat( szLogFile, TEXT( "\\iismigration.log" ), MAX_PATH - _tcslen( szLogFile ) );
  64. szLogFile[ MAX_PATH ] = NULL;
  65. HANDLE hFile = CreateFile(
  66. szLogFile, // file name
  67. GENERIC_WRITE, // open for writing
  68. 0, // do not share
  69. NULL, // no security
  70. OPEN_ALWAYS, // open and create if not exists
  71. FILE_ATTRIBUTE_NORMAL, // normal file
  72. NULL); // no attr. template
  73. if( hFile == INVALID_HANDLE_VALUE )
  74. {
  75. assert( false );
  76. return;
  77. }
  78. //
  79. // move the file pointer to the end so that we can append
  80. //
  81. SetFilePointer( hFile, 0, NULL, FILE_END );
  82. DWORD dwNumberOfBytesWritten;
  83. BOOL bOK = WriteFile(
  84. hFile,
  85. szBuf,
  86. (UINT) _tcslen( szBuf ) * sizeof( TCHAR ), // number of bytes to write
  87. &dwNumberOfBytesWritten, // number of bytes written
  88. NULL); // overlapped buffer
  89. assert( bOK );
  90. FlushFileBuffers ( hFile );
  91. CloseHandle( hFile );
  92. }
  93. //-----------------------------------------------------------------------------------------
  94. void ClearLog()
  95. {
  96. /*
  97. TCHAR szLogFile[ MAX_PATH ];
  98. if( 0 == GetWindowsDirectory( szLogFile, MAX_PATH ))
  99. {
  100. return;
  101. }
  102. _tcscat( szLogFile, TEXT( "\\" ) );
  103. _tcscat( szLogFile, UDDI_SETUP_LOG );
  104. ::DeleteFile( szLogFile );
  105. */
  106. Log( TEXT( "*******************************************************" ) );
  107. Log( TEXT( "********** Starting a new log *************************" ) );
  108. Log( TEXT( "*******************************************************" ) );
  109. }
  110. //-----------------------------------------------------------------------------------------
  111. void LogError( PTCHAR szAction, DWORD dwErrorCode )
  112. {
  113. LPVOID lpMsgBuf;
  114. FormatMessage(
  115. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  116. FORMAT_MESSAGE_FROM_SYSTEM |
  117. FORMAT_MESSAGE_IGNORE_INSERTS,
  118. NULL,
  119. dwErrorCode,
  120. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  121. (LPTSTR) &lpMsgBuf,
  122. 0,
  123. NULL
  124. );
  125. Log( TEXT( "----------------------------------------------------------" ) );
  126. Log( TEXT( "An error occurred during installation. Details follow:" ) );
  127. Log( TEXT( "Action: %s" ), szAction );
  128. Log( TEXT( "Message: %s" ), lpMsgBuf );
  129. Log( TEXT( "----------------------------------------------------------" ) );
  130. LocalFree( lpMsgBuf );
  131. }
  132. //--------------------------------------------------------------------------
  133. /*
  134. void Enter( PTCHAR szMsg )
  135. {
  136. #ifdef _DEBUG
  137. TCHAR szEnter[ 512 ];
  138. _stprintf( szEnter, TEXT( "Entering %s..." ), szMsg );
  139. Log( szEnter );
  140. #endif
  141. }
  142. */
  143. //--------------------------------------------------------------------------
  144. //
  145. // NOTE: The install path has a trailing backslash
  146. //
  147. bool GetUDDIInstallPath( PTCHAR szInstallPath, DWORD dwLen )
  148. {
  149. HKEY hKey;
  150. //
  151. // get the UDDI installation folder [TARGETDIR] from the registry. The installer squirrels it away there.
  152. //
  153. LONG iRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT( "SOFTWARE\\Microsoft\\UDDI" ), NULL, KEY_READ, &hKey );
  154. if( ERROR_SUCCESS != iRet )
  155. {
  156. LogError( TEXT( "Unable to open the UDDI registry key" ), iRet );
  157. return false;
  158. }
  159. DWORD dwType = REG_SZ;
  160. iRet = RegQueryValueEx(hKey, TEXT( "InstallRoot" ), 0, &dwType, (PBYTE) szInstallPath, &dwLen );
  161. if( ERROR_SUCCESS != iRet )
  162. {
  163. LogError( TEXT( "UDDI registry key did not have the InstallRoot value or buffer size was too small" ), iRet );
  164. return false;
  165. }
  166. return true;
  167. }