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.

183 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. Support
  5. Abstract:
  6. Miscelaneous support functions for the XCopy directory copy
  7. utility. All functions that are not involved directly in the
  8. copy process 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 "xcopy.hxx"
  16. VOID
  17. XCOPY::DisplayMessageAndExit (
  18. IN MSGID MsgId,
  19. IN PWSTRING 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. //
  36. // XCopy first displays the error message (if any) and then
  37. // displays the number of files copied.
  38. //
  39. if ( MsgId != 0 ) {
  40. if ( String ) {
  41. DisplayMessage( MsgId, ERROR_MESSAGE, "%W", String );
  42. } else {
  43. DisplayMessage( MsgId, ERROR_MESSAGE );
  44. }
  45. }
  46. if ( _DontCopySwitch ) {
  47. DisplayMessage( XCOPY_MESSAGE_FILES, NORMAL_MESSAGE, "%d", _FilesCopied );
  48. } else if ( !_StructureOnlySwitch ) {
  49. DisplayMessage( XCOPY_MESSAGE_FILES_COPIED, NORMAL_MESSAGE, "%d", _FilesCopied );
  50. }
  51. ExitProgram( ExitCode );
  52. }
  53. PWSTRING
  54. XCOPY::QueryMessageString (
  55. IN MSGID MsgId
  56. )
  57. /*++
  58. Routine Description:
  59. Obtains a string object initialized to the contents of some message
  60. Arguments:
  61. MsgId - Supplies ID of the message
  62. Return Value:
  63. PWSTRING - Pointer to initialized string object
  64. Notes:
  65. --*/
  66. {
  67. PWSTRING String;
  68. if ( ((String = NEW DSTRING) == NULL ) ||
  69. !(SYSTEM::QueryResourceString( String, MsgId, "" )) ) {
  70. DisplayMessageAndExit( XCOPY_ERROR_NO_MEMORY, NULL, EXIT_MISC_ERROR );
  71. }
  72. return String;
  73. }
  74. VOID
  75. XCOPY::ExitWithError(
  76. IN DWORD ErrorCode
  77. )
  78. /*++
  79. Routine Description:
  80. Displays a message based on a WIN32 error code, and exits.
  81. Arguments:
  82. ErrorCode - Supplies Windows error code
  83. Return Value:
  84. none
  85. --*/
  86. {
  87. MSGID ReadWriteMsgId = 0;
  88. switch ( ErrorCode ) {
  89. case ERROR_DISK_FULL:
  90. ReadWriteMsgId = XCOPY_ERROR_DISK_FULL;
  91. break;
  92. case ERROR_WRITE_PROTECT:
  93. ReadWriteMsgId = XCOPY_ERROR_WRITE_PROTECT;
  94. break;
  95. case ERROR_ACCESS_DENIED:
  96. ReadWriteMsgId = XCOPY_ERROR_ACCESS_DENIED;
  97. break;
  98. case ERROR_SHARING_VIOLATION:
  99. ReadWriteMsgId = XCOPY_ERROR_SHARING_VIOLATION;
  100. break;
  101. case ERROR_TOO_MANY_OPEN_FILES:
  102. ReadWriteMsgId = XCOPY_ERROR_TOO_MANY_OPEN_FILES;
  103. break;
  104. case ERROR_LOCK_VIOLATION:
  105. ReadWriteMsgId = XCOPY_ERROR_LOCK_VIOLATION;
  106. break;
  107. case ERROR_CANNOT_MAKE:
  108. ReadWriteMsgId = XCOPY_ERROR_CANNOT_MAKE;
  109. break;
  110. default:
  111. break;
  112. }
  113. if ( ReadWriteMsgId != 0 ) {
  114. DisplayMessageAndExit( ReadWriteMsgId, NULL, EXIT_READWRITE_ERROR );
  115. }
  116. Fatal( EXIT_MISC_ERROR, XCOPY_ERROR_EXTENDED, "%d", ErrorCode );
  117. }