Source code of Windows XP (NT5)
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.

156 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. Support
  5. Abstract:
  6. Miscelaneous support functions for the Replace utility.
  7. All functions that are not involved directly in the adding\replacing
  8. of files go here.
  9. Author:
  10. Ramon Juan San Andres (ramonsa) 02-May-1991
  11. Revision History:
  12. --*/
  13. #include "ulib.hxx"
  14. #include "system.hxx"
  15. #include "replace.hxx"
  16. VOID
  17. REPLACE::DisplayMessageAndExit (
  18. IN MSGID MsgId,
  19. IN PCWSTRING String,
  20. IN ULONG ExitCode
  21. )
  22. /*++
  23. Routine Description:
  24. Displays a message and exits the program with the supplied error code.
  25. We support a maximum of one string parameter for the message.
  26. Arguments:
  27. MsgId - Supplies the Id of the message to display.
  28. String - Supplies a string parameter for the message.
  29. ExitCode - Supplies the exit code with which to exit.
  30. Return Value:
  31. None.
  32. Notes:
  33. --*/
  34. {
  35. PATH Path;
  36. if ( MsgId != 0 ) {
  37. if ( String ) {
  38. DisplayMessage( MsgId, ERROR_MESSAGE, "%W", String );
  39. } else {
  40. DisplayMessage( MsgId, ERROR_MESSAGE, "" );
  41. }
  42. }
  43. //
  44. // Display the number of files added/ replaced.
  45. //
  46. if ( _AddSwitch ) {
  47. if ( _FilesAdded == 0 ) {
  48. DisplayMessage( REPLACE_MESSAGE_NO_FILES_ADDED );
  49. } else {
  50. DisplayMessage( REPLACE_MESSAGE_FILES_ADDED, NORMAL_MESSAGE, "%d", _FilesAdded );
  51. }
  52. } else {
  53. if ( _FilesReplaced == 0 ) {
  54. DisplayMessage( REPLACE_MESSAGE_NO_FILES_REPLACED );
  55. } else {
  56. DisplayMessage( REPLACE_MESSAGE_FILES_REPLACED, NORMAL_MESSAGE, "%d", _FilesReplaced );
  57. }
  58. }
  59. exit( (int)ExitCode );
  60. }
  61. PWSTRING
  62. REPLACE::QueryMessageString (
  63. IN MSGID MsgId
  64. )
  65. /*++
  66. Routine Description:
  67. Obtains a string object initialized to the contents of some message
  68. Arguments:
  69. MsgId - Supplies ID of the message
  70. Return Value:
  71. PWSTRING - Pointer to initialized string object
  72. Notes:
  73. --*/
  74. {
  75. PWSTRING String;
  76. if ( ((String = NEW DSTRING) == NULL ) ||
  77. !(SYSTEM::QueryResourceString( String, MsgId, "" )) ) {
  78. DisplayMessageAndExit( REPLACE_ERROR_NO_MEMORY, NULL, EXIT_NO_MEMORY );
  79. }
  80. return String;
  81. }
  82. VOID
  83. REPLACE::ExitWithError(
  84. IN DWORD ErrorCode
  85. )
  86. /*++
  87. Routine Description:
  88. Displays a message based on a WIN32 error code, and exits.
  89. Arguments:
  90. ErrorCode - Supplies Windows error code
  91. Return Value:
  92. none
  93. --*/
  94. {
  95. Fatal( EXIT_PATH_NOT_FOUND, REPLACE_ERROR_EXTENDED, "%d", ErrorCode );
  96. }