summaryrefslogtreecommitdiffstats
path: root/private/utils/replace/support.cxx
blob: 190a45f7c0dafc34765a260ba1caf781582c8e16 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*++

Copyright (c) 1990  Microsoft Corporation

Module Name:

	Support

Abstract:

	Miscelaneous support functions for the Replace utility.

	All functions that are not involved directly in the adding\replacing
	of files go here.

Author:

	Ramon Juan San Andres (ramonsa) 02-May-1991

Revision History:

--*/



#include "ulib.hxx"
#include "system.hxx"
#include "replace.hxx"





VOID
REPLACE::DisplayMessageAndExit (
    IN  MSGID       MsgId,
    IN  PCWSTRING   String,
    IN  ULONG       ExitCode
	)

/*++

Routine Description:

	Displays a message and exits the program with the supplied error code.
	We support a maximum of one string parameter for the message.

Arguments:

	MsgId		-	Supplies the Id of the message to display.
	String		-	Supplies a string parameter for the message.
	ExitCode	-	Supplies the exit code with which to exit.

Return Value:

    None.

Notes:

--*/

{

	PATH	Path;

	if ( MsgId != 0 ) {
        if ( String ) {
		    DisplayMessage( MsgId, ERROR_MESSAGE, "%W", String );
	    } else {
		    DisplayMessage( MsgId, ERROR_MESSAGE, "" );
	    }
    }
	//
	//	Display the number of files added/ replaced.
	//
	if ( _AddSwitch ) {

		if ( _FilesAdded == 0 ) {
			DisplayMessage( REPLACE_MESSAGE_NO_FILES_ADDED );
		} else {
			DisplayMessage( REPLACE_MESSAGE_FILES_ADDED, NORMAL_MESSAGE, "%d",	_FilesAdded );
		}

	} else {

		if ( _FilesReplaced == 0 ) {
			DisplayMessage( REPLACE_MESSAGE_NO_FILES_REPLACED );
		} else {
			DisplayMessage( REPLACE_MESSAGE_FILES_REPLACED, NORMAL_MESSAGE, "%d", _FilesReplaced );
		}
	}

	exit( (int)ExitCode );

}

PWSTRING
REPLACE::QueryMessageString (
	IN MSGID	MsgId
	)
/*++

Routine Description:

	Obtains a string object initialized to the contents of some message

Arguments:

	MsgId	-	Supplies ID of the message

Return Value:

	PWSTRING	-	Pointer to initialized string object

Notes:

--*/

{

	PWSTRING	String;

    if ( ((String = NEW DSTRING) == NULL )  ||
		 !(SYSTEM::QueryResourceString( String, MsgId, "" )) ) {

		DisplayMessageAndExit( REPLACE_ERROR_NO_MEMORY, NULL, EXIT_NO_MEMORY );
	}

	return String;

}

VOID
REPLACE::ExitWithError(
	IN	DWORD		ErrorCode
	)

/*++

Routine Description:

	Displays a message based on a WIN32 error code, and exits.

Arguments:

	ErrorCode	-	Supplies Windows error code

Return Value:

	none

--*/

{
	Fatal(	EXIT_PATH_NOT_FOUND, REPLACE_ERROR_EXTENDED, "%d", ErrorCode );
}