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.

206 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. error.c
  5. Abstract:
  6. Error handle module for the INSTALER program
  7. Author:
  8. Steve Wood (stevewo) 09-Aug-1994
  9. Revision History:
  10. --*/
  11. #include "instaler.h"
  12. VOID
  13. TraceDisplay(
  14. const char *FormatString,
  15. ...
  16. )
  17. {
  18. va_list arglist;
  19. va_start( arglist, FormatString );
  20. vprintf( FormatString, arglist );
  21. if (InstalerLogFile) {
  22. vfprintf( InstalerLogFile, FormatString, arglist );
  23. }
  24. va_end( arglist );
  25. fflush( stdout );
  26. return;
  27. }
  28. VOID
  29. CDECL
  30. DeclareError(
  31. UINT ErrorCode,
  32. UINT SupplementalErrorCode,
  33. ...
  34. )
  35. {
  36. va_list arglist;
  37. HMODULE ModuleHandle;
  38. DWORD Flags, Size;
  39. WCHAR MessageBuffer[ 512 ];
  40. va_start( arglist, SupplementalErrorCode );
  41. if ((ErrorCode & 0x0FFF0000) >> 16 == FACILITY_APPLICATION) {
  42. ModuleHandle = InstalerModuleHandle;
  43. Flags = FORMAT_MESSAGE_FROM_HMODULE;
  44. }
  45. else
  46. if ((ErrorCode & 0x0FFF0000) == FACILITY_NT) {
  47. ErrorCode ^= FACILITY_NT;
  48. ModuleHandle = ModuleInfo[ NTDLL_MODULE_INDEX ].ModuleHandle;
  49. Flags = FORMAT_MESSAGE_FROM_HMODULE;
  50. }
  51. else {
  52. ModuleHandle = NULL;
  53. Flags = FORMAT_MESSAGE_FROM_SYSTEM;
  54. }
  55. Size = FormatMessage( Flags,
  56. (LPCVOID)ModuleHandle,
  57. ErrorCode,
  58. 0,
  59. MessageBuffer,
  60. sizeof( MessageBuffer ) / sizeof( WCHAR ),
  61. &arglist
  62. );
  63. va_end( arglist );
  64. if (Size != 0) {
  65. printf( "INSTALER: %ws", MessageBuffer );
  66. }
  67. else {
  68. printf( "INSTALER: Unable to get message text for %08x\n", ErrorCode );
  69. }
  70. if (ModuleHandle == InstalerModuleHandle &&
  71. SupplementalErrorCode != 0 &&
  72. SupplementalErrorCode != ERROR_GEN_FAILURE &&
  73. SupplementalErrorCode != STATUS_UNSUCCESSFUL
  74. ) {
  75. if ((SupplementalErrorCode & 0x0FFF0000) == FACILITY_NT) {
  76. SupplementalErrorCode ^= FACILITY_NT;
  77. ModuleHandle = ModuleInfo[ NTDLL_MODULE_INDEX ].ModuleHandle;
  78. Flags = FORMAT_MESSAGE_FROM_HMODULE;
  79. }
  80. else {
  81. ModuleHandle = NULL;
  82. Flags = FORMAT_MESSAGE_FROM_SYSTEM;
  83. }
  84. Size = FormatMessage( Flags,
  85. (LPCVOID)ModuleHandle,
  86. SupplementalErrorCode,
  87. 0,
  88. MessageBuffer,
  89. sizeof( MessageBuffer ) / sizeof( WCHAR ),
  90. NULL
  91. );
  92. if (Size != 0) {
  93. while (Size != 0 && MessageBuffer[ Size ] <= L' ') {
  94. MessageBuffer[ Size ] = UNICODE_NULL;
  95. Size -= 1;
  96. }
  97. printf( " '%ws'\n", MessageBuffer );
  98. }
  99. else {
  100. printf( "INSTALER: Unable to get message text for %08x\n", SupplementalErrorCode );
  101. }
  102. }
  103. return;
  104. }
  105. WCHAR MessageBoxTitle[ MAX_PATH ];
  106. UINT
  107. CDECL
  108. AskUser(
  109. UINT MessageBoxFlags,
  110. UINT MessageId,
  111. UINT NumberOfArguments,
  112. ...
  113. )
  114. {
  115. va_list arglist;
  116. HMODULE ModuleHandle;
  117. DWORD Flags, Size;
  118. WCHAR MessageBuffer[ 512 ];
  119. PWSTR s;
  120. ULONG Args[ 24 ];
  121. PULONG p;
  122. if (MessageBoxTitle[ 0 ] == UNICODE_NULL) {
  123. Args[ 0 ] = (ULONG)InstallationName;
  124. Args[ 1 ] = 0;
  125. Size = FormatMessageW( FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  126. (LPCVOID)InstalerModuleHandle,
  127. INSTALER_ASKUSER_TITLE,
  128. 0,
  129. MessageBoxTitle,
  130. sizeof( MessageBoxTitle ) / sizeof( WCHAR ),
  131. (va_list *)Args
  132. );
  133. if (Size == 0) {
  134. _snwprintf( MessageBoxTitle,
  135. sizeof( MessageBoxTitle ) / sizeof( WCHAR ),
  136. L"Application Installation Monitor Program - %ws",
  137. InstallationName
  138. );
  139. //
  140. // Terminate the buffer
  141. //
  142. MessageBoxTitle[sizeof(MessageBoxTitle)/sizeof(WCHAR) - 1] = 0;
  143. }
  144. else {
  145. if ((s = wcschr( MessageBoxTitle, L'\r' )) ||
  146. (s = wcschr( MessageBoxTitle, L'\n' ))
  147. ) {
  148. *s = UNICODE_NULL;
  149. }
  150. }
  151. }
  152. va_start( arglist, NumberOfArguments );
  153. p = Args;
  154. while (NumberOfArguments--) {
  155. *p++ = va_arg( arglist, ULONG );
  156. }
  157. *p++ = 0;
  158. va_end( arglist );
  159. Size = FormatMessageW( FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  160. (LPCVOID)InstalerModuleHandle,
  161. MessageId,
  162. 0,
  163. MessageBuffer,
  164. sizeof( MessageBuffer ) / sizeof( WCHAR ),
  165. (va_list *)Args
  166. );
  167. if (Size != 0) {
  168. return MessageBox( NULL,
  169. MessageBuffer,
  170. MessageBoxTitle,
  171. MB_SETFOREGROUND | MessageBoxFlags
  172. );
  173. }
  174. else {
  175. return IDOK;
  176. }
  177. }