2007-03-06 21:04:15 +01:00
|
|
|
/*
|
|
|
|
* XCOPY - Wine-compatible xcopy program
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 J. Edmeades
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2007-03-30 20:20:21 +02:00
|
|
|
/*
|
|
|
|
* FIXME:
|
|
|
|
* This should now support all options listed in the xcopy help from
|
|
|
|
* windows XP except:
|
|
|
|
* /Z - Copy from network drives in restartable mode
|
|
|
|
* /X - Copy file audit settings (sets /O)
|
|
|
|
* /O - Copy file ownership + ACL info
|
|
|
|
* /G - Copy encrypted files to unencrypted destination
|
|
|
|
* /V - Verifies files
|
|
|
|
*/
|
|
|
|
|
2007-03-06 21:04:15 +01:00
|
|
|
/*
|
|
|
|
* Notes:
|
2018-06-24 22:44:13 +02:00
|
|
|
* Documented valid return codes are:
|
2007-03-06 21:04:15 +01:00
|
|
|
* 0 - OK
|
2018-06-24 22:44:13 +02:00
|
|
|
* 1 - No files found to copy (*1)
|
2007-03-06 21:04:15 +01:00
|
|
|
* 2 - CTRL+C during copy
|
|
|
|
* 4 - Initialization error, or invalid source specification
|
|
|
|
* 5 - Disk write error
|
2018-06-24 22:44:13 +02:00
|
|
|
*
|
|
|
|
* (*1) Testing shows return code 1 is never returned
|
2007-03-06 21:04:15 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2012-01-23 12:16:36 +01:00
|
|
|
#include <stdlib.h>
|
2007-03-06 21:04:15 +01:00
|
|
|
#include <windows.h>
|
|
|
|
#include <wine/debug.h>
|
2007-03-30 20:20:20 +02:00
|
|
|
#include "xcopy.h"
|
2007-03-29 23:21:03 +02:00
|
|
|
|
2007-03-06 21:04:15 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(xcopy);
|
|
|
|
|
2007-03-30 20:20:17 +02:00
|
|
|
|
|
|
|
/* Typedefs */
|
|
|
|
typedef struct _EXCLUDELIST
|
|
|
|
{
|
|
|
|
struct _EXCLUDELIST *next;
|
|
|
|
WCHAR *name;
|
|
|
|
} EXCLUDELIST;
|
|
|
|
|
2007-03-06 21:04:15 +01:00
|
|
|
|
|
|
|
/* Global variables */
|
|
|
|
static ULONG filesCopied = 0; /* Number of files copied */
|
2007-03-30 20:20:17 +02:00
|
|
|
static EXCLUDELIST *excludeList = NULL; /* Excluded strings list */
|
2007-03-30 20:20:18 +02:00
|
|
|
static FILETIME dateRange; /* Date range to copy after*/
|
2007-03-06 21:04:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* To minimize stack usage during recursion, some temporary variables
|
|
|
|
made global */
|
|
|
|
static WCHAR copyFrom[MAX_PATH];
|
|
|
|
static WCHAR copyTo[MAX_PATH];
|
|
|
|
|
|
|
|
|
|
|
|
/* =========================================================================
|
2011-10-18 16:43:04 +02:00
|
|
|
* Load a string from the resource file, handling any error
|
|
|
|
* Returns string retrieved from resource file
|
|
|
|
* ========================================================================= */
|
|
|
|
static WCHAR *XCOPY_LoadMessage(UINT id) {
|
|
|
|
static WCHAR msg[MAXSTRING];
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2018-07-13 19:01:26 +02:00
|
|
|
if (!LoadStringW(GetModuleHandleW(NULL), id, msg, ARRAY_SIZE(msg))) {
|
2011-10-18 16:43:04 +02:00
|
|
|
WINE_FIXME("LoadString failed with %d\n", GetLastError());
|
2020-10-21 01:02:40 +02:00
|
|
|
lstrcpyW(msg, L"Failed!");
|
2007-03-29 23:21:03 +02:00
|
|
|
}
|
2011-10-18 16:43:04 +02:00
|
|
|
return msg;
|
|
|
|
}
|
2007-03-29 23:21:03 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* =========================================================================
|
|
|
|
* Output a formatted unicode string. Ideally this will go to the console
|
|
|
|
* and hence required WriteConsoleW to output it, however if file i/o is
|
|
|
|
* redirected, it needs to be WriteFile'd using OEM (not ANSI) format
|
|
|
|
* ========================================================================= */
|
2017-11-02 10:22:27 +01:00
|
|
|
static int WINAPIV XCOPY_wprintf(const WCHAR *format, ...) {
|
2011-10-18 16:43:04 +02:00
|
|
|
|
|
|
|
static WCHAR *output_bufW = NULL;
|
|
|
|
static char *output_bufA = NULL;
|
|
|
|
static BOOL toConsole = TRUE;
|
|
|
|
static BOOL traceOutput = FALSE;
|
|
|
|
#define MAX_WRITECONSOLE_SIZE 65535
|
|
|
|
|
2011-10-20 14:31:29 +02:00
|
|
|
__ms_va_list parms;
|
2011-10-18 16:43:04 +02:00
|
|
|
DWORD nOut;
|
|
|
|
int len;
|
|
|
|
DWORD res = 0;
|
2007-03-31 22:49:30 +02:00
|
|
|
|
2010-10-27 01:48:50 +02:00
|
|
|
/*
|
2011-10-18 16:43:04 +02:00
|
|
|
* Allocate buffer to use when writing to console
|
|
|
|
* Note: Not freed - memory will be allocated once and released when
|
|
|
|
* xcopy ends
|
2010-10-27 01:48:50 +02:00
|
|
|
*/
|
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
if (!output_bufW) output_bufW = HeapAlloc(GetProcessHeap(), 0,
|
2013-09-29 14:23:04 +02:00
|
|
|
MAX_WRITECONSOLE_SIZE*sizeof(WCHAR));
|
2011-10-18 16:43:04 +02:00
|
|
|
if (!output_bufW) {
|
|
|
|
WINE_FIXME("Out of memory - could not allocate 2 x 64K buffers\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2010-10-27 01:48:50 +02:00
|
|
|
|
2011-10-20 14:31:29 +02:00
|
|
|
__ms_va_start(parms, format);
|
2011-10-18 16:44:32 +02:00
|
|
|
len = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, format, 0, 0, output_bufW,
|
|
|
|
MAX_WRITECONSOLE_SIZE/sizeof(*output_bufW), &parms);
|
2011-10-20 14:31:29 +02:00
|
|
|
__ms_va_end(parms);
|
2020-05-13 22:07:16 +02:00
|
|
|
if (len == 0 && GetLastError() != ERROR_NO_WORK_DONE) {
|
2011-10-18 16:44:32 +02:00
|
|
|
WINE_FIXME("Could not format string: le=%u, fmt=%s\n", GetLastError(), wine_dbgstr_w(format));
|
2011-10-18 16:43:04 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2010-10-27 01:48:50 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Try to write as unicode whenever we think it's a console */
|
|
|
|
if (toConsole) {
|
|
|
|
res = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE),
|
|
|
|
output_bufW, len, &nOut, NULL);
|
|
|
|
}
|
2010-10-27 01:48:50 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* If writing to console has failed (ever) we assume it's file
|
|
|
|
i/o so convert to OEM codepage and output */
|
|
|
|
if (!res) {
|
|
|
|
BOOL usedDefaultChar = FALSE;
|
|
|
|
DWORD convertedChars;
|
2010-10-27 01:48:50 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
toConsole = FALSE;
|
2010-10-27 01:48:50 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/*
|
|
|
|
* Allocate buffer to use when writing to file. Not freed, as above
|
|
|
|
*/
|
|
|
|
if (!output_bufA) output_bufA = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
MAX_WRITECONSOLE_SIZE);
|
|
|
|
if (!output_bufA) {
|
|
|
|
WINE_FIXME("Out of memory - could not allocate 2 x 64K buffers\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2010-10-27 01:48:50 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Convert to OEM, then output */
|
|
|
|
convertedChars = WideCharToMultiByte(GetConsoleOutputCP(), 0, output_bufW,
|
|
|
|
len, output_bufA, MAX_WRITECONSOLE_SIZE,
|
|
|
|
"?", &usedDefaultChar);
|
|
|
|
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), output_bufA, convertedChars,
|
|
|
|
&nOut, FALSE);
|
2010-10-27 01:48:50 +02:00
|
|
|
}
|
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Trace whether screen or console */
|
|
|
|
if (!traceOutput) {
|
|
|
|
WINE_TRACE("Writing to console? (%d)\n", toConsole);
|
|
|
|
traceOutput = TRUE;
|
2010-10-27 01:48:50 +02:00
|
|
|
}
|
2011-10-18 16:43:04 +02:00
|
|
|
return nOut;
|
2010-10-27 01:48:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* =========================================================================
|
2011-10-18 16:43:04 +02:00
|
|
|
* Load a string for a system error and writes it to the screen
|
|
|
|
* Returns string retrieved from resource file
|
|
|
|
* ========================================================================= */
|
|
|
|
static void XCOPY_FailMessage(DWORD err) {
|
|
|
|
LPWSTR lpMsgBuf;
|
|
|
|
int status;
|
2010-10-27 01:49:06 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
status = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
|
|
|
FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL, err, 0,
|
|
|
|
(LPWSTR) &lpMsgBuf, 0, NULL);
|
|
|
|
if (!status) {
|
|
|
|
WINE_FIXME("FIXME: Cannot display message for error %d, status %d\n",
|
|
|
|
err, GetLastError());
|
|
|
|
} else {
|
2020-10-21 01:02:40 +02:00
|
|
|
XCOPY_wprintf(L"%1\n", lpMsgBuf);
|
2011-10-18 16:43:04 +02:00
|
|
|
LocalFree ((HLOCAL)lpMsgBuf);
|
2010-10-27 01:49:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* =========================================================================
|
|
|
|
* Routine copied from cmd.exe md command -
|
|
|
|
* This works recursively. so creating dir1\dir2\dir3 will create dir1 and
|
|
|
|
* dir2 if they do not already exist.
|
|
|
|
* ========================================================================= */
|
|
|
|
static BOOL XCOPY_CreateDirectory(const WCHAR* path)
|
2010-10-27 01:48:50 +02:00
|
|
|
{
|
2011-10-18 16:43:04 +02:00
|
|
|
int len;
|
|
|
|
WCHAR *new_path;
|
|
|
|
BOOL ret = TRUE;
|
2010-10-27 01:48:50 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
new_path = HeapAlloc(GetProcessHeap(),0, sizeof(WCHAR) * (lstrlenW(path)+1));
|
|
|
|
lstrcpyW(new_path,path);
|
2010-10-27 01:48:50 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
while ((len = lstrlenW(new_path)) && new_path[len - 1] == '\\')
|
|
|
|
new_path[len - 1] = 0;
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
while (!CreateDirectoryW(new_path,NULL))
|
2007-03-06 21:04:15 +01:00
|
|
|
{
|
2011-10-18 16:43:04 +02:00
|
|
|
WCHAR *slash;
|
|
|
|
DWORD last_error = GetLastError();
|
|
|
|
if (last_error == ERROR_ALREADY_EXISTS)
|
|
|
|
break;
|
2007-03-30 20:20:18 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
if (last_error != ERROR_PATH_NOT_FOUND)
|
|
|
|
{
|
|
|
|
ret = FALSE;
|
|
|
|
break;
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
if (!(slash = wcsrchr(new_path,'\\')) && ! (slash = wcsrchr(new_path,'/')))
|
|
|
|
{
|
|
|
|
ret = FALSE;
|
|
|
|
break;
|
2007-03-31 22:24:17 +02:00
|
|
|
}
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
len = slash - new_path;
|
|
|
|
new_path[len] = 0;
|
|
|
|
if (!XCOPY_CreateDirectory(new_path))
|
|
|
|
{
|
|
|
|
ret = FALSE;
|
|
|
|
break;
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
2011-10-18 16:43:04 +02:00
|
|
|
new_path[len] = '\\';
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
2011-10-18 16:43:04 +02:00
|
|
|
HeapFree(GetProcessHeap(),0,new_path);
|
|
|
|
return ret;
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* =========================================================================
|
2011-10-18 16:43:04 +02:00
|
|
|
* Process a single file from the /EXCLUDE: file list, building up a list
|
|
|
|
* of substrings to avoid copying
|
|
|
|
* Returns TRUE on any failure
|
|
|
|
* ========================================================================= */
|
|
|
|
static BOOL XCOPY_ProcessExcludeFile(WCHAR* filename, WCHAR* endOfName) {
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
WCHAR endChar = *endOfName;
|
|
|
|
WCHAR buffer[MAXSTRING];
|
|
|
|
FILE *inFile = NULL;
|
|
|
|
|
|
|
|
/* Null terminate the filename (temporarily updates the filename hence
|
|
|
|
parms not const) */
|
|
|
|
*endOfName = 0x00;
|
|
|
|
|
|
|
|
/* Open the file */
|
2020-10-21 01:02:40 +02:00
|
|
|
inFile = _wfopen(filename, L"rt");
|
2011-10-18 16:43:04 +02:00
|
|
|
if (inFile == NULL) {
|
|
|
|
XCOPY_wprintf(XCOPY_LoadMessage(STRING_OPENFAIL), filename);
|
|
|
|
*endOfName = endChar;
|
|
|
|
return TRUE;
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Process line by line */
|
2018-07-13 19:01:26 +02:00
|
|
|
while (fgetws(buffer, ARRAY_SIZE(buffer), inFile) != NULL) {
|
2011-10-18 16:43:04 +02:00
|
|
|
EXCLUDELIST *thisEntry;
|
|
|
|
int length = lstrlenW(buffer);
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* If more than CRLF */
|
|
|
|
if (length > 1) {
|
2014-10-27 09:46:38 +01:00
|
|
|
buffer[length-1] = 0; /* strip CRLF */
|
2011-10-18 16:43:04 +02:00
|
|
|
thisEntry = HeapAlloc(GetProcessHeap(), 0, sizeof(EXCLUDELIST));
|
|
|
|
thisEntry->next = excludeList;
|
|
|
|
excludeList = thisEntry;
|
|
|
|
thisEntry->name = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
(length * sizeof(WCHAR))+1);
|
|
|
|
lstrcpyW(thisEntry->name, buffer);
|
|
|
|
CharUpperBuffW(thisEntry->name, length);
|
|
|
|
WINE_TRACE("Read line : '%s'\n", wine_dbgstr_w(thisEntry->name));
|
|
|
|
}
|
|
|
|
}
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* See if EOF or error occurred */
|
|
|
|
if (!feof(inFile)) {
|
|
|
|
XCOPY_wprintf(XCOPY_LoadMessage(STRING_READFAIL), filename);
|
|
|
|
*endOfName = endChar;
|
2013-07-15 21:33:32 +02:00
|
|
|
fclose(inFile);
|
2011-10-18 16:43:04 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Revert the input string to original form, and cleanup + return */
|
|
|
|
*endOfName = endChar;
|
|
|
|
fclose(inFile);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-03-30 20:20:20 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* =========================================================================
|
|
|
|
* Process the /EXCLUDE: file list, building up a list of substrings to
|
|
|
|
* avoid copying
|
|
|
|
* Returns TRUE on any failure
|
|
|
|
* ========================================================================= */
|
|
|
|
static BOOL XCOPY_ProcessExcludeList(WCHAR* parms) {
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
WCHAR *filenameStart = parms;
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
WINE_TRACE("/EXCLUDE parms: '%s'\n", wine_dbgstr_w(parms));
|
|
|
|
excludeList = NULL;
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
while (*parms && *parms != ' ' && *parms != '/') {
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* If found '+' then process the file found so far */
|
|
|
|
if (*parms == '+') {
|
|
|
|
if (XCOPY_ProcessExcludeFile(filenameStart, parms)) {
|
|
|
|
return TRUE;
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
2011-10-18 16:43:04 +02:00
|
|
|
filenameStart = parms+1;
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
2011-10-18 16:43:04 +02:00
|
|
|
parms++;
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
if (filenameStart != parms) {
|
|
|
|
if (XCOPY_ProcessExcludeFile(filenameStart, parms)) {
|
|
|
|
return TRUE;
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
|
|
|
}
|
2011-10-18 16:43:04 +02:00
|
|
|
|
|
|
|
return FALSE;
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* =========================================================================
|
|
|
|
XCOPY_DoCopy - Recursive function to copy files based on input parms
|
|
|
|
of a stem and a spec
|
|
|
|
|
|
|
|
This works by using FindFirstFile supplying the source stem and spec.
|
|
|
|
If results are found, any non-directory ones are processed
|
|
|
|
Then, if /S or /E is supplied, another search is made just for
|
|
|
|
directories, and this function is called again for that directory
|
|
|
|
|
|
|
|
========================================================================= */
|
|
|
|
static int XCOPY_DoCopy(WCHAR *srcstem, WCHAR *srcspec,
|
|
|
|
WCHAR *deststem, WCHAR *destspec,
|
|
|
|
DWORD flags)
|
|
|
|
{
|
2008-09-04 14:08:19 +02:00
|
|
|
WIN32_FIND_DATAW *finddata;
|
2007-03-06 21:04:15 +01:00
|
|
|
HANDLE h;
|
|
|
|
BOOL findres = TRUE;
|
|
|
|
WCHAR *inputpath, *outputpath;
|
|
|
|
BOOL copiedFile = FALSE;
|
2007-03-29 23:21:07 +02:00
|
|
|
DWORD destAttribs, srcAttribs;
|
2007-03-29 23:21:01 +02:00
|
|
|
BOOL skipFile;
|
2007-10-24 23:02:43 +02:00
|
|
|
int ret = 0;
|
2007-03-06 21:04:15 +01:00
|
|
|
|
|
|
|
/* Allocate some working memory on heap to minimize footprint */
|
2008-09-04 14:08:19 +02:00
|
|
|
finddata = HeapAlloc(GetProcessHeap(), 0, sizeof(WIN32_FIND_DATAW));
|
2007-03-06 21:04:15 +01:00
|
|
|
inputpath = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
|
|
|
|
outputpath = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
|
|
|
|
|
|
|
|
/* Build the search info into a single parm */
|
|
|
|
lstrcpyW(inputpath, srcstem);
|
|
|
|
lstrcatW(inputpath, srcspec);
|
|
|
|
|
|
|
|
/* Search 1 - Look for matching files */
|
2008-09-04 14:08:19 +02:00
|
|
|
h = FindFirstFileW(inputpath, finddata);
|
2007-03-06 21:04:15 +01:00
|
|
|
while (h != INVALID_HANDLE_VALUE && findres) {
|
|
|
|
|
2007-03-29 23:21:01 +02:00
|
|
|
skipFile = FALSE;
|
|
|
|
|
2007-03-06 21:04:15 +01:00
|
|
|
/* Ignore . and .. */
|
2020-10-21 01:02:40 +02:00
|
|
|
if (lstrcmpW(finddata->cFileName, L".")==0 ||
|
|
|
|
lstrcmpW(finddata->cFileName, L"..")==0 ||
|
2007-03-06 21:04:15 +01:00
|
|
|
finddata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
|
|
|
|
|
|
|
WINE_TRACE("Skipping directory, . or .. (%s)\n", wine_dbgstr_w(finddata->cFileName));
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* Get the filename information */
|
|
|
|
lstrcpyW(copyFrom, srcstem);
|
2007-03-29 23:21:04 +02:00
|
|
|
if (flags & OPT_SHORTNAME) {
|
|
|
|
lstrcatW(copyFrom, finddata->cAlternateFileName);
|
|
|
|
} else {
|
|
|
|
lstrcatW(copyFrom, finddata->cFileName);
|
|
|
|
}
|
2007-03-06 21:04:15 +01:00
|
|
|
|
|
|
|
lstrcpyW(copyTo, deststem);
|
|
|
|
if (*destspec == 0x00) {
|
2007-03-29 23:21:04 +02:00
|
|
|
if (flags & OPT_SHORTNAME) {
|
|
|
|
lstrcatW(copyTo, finddata->cAlternateFileName);
|
|
|
|
} else {
|
|
|
|
lstrcatW(copyTo, finddata->cFileName);
|
|
|
|
}
|
2007-03-06 21:04:15 +01:00
|
|
|
} else {
|
|
|
|
lstrcatW(copyTo, destspec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do the copy */
|
|
|
|
WINE_TRACE("ACTION: Copy '%s' -> '%s'\n", wine_dbgstr_w(copyFrom),
|
|
|
|
wine_dbgstr_w(copyTo));
|
|
|
|
if (!copiedFile && !(flags & OPT_SIMULATE)) XCOPY_CreateDirectory(deststem);
|
|
|
|
|
2007-03-29 23:21:07 +02:00
|
|
|
/* See if allowed to copy it */
|
|
|
|
srcAttribs = GetFileAttributesW(copyFrom);
|
2007-03-29 23:21:10 +02:00
|
|
|
WINE_TRACE("Source attribs: %d\n", srcAttribs);
|
|
|
|
|
2007-03-29 23:21:07 +02:00
|
|
|
if ((srcAttribs & FILE_ATTRIBUTE_HIDDEN) ||
|
|
|
|
(srcAttribs & FILE_ATTRIBUTE_SYSTEM)) {
|
|
|
|
|
|
|
|
if (!(flags & OPT_COPYHIDSYS)) {
|
|
|
|
skipFile = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-29 23:21:10 +02:00
|
|
|
if (!(srcAttribs & FILE_ATTRIBUTE_ARCHIVE) &&
|
|
|
|
(flags & OPT_ARCHIVEONLY)) {
|
|
|
|
skipFile = TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-29 23:21:01 +02:00
|
|
|
/* See if file exists */
|
|
|
|
destAttribs = GetFileAttributesW(copyTo);
|
2007-03-29 23:21:10 +02:00
|
|
|
WINE_TRACE("Dest attribs: %d\n", srcAttribs);
|
|
|
|
|
2007-03-30 20:20:18 +02:00
|
|
|
/* Check date ranges if a destination file already exists */
|
|
|
|
if (!skipFile && (flags & OPT_DATERANGE) &&
|
|
|
|
(CompareFileTime(&finddata->ftLastWriteTime, &dateRange) < 0)) {
|
|
|
|
WINE_TRACE("Skipping file as modified date too old\n");
|
|
|
|
skipFile = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If just /D supplied, only overwrite if src newer than dest */
|
|
|
|
if (!skipFile && (flags & OPT_DATENEWER) &&
|
|
|
|
(destAttribs != INVALID_FILE_ATTRIBUTES)) {
|
2008-09-04 14:08:19 +02:00
|
|
|
HANDLE h = CreateFileW(copyTo, GENERIC_READ, FILE_SHARE_READ,
|
2007-03-30 20:20:18 +02:00
|
|
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
|
|
|
|
NULL);
|
|
|
|
if (h != INVALID_HANDLE_VALUE) {
|
|
|
|
FILETIME writeTime;
|
|
|
|
GetFileTime(h, NULL, NULL, &writeTime);
|
|
|
|
|
|
|
|
if (CompareFileTime(&finddata->ftLastWriteTime, &writeTime) <= 0) {
|
|
|
|
WINE_TRACE("Skipping file as dest newer or same date\n");
|
|
|
|
skipFile = TRUE;
|
|
|
|
}
|
|
|
|
CloseHandle(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-30 20:20:19 +02:00
|
|
|
/* See if exclude list provided. Note since filenames are case
|
|
|
|
insensitive, need to uppercase the filename before doing
|
|
|
|
strstr */
|
|
|
|
if (!skipFile && (flags & OPT_EXCLUDELIST)) {
|
|
|
|
EXCLUDELIST *pos = excludeList;
|
|
|
|
WCHAR copyFromUpper[MAX_PATH];
|
|
|
|
|
|
|
|
/* Uppercase source filename */
|
|
|
|
lstrcpyW(copyFromUpper, copyFrom);
|
2008-09-04 14:08:19 +02:00
|
|
|
CharUpperBuffW(copyFromUpper, lstrlenW(copyFromUpper));
|
2007-03-30 20:20:19 +02:00
|
|
|
|
|
|
|
/* Loop through testing each exclude line */
|
|
|
|
while (pos) {
|
|
|
|
if (wcsstr(copyFromUpper, pos->name) != NULL) {
|
|
|
|
WINE_TRACE("Skipping file as matches exclude '%s'\n",
|
|
|
|
wine_dbgstr_w(pos->name));
|
|
|
|
skipFile = TRUE;
|
|
|
|
pos = NULL;
|
|
|
|
} else {
|
|
|
|
pos = pos->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prompt each file if necessary */
|
|
|
|
if (!skipFile && (flags & OPT_SRCPROMPT)) {
|
|
|
|
DWORD count;
|
|
|
|
char answer[10];
|
|
|
|
BOOL answered = FALSE;
|
2007-03-30 20:20:20 +02:00
|
|
|
WCHAR yesChar[2];
|
|
|
|
WCHAR noChar[2];
|
|
|
|
|
|
|
|
/* Read the Y and N characters from the resource file */
|
|
|
|
wcscpy(yesChar, XCOPY_LoadMessage(STRING_YES_CHAR));
|
|
|
|
wcscpy(noChar, XCOPY_LoadMessage(STRING_NO_CHAR));
|
2007-03-30 20:20:19 +02:00
|
|
|
|
|
|
|
while (!answered) {
|
2007-04-26 22:38:04 +02:00
|
|
|
XCOPY_wprintf(XCOPY_LoadMessage(STRING_SRCPROMPT), copyFrom);
|
2007-03-30 20:20:19 +02:00
|
|
|
ReadFile (GetStdHandle(STD_INPUT_HANDLE), answer, sizeof(answer),
|
|
|
|
&count, NULL);
|
|
|
|
|
|
|
|
answered = TRUE;
|
2007-03-30 20:20:20 +02:00
|
|
|
if (toupper(answer[0]) == noChar[0])
|
2007-03-30 20:20:19 +02:00
|
|
|
skipFile = TRUE;
|
2007-03-30 20:20:20 +02:00
|
|
|
else if (toupper(answer[0]) != yesChar[0])
|
2007-03-30 20:20:19 +02:00
|
|
|
answered = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-29 23:21:07 +02:00
|
|
|
if (!skipFile &&
|
|
|
|
destAttribs != INVALID_FILE_ATTRIBUTES && !(flags & OPT_NOPROMPT)) {
|
2007-03-29 23:21:01 +02:00
|
|
|
DWORD count;
|
|
|
|
char answer[10];
|
|
|
|
BOOL answered = FALSE;
|
2007-03-30 20:20:20 +02:00
|
|
|
WCHAR yesChar[2];
|
|
|
|
WCHAR allChar[2];
|
|
|
|
WCHAR noChar[2];
|
|
|
|
|
|
|
|
/* Read the A,Y and N characters from the resource file */
|
|
|
|
wcscpy(yesChar, XCOPY_LoadMessage(STRING_YES_CHAR));
|
|
|
|
wcscpy(allChar, XCOPY_LoadMessage(STRING_ALL_CHAR));
|
|
|
|
wcscpy(noChar, XCOPY_LoadMessage(STRING_NO_CHAR));
|
2007-03-29 23:21:01 +02:00
|
|
|
|
|
|
|
while (!answered) {
|
2007-04-26 22:38:04 +02:00
|
|
|
XCOPY_wprintf(XCOPY_LoadMessage(STRING_OVERWRITE), copyTo);
|
2007-03-29 23:21:01 +02:00
|
|
|
ReadFile (GetStdHandle(STD_INPUT_HANDLE), answer, sizeof(answer),
|
|
|
|
&count, NULL);
|
|
|
|
|
|
|
|
answered = TRUE;
|
2007-03-30 20:20:20 +02:00
|
|
|
if (toupper(answer[0]) == allChar[0])
|
2007-03-29 23:21:01 +02:00
|
|
|
flags |= OPT_NOPROMPT;
|
2007-03-30 20:20:20 +02:00
|
|
|
else if (toupper(answer[0]) == noChar[0])
|
2007-03-29 23:21:01 +02:00
|
|
|
skipFile = TRUE;
|
2007-03-30 20:20:20 +02:00
|
|
|
else if (toupper(answer[0]) != yesChar[0])
|
2007-03-29 23:21:01 +02:00
|
|
|
answered = FALSE;
|
|
|
|
}
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
|
|
|
|
2007-03-29 23:21:05 +02:00
|
|
|
/* See if it has to exist! */
|
|
|
|
if (destAttribs == INVALID_FILE_ATTRIBUTES && (flags & OPT_MUSTEXIST)) {
|
|
|
|
skipFile = TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-29 23:21:01 +02:00
|
|
|
/* Output a status message */
|
|
|
|
if (!skipFile) {
|
2020-10-21 01:02:39 +02:00
|
|
|
if (!(flags & OPT_QUIET)) {
|
|
|
|
if (flags & OPT_FULL)
|
|
|
|
XCOPY_wprintf(L"%1 -> %2\n", copyFrom, copyTo);
|
|
|
|
else
|
|
|
|
XCOPY_wprintf(L"%1\n", copyFrom);
|
2007-03-29 23:21:01 +02:00
|
|
|
}
|
|
|
|
|
2007-03-29 23:21:06 +02:00
|
|
|
/* If allowing overwriting of read only files, remove any
|
|
|
|
write protection */
|
|
|
|
if ((destAttribs & FILE_ATTRIBUTE_READONLY) &&
|
|
|
|
(flags & OPT_REPLACEREAD)) {
|
2008-09-04 14:08:19 +02:00
|
|
|
SetFileAttributesW(copyTo, destAttribs & ~FILE_ATTRIBUTE_READONLY);
|
2007-03-29 23:21:06 +02:00
|
|
|
}
|
|
|
|
|
2007-03-29 23:21:01 +02:00
|
|
|
copiedFile = TRUE;
|
|
|
|
if (flags & OPT_SIMULATE || flags & OPT_NOCOPY) {
|
|
|
|
/* Skip copy */
|
2008-09-04 14:08:19 +02:00
|
|
|
} else if (CopyFileW(copyFrom, copyTo, FALSE) == 0) {
|
2007-03-30 20:20:20 +02:00
|
|
|
|
|
|
|
DWORD error = GetLastError();
|
2007-04-26 22:38:04 +02:00
|
|
|
XCOPY_wprintf(XCOPY_LoadMessage(STRING_COPYFAIL),
|
2007-03-30 20:20:20 +02:00
|
|
|
copyFrom, copyTo, error);
|
|
|
|
XCOPY_FailMessage(error);
|
|
|
|
|
2007-03-29 23:21:08 +02:00
|
|
|
if (flags & OPT_IGNOREERRORS) {
|
|
|
|
skipFile = TRUE;
|
|
|
|
} else {
|
2007-10-24 23:02:43 +02:00
|
|
|
ret = RC_WRITEERROR;
|
|
|
|
goto cleanup;
|
2007-03-29 23:21:08 +02:00
|
|
|
}
|
2018-07-04 23:08:41 +02:00
|
|
|
} else {
|
2007-03-29 23:21:10 +02:00
|
|
|
|
2018-07-04 23:08:41 +02:00
|
|
|
if (!skipFile) {
|
|
|
|
/* If keeping attributes, update the destination attributes
|
|
|
|
otherwise remove the read only attribute */
|
|
|
|
if (flags & OPT_KEEPATTRS) {
|
|
|
|
SetFileAttributesW(copyTo, srcAttribs | FILE_ATTRIBUTE_ARCHIVE);
|
|
|
|
} else {
|
|
|
|
SetFileAttributesW(copyTo,
|
|
|
|
(GetFileAttributesW(copyTo) & ~FILE_ATTRIBUTE_READONLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If /M supplied, remove the archive bit after successful copy */
|
|
|
|
if ((srcAttribs & FILE_ATTRIBUTE_ARCHIVE) &&
|
|
|
|
(flags & OPT_REMOVEARCH)) {
|
|
|
|
SetFileAttributesW(copyFrom, (srcAttribs & ~FILE_ATTRIBUTE_ARCHIVE));
|
|
|
|
}
|
|
|
|
filesCopied++;
|
2007-03-29 23:21:10 +02:00
|
|
|
}
|
|
|
|
}
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find next file */
|
2008-09-04 14:08:19 +02:00
|
|
|
findres = FindNextFileW(h, finddata);
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
|
|
|
FindClose(h);
|
|
|
|
|
|
|
|
/* Search 2 - do subdirs */
|
|
|
|
if (flags & OPT_RECURSIVE) {
|
2018-06-24 22:44:14 +02:00
|
|
|
|
|
|
|
/* If /E is supplied, create the directory now */
|
|
|
|
if ((flags & OPT_EMPTYDIR) &&
|
|
|
|
!(flags & OPT_SIMULATE)) {
|
|
|
|
XCOPY_CreateDirectory(deststem);
|
|
|
|
}
|
|
|
|
|
2007-03-06 21:04:15 +01:00
|
|
|
lstrcpyW(inputpath, srcstem);
|
2020-10-21 01:02:40 +02:00
|
|
|
lstrcatW(inputpath, L"*");
|
2007-03-06 21:04:15 +01:00
|
|
|
findres = TRUE;
|
|
|
|
WINE_TRACE("Processing subdirs with spec: %s\n", wine_dbgstr_w(inputpath));
|
|
|
|
|
2008-09-04 14:08:19 +02:00
|
|
|
h = FindFirstFileW(inputpath, finddata);
|
2007-03-06 21:04:15 +01:00
|
|
|
while (h != INVALID_HANDLE_VALUE && findres) {
|
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Only looking for dirs */
|
|
|
|
if ((finddata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
|
2020-10-21 01:02:40 +02:00
|
|
|
(lstrcmpW(finddata->cFileName, L".") != 0) &&
|
|
|
|
(lstrcmpW(finddata->cFileName, L"..") != 0)) {
|
2011-10-18 16:43:04 +02:00
|
|
|
|
|
|
|
WINE_TRACE("Handling subdir: %s\n", wine_dbgstr_w(finddata->cFileName));
|
|
|
|
|
|
|
|
/* Make up recursive information */
|
|
|
|
lstrcpyW(inputpath, srcstem);
|
|
|
|
lstrcatW(inputpath, finddata->cFileName);
|
2020-10-21 01:02:40 +02:00
|
|
|
lstrcatW(inputpath, L"\\");
|
2011-10-18 16:43:04 +02:00
|
|
|
|
|
|
|
lstrcpyW(outputpath, deststem);
|
|
|
|
if (*destspec == 0x00) {
|
|
|
|
lstrcatW(outputpath, finddata->cFileName);
|
2020-10-21 01:02:40 +02:00
|
|
|
lstrcatW(outputpath, L"\\");
|
2011-10-18 16:43:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
XCOPY_DoCopy(inputpath, srcspec, outputpath, destspec, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find next one */
|
|
|
|
findres = FindNextFileW(h, finddata);
|
|
|
|
}
|
2012-11-05 22:53:39 +01:00
|
|
|
FindClose(h);
|
2011-10-18 16:43:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
|
|
|
|
/* free up memory */
|
|
|
|
HeapFree(GetProcessHeap(), 0, finddata);
|
|
|
|
HeapFree(GetProcessHeap(), 0, inputpath);
|
|
|
|
HeapFree(GetProcessHeap(), 0, outputpath);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* =========================================================================
|
|
|
|
XCOPY_ParseCommandLine - Parses the command line
|
|
|
|
========================================================================= */
|
2017-05-17 14:35:52 +02:00
|
|
|
static inline BOOL is_whitespace(WCHAR c)
|
2011-10-18 16:43:04 +02:00
|
|
|
{
|
|
|
|
return c == ' ' || c == '\t';
|
|
|
|
}
|
|
|
|
|
|
|
|
static WCHAR *skip_whitespace(WCHAR *p)
|
|
|
|
{
|
|
|
|
for (; *p && is_whitespace(*p); p++);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2017-05-17 14:35:52 +02:00
|
|
|
static inline BOOL is_digit(WCHAR c)
|
|
|
|
{
|
|
|
|
return c >= '0' && c <= '9';
|
|
|
|
}
|
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Windows XCOPY uses a simplified command line parsing algorithm
|
|
|
|
that lacks the escaped-quote logic of build_argv(), because
|
|
|
|
literal double quotes are illegal in any of its arguments.
|
|
|
|
Example: 'XCOPY "c:\DIR A" "c:DIR B\"' is OK. */
|
|
|
|
static int find_end_of_word(const WCHAR *word, WCHAR **end)
|
|
|
|
{
|
2013-10-15 00:27:18 +02:00
|
|
|
BOOL in_quotes = FALSE;
|
2011-10-18 16:43:04 +02:00
|
|
|
const WCHAR *ptr = word;
|
|
|
|
for (;;) {
|
|
|
|
for (; *ptr != '\0' && *ptr != '"' &&
|
|
|
|
(in_quotes || !is_whitespace(*ptr)); ptr++);
|
|
|
|
if (*ptr == '"') {
|
|
|
|
in_quotes = !in_quotes;
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
/* Odd number of double quotes is illegal for XCOPY */
|
|
|
|
if (in_quotes && *ptr == '\0')
|
|
|
|
return RC_INITERROR;
|
|
|
|
if (*ptr == '\0' || (!in_quotes && is_whitespace(*ptr)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*end = (WCHAR*)ptr;
|
|
|
|
return RC_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove all double quotes from a word */
|
|
|
|
static void strip_quotes(WCHAR *word, WCHAR **end)
|
|
|
|
{
|
|
|
|
WCHAR *rp, *wp;
|
|
|
|
for (rp = word, wp = word; *rp != '\0'; rp++) {
|
|
|
|
if (*rp == '"')
|
|
|
|
continue;
|
|
|
|
if (wp < rp)
|
|
|
|
*wp = *rp;
|
|
|
|
wp++;
|
|
|
|
}
|
|
|
|
*wp = '\0';
|
|
|
|
*end = wp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int XCOPY_ParseCommandLine(WCHAR *suppliedsource,
|
|
|
|
WCHAR *supplieddestination, DWORD *pflags)
|
|
|
|
{
|
|
|
|
DWORD flags = *pflags;
|
|
|
|
WCHAR *cmdline, *word, *end, *next;
|
|
|
|
int rc = RC_INITERROR;
|
|
|
|
|
|
|
|
cmdline = _wcsdup(GetCommandLineW());
|
|
|
|
if (cmdline == NULL)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* Skip first arg, which is the program name */
|
|
|
|
if ((rc = find_end_of_word(cmdline, &word)) != RC_OK)
|
|
|
|
goto out;
|
|
|
|
word = skip_whitespace(word);
|
|
|
|
|
|
|
|
while (*word)
|
|
|
|
{
|
|
|
|
WCHAR first;
|
|
|
|
if ((rc = find_end_of_word(word, &end)) != RC_OK)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
next = skip_whitespace(end);
|
|
|
|
first = word[0];
|
|
|
|
*end = '\0';
|
|
|
|
strip_quotes(word, &end);
|
|
|
|
WINE_TRACE("Processing Arg: '%s'\n", wine_dbgstr_w(word));
|
|
|
|
|
|
|
|
/* First non-switch parameter is source, second is destination */
|
|
|
|
if (first != '/') {
|
|
|
|
if (suppliedsource[0] == 0x00) {
|
|
|
|
lstrcpyW(suppliedsource, word);
|
|
|
|
} else if (supplieddestination[0] == 0x00) {
|
|
|
|
lstrcpyW(supplieddestination, word);
|
|
|
|
} else {
|
|
|
|
XCOPY_wprintf(XCOPY_LoadMessage(STRING_INVPARMS));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Process all the switch options
|
|
|
|
Note: Windows docs say /P prompts when dest is created
|
|
|
|
but tests show it is done for each src file
|
|
|
|
regardless of the destination */
|
2018-06-24 22:44:12 +02:00
|
|
|
int skip=0;
|
|
|
|
WCHAR *rest;
|
|
|
|
|
|
|
|
while (word[0]) {
|
|
|
|
rest = NULL;
|
|
|
|
|
|
|
|
switch (toupper(word[1])) {
|
|
|
|
case 'I': flags |= OPT_ASSUMEDIR; break;
|
|
|
|
case 'S': flags |= OPT_RECURSIVE; break;
|
|
|
|
case 'Q': flags |= OPT_QUIET; break;
|
|
|
|
case 'F': flags |= OPT_FULL; break;
|
|
|
|
case 'L': flags |= OPT_SIMULATE; break;
|
|
|
|
case 'W': flags |= OPT_PAUSE; break;
|
|
|
|
case 'T': flags |= OPT_NOCOPY | OPT_RECURSIVE; break;
|
|
|
|
case 'Y': flags |= OPT_NOPROMPT; break;
|
|
|
|
case 'N': flags |= OPT_SHORTNAME; break;
|
|
|
|
case 'U': flags |= OPT_MUSTEXIST; break;
|
|
|
|
case 'R': flags |= OPT_REPLACEREAD; break;
|
2018-07-04 23:08:41 +02:00
|
|
|
case 'K': flags |= OPT_KEEPATTRS; break;
|
2018-06-24 22:44:12 +02:00
|
|
|
case 'H': flags |= OPT_COPYHIDSYS; break;
|
|
|
|
case 'C': flags |= OPT_IGNOREERRORS; break;
|
|
|
|
case 'P': flags |= OPT_SRCPROMPT; break;
|
|
|
|
case 'A': flags |= OPT_ARCHIVEONLY; break;
|
|
|
|
case 'M': flags |= OPT_ARCHIVEONLY |
|
|
|
|
OPT_REMOVEARCH; break;
|
|
|
|
|
|
|
|
/* E can be /E or /EXCLUDE */
|
2020-10-21 01:02:40 +02:00
|
|
|
case 'E': if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT,
|
|
|
|
&word[1], 8, L"EXCLUDE:", -1) == CSTR_EQUAL) {
|
2018-06-24 22:44:12 +02:00
|
|
|
if (XCOPY_ProcessExcludeList(&word[9])) {
|
|
|
|
XCOPY_FailMessage(ERROR_INVALID_PARAMETER);
|
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
flags |= OPT_EXCLUDELIST;
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2018-06-24 22:44:12 +02:00
|
|
|
/* Do not support concatenated switches onto exclude lists yet */
|
|
|
|
rest = end;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
flags |= OPT_EMPTYDIR | OPT_RECURSIVE;
|
2011-10-18 16:43:04 +02:00
|
|
|
}
|
2018-06-24 22:44:12 +02:00
|
|
|
break;
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2018-06-24 22:44:12 +02:00
|
|
|
/* D can be /D or /D: */
|
|
|
|
case 'D': if (word[2]==':' && is_digit(word[3])) {
|
2011-10-18 16:43:04 +02:00
|
|
|
SYSTEMTIME st;
|
2018-06-24 22:44:12 +02:00
|
|
|
WCHAR *pos = &word[3];
|
|
|
|
BOOL isError = FALSE;
|
|
|
|
memset(&st, 0x00, sizeof(st));
|
|
|
|
|
|
|
|
/* Microsoft xcopy's usage message implies that the date
|
|
|
|
* format depends on the locale, but that is false.
|
|
|
|
* It is hardcoded to month-day-year.
|
|
|
|
*/
|
|
|
|
st.wMonth = _wtol(pos);
|
|
|
|
while (*pos && is_digit(*pos)) pos++;
|
|
|
|
if (*pos++ != '-') isError = TRUE;
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2018-06-24 22:44:12 +02:00
|
|
|
if (!isError) {
|
|
|
|
st.wDay = _wtol(pos);
|
|
|
|
while (*pos && is_digit(*pos)) pos++;
|
|
|
|
if (*pos++ != '-') isError = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isError) {
|
|
|
|
st.wYear = _wtol(pos);
|
|
|
|
while (*pos && is_digit(*pos)) pos++;
|
|
|
|
if (st.wYear < 100) st.wYear+=2000;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle switches straight after the supplied date */
|
|
|
|
rest = pos;
|
|
|
|
|
|
|
|
if (!isError && SystemTimeToFileTime(&st, &dateRange)) {
|
|
|
|
SYSTEMTIME st;
|
|
|
|
WCHAR datestring[32], timestring[32];
|
|
|
|
|
|
|
|
flags |= OPT_DATERANGE;
|
|
|
|
|
|
|
|
/* Debug info: */
|
|
|
|
FileTimeToSystemTime (&dateRange, &st);
|
|
|
|
GetDateFormatW(0, DATE_SHORTDATE, &st, NULL, datestring,
|
2018-07-13 19:01:26 +02:00
|
|
|
ARRAY_SIZE(datestring));
|
2018-06-24 22:44:12 +02:00
|
|
|
GetTimeFormatW(0, TIME_NOSECONDS, &st,
|
2018-07-13 19:01:26 +02:00
|
|
|
NULL, timestring, ARRAY_SIZE(timestring));
|
2018-06-24 22:44:12 +02:00
|
|
|
|
|
|
|
WINE_TRACE("Date being used is: %s %s\n",
|
|
|
|
wine_dbgstr_w(datestring), wine_dbgstr_w(timestring));
|
|
|
|
} else {
|
|
|
|
XCOPY_FailMessage(ERROR_INVALID_PARAMETER);
|
|
|
|
goto out;
|
|
|
|
}
|
2011-10-18 16:43:04 +02:00
|
|
|
} else {
|
2018-06-24 22:44:12 +02:00
|
|
|
flags |= OPT_DATENEWER;
|
2011-10-18 16:43:04 +02:00
|
|
|
}
|
2018-06-24 22:44:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '-': if (toupper(word[2])=='Y') {
|
|
|
|
flags &= ~OPT_NOPROMPT;
|
|
|
|
rest = &word[3]; /* Skip over 3 characters */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '?': XCOPY_wprintf(XCOPY_LoadMessage(STRING_HELP));
|
|
|
|
rc = RC_HELP;
|
|
|
|
goto out;
|
|
|
|
case 'V':
|
|
|
|
WINE_FIXME("ignoring /V\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WINE_TRACE("Unhandled parameter '%s'\n", wine_dbgstr_w(word));
|
|
|
|
XCOPY_wprintf(XCOPY_LoadMessage(STRING_INVPARM), word);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-08-23 16:43:57 +02:00
|
|
|
/* Unless overridden above, skip over the '/' and the first character */
|
2018-06-24 22:44:12 +02:00
|
|
|
if (rest == NULL) rest = &word[2];
|
|
|
|
|
|
|
|
/* By now, rest should point either to the null after the
|
|
|
|
switch, or the beginning of the next switch if there
|
|
|
|
was no whitespace between them */
|
|
|
|
if (!skip && *rest && *rest != '/') {
|
|
|
|
WINE_FIXME("Unexpected characters found and ignored '%s'\n", wine_dbgstr_w(rest));
|
|
|
|
skip=1;
|
|
|
|
} else {
|
|
|
|
word = rest;
|
|
|
|
}
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
|
|
|
}
|
2011-10-18 16:43:04 +02:00
|
|
|
word = next;
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Default the destination if not supplied */
|
|
|
|
if (supplieddestination[0] == 0x00)
|
2020-10-21 01:02:40 +02:00
|
|
|
lstrcpyW(supplieddestination, L".");
|
2007-10-24 23:02:43 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
*pflags = flags;
|
|
|
|
rc = RC_OK;
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
out:
|
|
|
|
free(cmdline);
|
|
|
|
return rc;
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
|
2007-03-06 21:04:15 +01:00
|
|
|
/* =========================================================================
|
2011-10-18 16:43:04 +02:00
|
|
|
XCOPY_ProcessSourceParm - Takes the supplied source parameter, and
|
|
|
|
converts it into a stem and a filespec
|
|
|
|
========================================================================= */
|
|
|
|
static int XCOPY_ProcessSourceParm(WCHAR *suppliedsource, WCHAR *stem,
|
|
|
|
WCHAR *spec, DWORD flags)
|
2007-03-06 21:04:15 +01:00
|
|
|
{
|
2011-10-18 16:43:04 +02:00
|
|
|
WCHAR actualsource[MAX_PATH];
|
|
|
|
WCHAR *starPos;
|
|
|
|
WCHAR *questPos;
|
|
|
|
DWORD attribs;
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/*
|
|
|
|
* Validate the source, expanding to full path ensuring it exists
|
|
|
|
*/
|
|
|
|
if (GetFullPathNameW(suppliedsource, MAX_PATH, actualsource, NULL) == 0) {
|
|
|
|
WINE_FIXME("Unexpected failure expanding source path (%d)\n", GetLastError());
|
|
|
|
return RC_INITERROR;
|
|
|
|
}
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* If full names required, convert to using the full path */
|
|
|
|
if (flags & OPT_FULL) {
|
|
|
|
lstrcpyW(suppliedsource, actualsource);
|
|
|
|
}
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/*
|
|
|
|
* Work out the stem of the source
|
|
|
|
*/
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* If a directory is supplied, use that as-is (either fully or
|
|
|
|
partially qualified)
|
|
|
|
If a filename is supplied + a directory or drive path, use that
|
|
|
|
as-is
|
|
|
|
Otherwise
|
|
|
|
If no directory or path specified, add eg. C:
|
|
|
|
stem is Drive/Directory is bit up to last \ (or first :)
|
|
|
|
spec is bit after that */
|
2007-03-06 21:04:15 +01:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
starPos = wcschr(suppliedsource, '*');
|
|
|
|
questPos = wcschr(suppliedsource, '?');
|
|
|
|
if (starPos || questPos) {
|
|
|
|
attribs = 0x00; /* Ensures skips invalid or directory check below */
|
|
|
|
} else {
|
|
|
|
attribs = GetFileAttributesW(actualsource);
|
2007-03-06 21:04:15 +01:00
|
|
|
}
|
2007-03-30 20:20:17 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
if (attribs == INVALID_FILE_ATTRIBUTES) {
|
|
|
|
XCOPY_FailMessage(GetLastError());
|
|
|
|
return RC_INITERROR;
|
2007-03-30 20:20:17 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Directory:
|
|
|
|
stem should be exactly as supplied plus a '\', unless it was
|
|
|
|
eg. C: in which case no slash required */
|
|
|
|
} else if (attribs & FILE_ATTRIBUTE_DIRECTORY) {
|
|
|
|
WCHAR lastChar;
|
2007-03-30 20:20:17 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
WINE_TRACE("Directory supplied\n");
|
|
|
|
lstrcpyW(stem, suppliedsource);
|
|
|
|
lastChar = stem[lstrlenW(stem)-1];
|
2020-10-21 01:02:40 +02:00
|
|
|
if (lastChar != '\\' && lastChar != ':')
|
|
|
|
lstrcatW(stem, L"\\");
|
|
|
|
lstrcpyW(spec, L"*");
|
2007-03-30 20:20:17 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* File or wildcard search:
|
|
|
|
stem should be:
|
|
|
|
Up to and including last slash if directory path supplied
|
|
|
|
If c:filename supplied, just the c:
|
|
|
|
Otherwise stem should be the current drive letter + ':' */
|
|
|
|
} else {
|
|
|
|
WCHAR *lastDir;
|
2007-03-30 20:20:17 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
WINE_TRACE("Filename supplied\n");
|
|
|
|
lastDir = wcsrchr(suppliedsource, '\\');
|
2007-03-30 20:20:17 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
if (lastDir) {
|
|
|
|
lstrcpyW(stem, suppliedsource);
|
|
|
|
stem[(lastDir-suppliedsource) + 1] = 0x00;
|
|
|
|
lstrcpyW(spec, (lastDir+1));
|
|
|
|
} else if (suppliedsource[1] == ':') {
|
|
|
|
lstrcpyW(stem, suppliedsource);
|
|
|
|
stem[2] = 0x00;
|
|
|
|
lstrcpyW(spec, suppliedsource+2);
|
|
|
|
} else {
|
|
|
|
WCHAR curdir[MAXSTRING];
|
2018-07-13 19:01:26 +02:00
|
|
|
GetCurrentDirectoryW(ARRAY_SIZE(curdir), curdir);
|
2011-10-18 16:43:04 +02:00
|
|
|
stem[0] = curdir[0];
|
|
|
|
stem[1] = curdir[1];
|
|
|
|
stem[2] = 0x00;
|
|
|
|
lstrcpyW(spec, suppliedsource);
|
2007-03-30 20:20:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
return RC_OK;
|
2007-03-30 20:20:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* =========================================================================
|
2011-10-18 16:43:04 +02:00
|
|
|
XCOPY_ProcessDestParm - Takes the supplied destination parameter, and
|
|
|
|
converts it into a stem
|
|
|
|
========================================================================= */
|
|
|
|
static int XCOPY_ProcessDestParm(WCHAR *supplieddestination, WCHAR *stem, WCHAR *spec,
|
|
|
|
WCHAR *srcspec, DWORD flags)
|
|
|
|
{
|
|
|
|
WCHAR actualdestination[MAX_PATH];
|
|
|
|
DWORD attribs;
|
|
|
|
BOOL isDir = FALSE;
|
2007-03-30 20:20:17 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/*
|
|
|
|
* Validate the source, expanding to full path ensuring it exists
|
|
|
|
*/
|
|
|
|
if (GetFullPathNameW(supplieddestination, MAX_PATH, actualdestination, NULL) == 0) {
|
|
|
|
WINE_FIXME("Unexpected failure expanding source path (%d)\n", GetLastError());
|
|
|
|
return RC_INITERROR;
|
2007-03-30 20:20:17 +02:00
|
|
|
}
|
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Destination is either a directory or a file */
|
|
|
|
attribs = GetFileAttributesW(actualdestination);
|
2007-03-30 20:20:17 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
if (attribs == INVALID_FILE_ATTRIBUTES) {
|
2007-03-30 20:20:17 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* If /I supplied and wildcard copy, assume directory */
|
|
|
|
/* Also if destination ends with backslash */
|
|
|
|
if ((flags & OPT_ASSUMEDIR &&
|
|
|
|
(wcschr(srcspec, '?') || wcschr(srcspec, '*'))) ||
|
|
|
|
(supplieddestination[lstrlenW(supplieddestination)-1] == '\\')) {
|
2007-03-30 20:20:17 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
isDir = TRUE;
|
2007-03-30 20:20:17 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
} else {
|
|
|
|
DWORD count;
|
|
|
|
char answer[10] = "";
|
|
|
|
WCHAR fileChar[2];
|
|
|
|
WCHAR dirChar[2];
|
2007-03-30 20:20:20 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Read the F and D characters from the resource file */
|
|
|
|
wcscpy(fileChar, XCOPY_LoadMessage(STRING_FILE_CHAR));
|
|
|
|
wcscpy(dirChar, XCOPY_LoadMessage(STRING_DIR_CHAR));
|
2007-03-30 20:20:20 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
while (answer[0] != fileChar[0] && answer[0] != dirChar[0]) {
|
|
|
|
XCOPY_wprintf(XCOPY_LoadMessage(STRING_QISDIR), supplieddestination);
|
|
|
|
|
|
|
|
ReadFile(GetStdHandle(STD_INPUT_HANDLE), answer, sizeof(answer), &count, NULL);
|
|
|
|
WINE_TRACE("User answer %c\n", answer[0]);
|
|
|
|
|
|
|
|
answer[0] = toupper(answer[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (answer[0] == dirChar[0]) {
|
|
|
|
isDir = TRUE;
|
|
|
|
} else {
|
|
|
|
isDir = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
isDir = (attribs & FILE_ATTRIBUTE_DIRECTORY);
|
2007-03-30 20:20:20 +02:00
|
|
|
}
|
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
if (isDir) {
|
|
|
|
lstrcpyW(stem, actualdestination);
|
|
|
|
*spec = 0x00;
|
|
|
|
|
|
|
|
/* Ensure ends with a '\' */
|
2020-10-21 01:02:40 +02:00
|
|
|
if (stem[lstrlenW(stem)-1] != '\\')
|
|
|
|
lstrcatW(stem, L"\\");
|
2007-03-30 20:20:20 +02:00
|
|
|
|
|
|
|
} else {
|
2011-10-18 16:43:04 +02:00
|
|
|
WCHAR drive[MAX_PATH];
|
|
|
|
WCHAR dir[MAX_PATH];
|
|
|
|
WCHAR fname[MAX_PATH];
|
|
|
|
WCHAR ext[MAX_PATH];
|
|
|
|
_wsplitpath(actualdestination, drive, dir, fname, ext);
|
|
|
|
lstrcpyW(stem, drive);
|
|
|
|
lstrcatW(stem, dir);
|
|
|
|
lstrcpyW(spec, fname);
|
|
|
|
lstrcatW(spec, ext);
|
2007-03-30 20:20:20 +02:00
|
|
|
}
|
2011-10-18 16:43:04 +02:00
|
|
|
return RC_OK;
|
2007-03-30 20:20:20 +02:00
|
|
|
}
|
2007-04-26 22:38:04 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
|
2007-04-26 22:38:04 +02:00
|
|
|
/* =========================================================================
|
2011-10-18 16:43:04 +02:00
|
|
|
main - Main entrypoint for the xcopy command
|
2007-04-26 22:38:04 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
Processes the args, and drives the actual copying
|
|
|
|
========================================================================= */
|
2019-10-17 17:05:47 +02:00
|
|
|
int __cdecl wmain (int argc, WCHAR *argvW[])
|
2011-10-18 16:43:04 +02:00
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
WCHAR suppliedsource[MAX_PATH] = {0}; /* As supplied on the cmd line */
|
|
|
|
WCHAR supplieddestination[MAX_PATH] = {0};
|
|
|
|
WCHAR sourcestem[MAX_PATH] = {0}; /* Stem of source */
|
|
|
|
WCHAR sourcespec[MAX_PATH] = {0}; /* Filespec of source */
|
|
|
|
WCHAR destinationstem[MAX_PATH] = {0}; /* Stem of destination */
|
|
|
|
WCHAR destinationspec[MAX_PATH] = {0}; /* Filespec of destination */
|
|
|
|
WCHAR copyCmd[MAXSTRING]; /* COPYCMD env var */
|
|
|
|
DWORD flags = 0; /* Option flags */
|
2007-04-26 22:38:04 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Preinitialize flags based on COPYCMD */
|
2020-10-21 01:02:40 +02:00
|
|
|
if (GetEnvironmentVariableW(L"COPYCMD", copyCmd, MAXSTRING)) {
|
|
|
|
if (wcsstr(copyCmd, L"/Y") != NULL || wcsstr(copyCmd, L"/y") != NULL)
|
2011-10-18 16:43:04 +02:00
|
|
|
flags |= OPT_NOPROMPT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: On UNIX, files starting with a '.' are treated as hidden under
|
|
|
|
wine, but on windows these can be normal files. At least one installer
|
|
|
|
uses files such as .packlist and (validly) expects them to be copied.
|
|
|
|
Under wine, if we do not copy hidden files by default then they get
|
|
|
|
lose */
|
|
|
|
flags |= OPT_COPYHIDSYS;
|
2007-04-26 22:38:04 +02:00
|
|
|
|
|
|
|
/*
|
2011-10-18 16:43:04 +02:00
|
|
|
* Parse the command line
|
2007-04-26 22:38:04 +02:00
|
|
|
*/
|
2011-10-18 16:43:04 +02:00
|
|
|
if ((rc = XCOPY_ParseCommandLine(suppliedsource, supplieddestination,
|
|
|
|
&flags)) != RC_OK) {
|
|
|
|
if (rc == RC_HELP)
|
|
|
|
return RC_OK;
|
|
|
|
else
|
|
|
|
return rc;
|
2007-04-26 22:38:04 +02:00
|
|
|
}
|
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Trace out the supplied information */
|
|
|
|
WINE_TRACE("Supplied parameters:\n");
|
|
|
|
WINE_TRACE("Source : '%s'\n", wine_dbgstr_w(suppliedsource));
|
|
|
|
WINE_TRACE("Destination : '%s'\n", wine_dbgstr_w(supplieddestination));
|
2007-04-26 22:38:04 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Extract required information from source specification */
|
|
|
|
rc = XCOPY_ProcessSourceParm(suppliedsource, sourcestem, sourcespec, flags);
|
|
|
|
if (rc != RC_OK) return rc;
|
2007-04-26 22:38:04 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Extract required information from destination specification */
|
|
|
|
rc = XCOPY_ProcessDestParm(supplieddestination, destinationstem,
|
|
|
|
destinationspec, sourcespec, flags);
|
|
|
|
if (rc != RC_OK) return rc;
|
2007-04-26 22:38:04 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Trace out the resulting information */
|
|
|
|
WINE_TRACE("Resolved parameters:\n");
|
|
|
|
WINE_TRACE("Source Stem : '%s'\n", wine_dbgstr_w(sourcestem));
|
|
|
|
WINE_TRACE("Source Spec : '%s'\n", wine_dbgstr_w(sourcespec));
|
|
|
|
WINE_TRACE("Dest Stem : '%s'\n", wine_dbgstr_w(destinationstem));
|
|
|
|
WINE_TRACE("Dest Spec : '%s'\n", wine_dbgstr_w(destinationspec));
|
2007-04-26 22:38:04 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Pause if necessary */
|
|
|
|
if (flags & OPT_PAUSE) {
|
|
|
|
DWORD count;
|
|
|
|
char pausestr[10];
|
2007-04-26 22:38:04 +02:00
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
XCOPY_wprintf(XCOPY_LoadMessage(STRING_PAUSE));
|
|
|
|
ReadFile (GetStdHandle(STD_INPUT_HANDLE), pausestr, sizeof(pausestr),
|
|
|
|
&count, NULL);
|
2007-04-26 22:38:04 +02:00
|
|
|
}
|
|
|
|
|
2011-10-18 16:43:04 +02:00
|
|
|
/* Now do the hard work... */
|
|
|
|
rc = XCOPY_DoCopy(sourcestem, sourcespec,
|
|
|
|
destinationstem, destinationspec,
|
|
|
|
flags);
|
|
|
|
|
|
|
|
/* Clear up exclude list allocated memory */
|
|
|
|
while (excludeList) {
|
|
|
|
EXCLUDELIST *pos = excludeList;
|
|
|
|
excludeList = excludeList -> next;
|
|
|
|
HeapFree(GetProcessHeap(), 0, pos->name);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pos);
|
2007-04-26 22:38:04 +02:00
|
|
|
}
|
2011-10-18 16:43:04 +02:00
|
|
|
|
|
|
|
/* Finished - print trailer and exit */
|
|
|
|
if (flags & OPT_SIMULATE) {
|
|
|
|
XCOPY_wprintf(XCOPY_LoadMessage(STRING_SIMCOPY), filesCopied);
|
|
|
|
} else if (!(flags & OPT_NOCOPY)) {
|
|
|
|
XCOPY_wprintf(XCOPY_LoadMessage(STRING_COPY), filesCopied);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
|
2007-04-26 22:38:04 +02:00
|
|
|
}
|