ReactOS 0.4.16-dev-2613-g9533ad7
replace.c File Reference
#include "replace.h"
Include dependency graph for replace.c:

Go to the source code of this file.

Enumerations

enum  {
  REPLACE_ADD = 0x001 , REPLACE_CONFIRM = 0x002 , REPLACE_READ_ONLY = 0x004 , REPLACE_SUBDIR = 0x008 ,
  REPLACE_DISK = 0x010 , REPLACE_UPDATE = 0x020
}
 

Functions

void invalid_switch (LPTSTR is)
 
void getPath (TCHAR *out, LPTSTR in)
 
INT replace (TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], DWORD dwFlags, BOOL *doMore)
 
INT recReplace (DWORD dwFlags, TCHAR szSrcPath[MAX_PATH], TCHAR szDestPath[MAX_PATH], BOOL *doMore)
 
INT recFindSubDirs (DWORD dwFlags, TCHAR szSrcPath[MAX_PATH], TCHAR szDestPath[MAX_PATH], BOOL *doMore)
 
INT cmd_replace (INT argc, WCHAR **argv)
 
static BOOL CALLBACK CtrlHandlerRoutine (DWORD dwCtrlType)
 
int wmain (int argc, WCHAR **argvW)
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
REPLACE_ADD 
REPLACE_CONFIRM 
REPLACE_READ_ONLY 
REPLACE_SUBDIR 
REPLACE_DISK 
REPLACE_UPDATE 

Definition at line 11 of file replace.c.

12{
13 REPLACE_ADD = 0x001, /* /A */
14 REPLACE_CONFIRM = 0x002, /* /P */
15 REPLACE_READ_ONLY = 0x004, /* /R */
16 REPLACE_SUBDIR = 0x008, /* /S */
17 REPLACE_DISK = 0x010, /* /W */
18 REPLACE_UPDATE = 0x020, /* /U */
19};
@ REPLACE_UPDATE
Definition: replace.c:18
@ REPLACE_READ_ONLY
Definition: replace.c:15
@ REPLACE_SUBDIR
Definition: replace.c:16
@ REPLACE_DISK
Definition: replace.c:17
@ REPLACE_ADD
Definition: replace.c:13
@ REPLACE_CONFIRM
Definition: replace.c:14

Function Documentation

◆ cmd_replace()

INT cmd_replace ( INT  argc,
WCHAR **  argv 
)

Definition at line 382 of file replace.c.

383{
384 LPTSTR *arg;
385 INT i, filesReplaced = 0, nFiles, srcIndex = -1, destIndex = -1;
386 DWORD dwFlags = 0;
387 TCHAR szDestPath[MAX_PATH], szSrcPath[MAX_PATH], tmpSrcPath[MAX_PATH];
388 BOOL doMore = TRUE;
389
390 --argc;
391 ++argv;
392
393 /* Help wanted? */
394 if (argc == 1 && !_tcscmp(argv[0], _T("/?")))
395 {
397 return EXIT_SUCCESS;
398 }
399
400 /* Divide the argument in to an array of c-strings */
401 arg = argv;
402 nFiles = argc;
403
404 /* Read options */
405 for (i = 0; i < argc; i++)
406 {
407 if (arg[i][0] == _T('/'))
408 {
409 if (_tcslen(arg[i]) == 2)
410 {
411 switch (_totupper(arg[i][1]))
412 {
413 case _T('A'):
415 break;
416 case _T('P'):
418 break;
419 case _T('R'):
421 break;
422 case _T('S'):
424 break;
425 case _T('W'):
427 break;
428 case _T('U'):
430 break;
431 default:
433 return 11; /* Error */
434 }
435 }
436 else
437 {
439 return 11; /* Error */
440 }
441 nFiles--;
442 }
443 else
444 {
445 if (srcIndex == -1)
446 {
447 srcIndex = i;
448 }
449 else if (destIndex == -1)
450 {
451 destIndex = i;
452 }
453 else
454 {
456 return 11; /* Error */
457 }
458 }
459 }
460
461 /* See so that at least source is there */
462 if (nFiles < 1)
463 {
466 return 11; /* Error */
467 }
468
469 /* Check so that not both update and add switch is added and subdir */
471 {
474 return 11; /* Error */
475 }
476
477 /* If we have a destination get the full path */
478 if (destIndex != -1)
479 {
480 if (_tcslen(arg[destIndex]) == 2 && arg[destIndex][1] == ':')
481 GetRootPath(arg[destIndex],szDestPath,MAX_PATH);
482 else
483 {
484 /* Check for wildcards in destination directory */
485 if (_tcschr(arg[destIndex], _T('*')) != NULL ||
486 _tcschr(arg[destIndex], _T('?')) != NULL)
487 {
490 return 3; /* Error */
491 }
492 getPath(szDestPath, arg[destIndex]);
493 /* Make sure that destination exists */
494 if (!IsExistingDirectory(szDestPath))
495 {
498 return 3; /* Error */
499 }
500 }
501 }
502 else
503 {
504 /* Dest is current dir */
505 GetCurrentDirectory(MAX_PATH,szDestPath);
506 }
507
508 /* Get the full source path */
509 if (!(_tcslen(arg[srcIndex]) == 2 && arg[srcIndex][1] == ':'))
510 getPath(szSrcPath, arg[srcIndex]);
511 else
512 _tcscpy(szSrcPath,arg[srcIndex]);
513
514 /* Source does not have wildcards */
515 if (_tcschr(arg[srcIndex], _T('*')) == NULL &&
516 _tcschr(arg[srcIndex], _T('?')) == NULL)
517 {
518 /* Check so that source is not a directory, because that is not allowed */
519 if (IsExistingDirectory(szSrcPath))
520 {
523 return 2; /* Error */
524 }
525 /* Check if the file exists */
526 if (!IsExistingFile(szSrcPath))
527 {
529 return 2; /* Error */
530 }
531 }
532
533 /* /w switch is set so wait for any key to be pressed */
534 if (dwFlags & REPLACE_DISK)
535 {
536 msg_pause();
537 cgetchar();
538 }
539
540 /* Add an extra \ to the destination path if needed */
541 if (szDestPath[_tcslen(szDestPath) - 1] != _T('\\'))
542 _tcscat(szDestPath, _T("\\"));
543
544 /* Save source path */
545 _tcscpy(tmpSrcPath,szSrcPath);
546 /* Replace in dest dir */
547 filesReplaced += recReplace(dwFlags, tmpSrcPath, szDestPath, &doMore);
548 /* If subdir switch is set replace in the subdirs to */
549 if (dwFlags & REPLACE_SUBDIR && doMore)
550 {
551 filesReplaced += recFindSubDirs(dwFlags, szSrcPath, szDestPath, &doMore);
552 }
553
554 /* If source == dest write no more */
555 if (filesReplaced != -1)
556 {
557 /* No files replaced */
558 if (filesReplaced == 0)
559 {
560 /* Add switch dependent output */
561 if (dwFlags & REPLACE_ADD)
563 else
565 }
566 /* Some files replaced */
567 else
568 {
569 /* Add switch dependent output */
570 if (dwFlags & REPLACE_ADD)
572 else
574 }
575 }
576
577 /* Return memory */
578 return EXIT_SUCCESS;
579}
#define STRING_REPLACE_HELP1
Definition: resource.h:13
#define STRING_REPLACE_HELP7
Definition: resource.h:18
#define STRING_REPLACE_HELP3
Definition: resource.h:15
#define STRING_REPLACE_HELP4
Definition: resource.h:16
#define STRING_REPLACE_HELP2
Definition: resource.h:14
#define STRING_REPLACE_ERROR4
Definition: resource.h:8
#define STRING_REPLACE_ERROR6
Definition: resource.h:10
#define STRING_REPLACE_ERROR2
Definition: resource.h:6
#define STRING_REPLACE_HELP8
Definition: resource.h:19
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define MAX_PATH
Definition: compat.h:34
MonoAssembly int argc
Definition: metahost.c:107
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
char TCHAR
Definition: tchar.h:1402
#define _tcscmp
Definition: tchar.h:1424
#define _tcscat
Definition: tchar.h:622
#define _tcscpy
Definition: tchar.h:623
#define _totupper
Definition: tchar.h:1509
#define _tcslen
Definition: tchar.h:626
#define _tcschr
Definition: tchar.h:1406
#define argv
Definition: mplay32.c:18
LPSTR LPTSTR
Definition: ms-dtyp.idl:131
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
void invalid_switch(LPTSTR is)
Definition: replace.c:22
INT recReplace(DWORD dwFlags, TCHAR szSrcPath[MAX_PATH], TCHAR szDestPath[MAX_PATH], BOOL *doMore)
Definition: replace.c:205
void getPath(TCHAR *out, LPTSTR in)
Definition: replace.c:29
INT recFindSubDirs(DWORD dwFlags, TCHAR szSrcPath[MAX_PATH], TCHAR szDestPath[MAX_PATH], BOOL *doMore)
Definition: replace.c:305
BOOL IsExistingDirectory(IN LPCTSTR pszPath)
Definition: util.c:105
BOOL IsExistingFile(IN LPCTSTR pszPath)
Definition: util.c:99
INT GetRootPath(IN LPCTSTR InPath, OUT LPTSTR OutPath, IN INT size)
Definition: util.c:21
TCHAR cgetchar(VOID)
Definition: util.c:243
VOID msg_pause(VOID)
Definition: util.c:211
#define ConOutResPrintf(uID,...)
Definition: replace.h:31
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
#define GetCurrentDirectory
Definition: winbase.h:3554
void * arg
Definition: msvc.h:10

Referenced by wmain().

◆ CtrlHandlerRoutine()

static BOOL CALLBACK CtrlHandlerRoutine ( DWORD  dwCtrlType)
static

Definition at line 582 of file replace.c.

583{
584 switch (dwCtrlType)
585 {
586 case CTRL_C_EVENT: /* Ctrl+C */
587 case CTRL_CLOSE_EVENT: /* Closing console? */
589 return TRUE; /* Handled */
590
591 default:
592 return FALSE; /* Ignored */
593 }
594}
#define FALSE
Definition: types.h:117
BOOL bCtrlBreak
Definition: util.c:11
#define CTRL_C_EVENT
Definition: wincon.h:96
#define CTRL_CLOSE_EVENT
Definition: wincon.h:98

Referenced by wmain().

◆ getPath()

void getPath ( TCHAR out,
LPTSTR  in 
)

Definition at line 29 of file replace.c.

30{
31 if (_tcslen(in) == 2 && in[1] == _T(':'))
33 else
35}
GLuint in
Definition: glext.h:9616
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383
#define GetFullPathName
Definition: winbase.h:3570

Referenced by cmd_replace().

◆ invalid_switch()

void invalid_switch ( LPTSTR  is)

Definition at line 22 of file replace.c.

Referenced by cmd_replace().

◆ recFindSubDirs()

INT recFindSubDirs ( DWORD  dwFlags,
TCHAR  szSrcPath[MAX_PATH],
TCHAR  szDestPath[MAX_PATH],
BOOL doMore 
)

Definition at line 305 of file replace.c.

309{
311 WIN32_FIND_DATA findBuffer;
312 TCHAR tmpDestPath[MAX_PATH], tmpSrcPath[MAX_PATH];
313 INT filesReplaced = 0;
314 INT_PTR i;
315
316 /*
317 * Add a wildcard to dest end so the it will be easy to iterate
318 * over all the files and directorys in the dest directory.
319 */
320 _tcscat(szDestPath, _T("*"));
321
322 /* Get the first file in the directory */
323 hFile = FindFirstFile(szDestPath, &findBuffer);
324
325 /* Remove the star added earlier to dest path */
326 for (i = (_tcslen(szDestPath) - 1); i > -1; i--)
327 {
328 if (szDestPath[i] != _T('\\'))
329 szDestPath[i] = _T('\0');
330 else
331 break;
332 }
333
334 /* Iterate over all filed directories in the dest dir */
335 do
336 {
337 /* Save the source path so that it will not be wrecked */
338 _tcscpy(tmpSrcPath,szSrcPath);
339 /* Check for reading problems */
341 {
342 ConOutFormatMessage(GetLastError(), tmpSrcPath);
343 return filesReplaced;
344 }
345
346 /*
347 * Check if the we should enter the dir or if it is a file
348 * or . or .. if so thake the next object to process.
349 */
350 if (!_tcscmp(findBuffer.cFileName, _T(".")) ||
351 !_tcscmp(findBuffer.cFileName, _T(".."))||
352 IsExistingFile(findBuffer.cFileName))
353 continue;
354 /* Add the destpath and the new dir path to tempDestPath */
355 _tcscpy(tmpDestPath,szDestPath);
356 _tcscat(tmpDestPath, findBuffer.cFileName);
357 /* Make sure that we have a directory */
358 if (IsExistingDirectory(tmpDestPath))
359 {
360 /* Add a \ to the end or the path */
361 if (szDestPath[_tcslen(tmpDestPath) - 1] != _T('\\'))
362 _tcscat(tmpDestPath, _T("\\"));
363 /* Call the function to replace files in the new directory */
364 filesReplaced += recReplace(dwFlags, tmpSrcPath, tmpDestPath, doMore);
365 /* If there were problems break e.g. read-only file */
366 if (!*doMore)
367 break;
368 _tcscpy(tmpSrcPath,szSrcPath);
369 /* Control the next level of subdirs */
370 filesReplaced += recFindSubDirs(dwFlags,tmpSrcPath,tmpDestPath, doMore);
371 if (!*doMore)
372 break;
373 }
374 /* Get the next handle */
375 } while (FindNextFile(hFile, &findBuffer));
376
378
379 return filesReplaced;
380}
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
_In_ HANDLE hFile
Definition: mswsock.h:90
#define ConOutFormatMessage(MessageId,...)
Definition: replace.h:34
int32_t INT_PTR
Definition: typedefs.h:64
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FindNextFile
Definition: winbase.h:3537
#define FindFirstFile
Definition: winbase.h:3531

Referenced by cmd_replace(), and recFindSubDirs().

◆ recReplace()

INT recReplace ( DWORD  dwFlags,
TCHAR  szSrcPath[MAX_PATH],
TCHAR  szDestPath[MAX_PATH],
BOOL doMore 
)

Definition at line 205 of file replace.c.

209{
210 TCHAR tmpDestPath[MAX_PATH], tmpSrcPath[MAX_PATH];
211 INT filesReplaced=0;
212 INT_PTR i;
213 DWORD dwAttrib = 0;
215 WIN32_FIND_DATA findBuffer;
216
217 /* Get file handle to the sourcefile(s) */
218 hFile = FindFirstFile(szSrcPath, &findBuffer);
219
220 /*
221 * Strip the paths back to the folder they are in, so that
222 * the different filenames can be added if more than one.
223 */
224 for (i = (_tcslen(szSrcPath) - 1); i > -1; i--)
225 {
226 if (szSrcPath[i] != _T('\\'))
227 szSrcPath[i] = _T('\0');
228 else
229 break;
230 }
231
232 /* Go through all the sourcefiles and copy/replace them */
233 do
234 {
235 if (bCtrlBreak)
236 return filesReplaced;
237
238 /* Problem with file handler */
240 return filesReplaced;
241
242 /* We do not want to replace any .. . ocr directory */
243 if (!_tcscmp(findBuffer.cFileName, _T(".")) ||
244 !_tcscmp(findBuffer.cFileName, _T("..")) ||
245 (findBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
246 {
247 continue;
248 }
249
250 /* Add filename to destpath */
251 _tcscpy(tmpDestPath,szDestPath);
252 _tcscat(tmpDestPath, findBuffer.cFileName);
253
254 dwAttrib = GetFileAttributes(tmpDestPath);
255 /* Check add flag */
256 if (dwFlags & REPLACE_ADD)
257 {
258 if (IsExistingFile(tmpDestPath))
259 continue;
260 else
261 dwAttrib = 0;
262 }
263 else
264 {
265 if (!IsExistingFile(tmpDestPath))
266 continue;
267 }
268
269 /* Check if file is read only, if so check if that should be ignored */
270 if (dwAttrib & FILE_ATTRIBUTE_READONLY)
271 {
272 if (!(dwFlags & REPLACE_READ_ONLY))
273 {
275 *doMore = FALSE;
276 break;
277 }
278 }
279
280 /* Add filename to sourcepath, insted of wildcards */
281 _tcscpy(tmpSrcPath,szSrcPath);
282 _tcscat(tmpSrcPath, findBuffer.cFileName);
283
284 /* Make the replace */
285 if (replace(tmpSrcPath,tmpDestPath, dwFlags, doMore))
286 {
287 filesReplaced++;
288 }
289 else if (!*doMore)
290 {
291 /* The file to be replaced was the same as the source */
292 filesReplaced = -1;
293 break;
294 }
295
296 /* Take next sourcefile if any */
297 } while (FindNextFile(hFile, &findBuffer));
298
300
301 return filesReplaced;
302}
#define STRING_REPLACE_ERROR5
Definition: resource.h:9
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
INT replace(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], DWORD dwFlags, BOOL *doMore)
Definition: replace.c:38
#define GetFileAttributes
Definition: winbase.h:3564

Referenced by cmd_replace(), and recFindSubDirs().

◆ replace()

INT replace ( TCHAR  source[MAX_PATH],
TCHAR  dest[MAX_PATH],
DWORD  dwFlags,
BOOL doMore 
)

Definition at line 38 of file replace.c.

39{
42 HANDLE hFileSrc, hFileDest;
43 DWORD dwAttrib, dwRead, dwWritten;
45 BOOL bEof = FALSE;
46 FILETIME srcCreationTime, destCreationTime, srcLastAccessTime, destLastAccessTime;
47 FILETIME srcLastWriteTime, destLastWriteTime;
50 s[0] = _totupper(s[0]);
51 d[0] = _totupper(d[0]);
52 // ConOutPrintf(_T("old-src: %s\n"), s);
53 // ConOutPrintf(_T("old-dest: %s\n"), d);
54 // ConOutPrintf(_T("src: %s\n"), source);
55 // ConOutPrintf(_T("dest: %s\n"), dest);
56
57 /* Open up the sourcefile */
59 if (hFileSrc == INVALID_HANDLE_VALUE)
60 {
62 return 0;
63 }
64
65 /*
66 * Get the time from source file to be used in the comparison
67 * with dest time if update switch is set.
68 */
69 GetFileTime(hFileSrc, &srcCreationTime, &srcLastAccessTime, &srcLastWriteTime);
70
71 /*
72 * Retrieve the source attributes so that they later on
73 * can be inserted in to the destination.
74 */
75 dwAttrib = GetFileAttributes(source);
76
78 {
79 /*
80 * Resets the attributes to avoid problems with read only files,
81 * checks for read only has been made earlier.
82 */
84 /*
85 * Is the update flas set? The time has to be controled so that
86 * only older files are replaced.
87 */
89 {
90 /* Read destination time */
92 0, NULL);
93
94 if (hFileDest == INVALID_HANDLE_VALUE)
95 {
97 CloseHandle(hFileSrc);
98 return 0;
99 }
100
101 /* Compare time */
102 GetFileTime(hFileDest, &destCreationTime, &destLastAccessTime, &destLastWriteTime);
103 if (!((srcLastWriteTime.dwHighDateTime > destLastWriteTime.dwHighDateTime) ||
104 (srcLastWriteTime.dwHighDateTime == destLastWriteTime.dwHighDateTime &&
105 srcLastWriteTime.dwLowDateTime > destLastWriteTime.dwLowDateTime)))
106 {
107 CloseHandle(hFileSrc);
108 CloseHandle(hFileDest);
109 return 0;
110 }
111 CloseHandle(hFileDest);
112 }
113 /* Delete the old file */
115 }
116
117 /* Check confirm flag, and take appropriate action */
119 {
120 /* Output depending on add flag */
121 if (dwFlags & REPLACE_ADD)
123 else
125 if (!FilePromptYNA(0))
126 {
127 CloseHandle(hFileSrc);
128 return 0;
129 }
130 }
131
132 /* Output depending on add flag */
133 if (dwFlags & REPLACE_ADD)
135 else
137
138 /* Make sure source and destination is not the same */
139 if (!_tcscmp(s, d))
140 {
142 CloseHandle(hFileSrc);
143 *doMore = FALSE;
144 return 0;
145 }
146
147 /* Open destination file to write to */
148 hFileDest = CreateFile(dest, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
149 if (hFileDest == INVALID_HANDLE_VALUE)
150 {
151 CloseHandle(hFileSrc);
153 *doMore = FALSE;
154 return 0;
155 }
156
157 /* Get buffer for the copy process */
159 if (buffer == NULL)
160 {
161 CloseHandle(hFileDest);
162 CloseHandle(hFileSrc);
164 return 0;
165 }
166
167 /* Put attribute and time to the new destination file */
168 SetFileAttributes(dest, dwAttrib);
169 SetFileTime(hFileDest, &srcCreationTime, &srcLastAccessTime, &srcLastWriteTime);
170 do
171 {
172 /* Read data from source */
173 ReadFile(hFileSrc, buffer, BUFF_SIZE, &dwRead, NULL);
174
175 /* Done? */
176 if (dwRead == 0)
177 break;
178
179 /* Write to destination file */
180 WriteFile(hFileDest, buffer, dwRead, &dwWritten, NULL);
181
182 /* Done! or ctrl break! */
183 if (dwWritten != dwRead || bCtrlBreak)
184 {
187 CloseHandle(hFileDest);
188 CloseHandle(hFileSrc);
189 return 0;
190 }
191 }
192 while (!bEof);
193
194 /* Return memory and close files */
196 CloseHandle(hFileDest);
197 CloseHandle(hFileSrc);
198
199 /* Return one file replaced */
200 return 1;
201}
#define STRING_ERROR_OUT_OF_MEMORY
Definition: resource.h:28
#define STRING_REPLACE_HELP11
Definition: resource.h:22
#define STRING_REPLACE_ERROR7
Definition: resource.h:11
#define STRING_COPY_ERROR1
Definition: resource.h:25
#define STRING_REPLACE_HELP5
Definition: resource.h:17
#define STRING_REPLACE_HELP9
Definition: resource.h:20
#define STRING_REPLACE_HELP10
Definition: resource.h:21
#define STRING_COPY_ERROR3
Definition: resource.h:26
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define GENERIC_READ
Definition: compat.h:135
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI SetFileTime(IN HANDLE hFile, CONST FILETIME *lpCreationTime OPTIONAL, CONST FILETIME *lpLastAccessTime OPTIONAL, CONST FILETIME *lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:932
BOOL WINAPI GetFileTime(IN HANDLE hFile, OUT LPFILETIME lpCreationTime OPTIONAL, OUT LPFILETIME lpLastAccessTime OPTIONAL, OUT LPFILETIME lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:880
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
GLdouble s
Definition: gl.h:2039
GLuint buffer
Definition: glext.h:5915
#define d
Definition: ke_i.h:81
#define CREATE_ALWAYS
Definition: disk.h:72
static char * dest
Definition: rtl.c:135
#define PAGE_READWRITE
Definition: nt_native.h:1307
#define MEM_RELEASE
Definition: nt_native.h:1319
#define GENERIC_WRITE
Definition: nt_native.h:90
#define MEM_COMMIT
Definition: nt_native.h:1316
#define BUFF_SIZE
Definition: replace.h:26
#define ConOutResPuts(uID)
Definition: replace.h:28
INT FilePromptYNA(UINT resID)
Definition: util.c:111
VOID GetPathCase(TCHAR *Path, TCHAR *OutPath)
Definition: util.c:53
DWORD dwHighDateTime
Definition: mapidefs.h:66
DWORD dwLowDateTime
Definition: mapidefs.h:65
unsigned char * LPBYTE
Definition: typedefs.h:53
LPVOID NTAPI VirtualAlloc(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flAllocationType, IN DWORD flProtect)
Definition: virtmem.c:65
BOOL NTAPI VirtualFree(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD dwFreeType)
Definition: virtmem.c:119
#define SetFileAttributes
Definition: winbase.h:3658
#define DeleteFile
Definition: winbase.h:3513
#define CreateFile
Definition: winbase.h:3498

Referenced by AddMRUData(), cache_container_create_object_name(), dialog_find(), EmptyStore_add(), epm_register(), ept_insert(), ext4_fs_set_xattr(), format_replace(), HLPFILE_RtfAddText(), HTMLDocument_open(), HTMLWindow2_open(), IEHTMLWindow2_open(), MAIN_ReplaceString(), msi_set_sourcedir_props(), ParaNdis_DebugInitialize(), recReplace(), RegExp_Replace(), RmCpTest::replace0(), and RmCpTest::replace1().

◆ wmain()

int wmain ( int  argc,
WCHAR **  argvW 
)

Definition at line 596 of file replace.c.

597{
598 /* Handle Ctrl+C and console closing */
600
601 /* Initialize the Console Standard Streams */
603
604 return cmd_replace(argc, argvW);
605}
#define ConInitStdStreams()
Definition: conutils_noros.h:5
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, BOOL Add)
Definition: console.c:2111
INT cmd_replace(INT argc, WCHAR **argv)
Definition: replace.c:382
static BOOL CALLBACK CtrlHandlerRoutine(DWORD dwCtrlType)
Definition: replace.c:582