(Brandon Turner) <turnerb7@msu.edu>) Fixed bug to allow MS style wildcards + code clean up added /y and /-y

svn path=/trunk/; revision=16248
This commit is contained in:
Magnus Olsen 2005-06-23 18:12:17 +00:00
parent f887cf0f05
commit 366a911edc

View file

@ -23,6 +23,10 @@
*
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
* Remove all hardcode string to En.rc
*
* 24-Jun-2005 (Brandon Turner) <turnerb7@msu.edu>)
* Fixed bug to allow MS style wildcards + code clean up
* added /y and /-y
*/
#include "precomp.h"
@ -31,32 +35,22 @@
#ifdef INCLUDE_CMD_MOVE
#define OVERWRITE_NO 0
#define OVERWRITE_YES 1
#define OVERWRITE_ALL 2
#define OVERWRITE_CANCEL 3
enum
{
MOVE_NOTHING = 0x001, /* /N */
MOVE_OVER_YES = 0x002, /* /Y */
MOVE_OVER_NO = 0x004, /* /-Y */
};
static INT Overwrite (LPTSTR fn)
{
/*ask the user if they want to override*/
TCHAR szMsg[RC_STRING_MAX_SIZE];
TCHAR inp[10];
LPTSTR p;
INT res;
LoadString(CMD_ModuleHandle, STRING_MOVE_HELP1, szMsg, RC_STRING_MAX_SIZE);
ConOutPrintf(szMsg,fn);
ConInString(inp, 10);
_tcsupr (inp);
for (p = inp; _istspace(*p); p++)
;
if (*p != szMsg[0] && *p != szMsg[2])
return OVERWRITE_NO;
if (*p == szMsg[2])
return OVERWRITE_ALL;
return OVERWRITE_YES;
res = FilePromptYNA ("");
return res;
}
@ -68,12 +62,12 @@ INT cmd_move (LPTSTR cmd, LPTSTR param)
INT argc, i, nFiles;
TCHAR szDestPath[MAX_PATH];
TCHAR szSrcPath[MAX_PATH];
BOOL bPrompt = TRUE;
LPTSTR p;
DWORD dwFlags = 0;
INT nOverwrite = 0;
WIN32_FIND_DATA findBuffer;
HANDLE hFile;
LPTSTR pszFile;
BOOL bNothing = FALSE;
if (!_tcsncmp (param, _T("/?"), 2))
{
@ -103,23 +97,24 @@ INT cmd_move (LPTSTR cmd, LPTSTR param)
/* read options */
for (i = 0; i < argc; i++)
{
p = arg[i];
if (*arg[i] == _T('/'))
{
if (_tcslen(arg[i]) >= 2)
{
switch (_totupper(arg[i][1]))
{
case _T('N'):
dwFlags |= MOVE_NOTHING;
break;
if (*p == _T('/'))
{
p++;
if (*p == _T('-'))
{
p++;
if (_totupper (*p) == _T('Y'))
bPrompt = TRUE;
case _T('Y'):
dwFlags |= MOVE_OVER_YES;
break;
case _T('-'):
dwFlags |= MOVE_OVER_NO;
break;
}
else
{
if (_totupper (*p) == _T('Y'))
bPrompt = FALSE;
else if (_totupper (*p) == _T('N'))
bNothing = TRUE;
}
nFiles--;
}
@ -132,6 +127,13 @@ INT cmd_move (LPTSTR cmd, LPTSTR param)
return 1;
}
if (_tcschr (arg[argc - 1], _T('*')) != NULL)
{
/*'*' in dest, this doesnt happen. give folder name instead*/
error_parameter_format('2');
return 1;
}
/* get destination */
GetFullPathName (arg[argc - 1], MAX_PATH, szDestPath, NULL);
#ifdef _DEBUG
@ -154,6 +156,8 @@ INT cmd_move (LPTSTR cmd, LPTSTR param)
do
{
nOverwrite = 1;
GetFullPathName (findBuffer.cFileName, MAX_PATH, szSrcPath, &pszFile);
if (GetFileAttributes (szSrcPath) & FILE_ATTRIBUTE_DIRECTORY)
@ -164,91 +168,98 @@ INT cmd_move (LPTSTR cmd, LPTSTR param)
DebugPrintf (_T("Move directory \'%s\' to \'%s\'\n"),
szSrcPath, szDestPath);
#endif
if (!bNothing)
{
if (!(dwFlags & MOVE_NOTHING))
continue;
MoveFile (szSrcPath, szDestPath);
}
}
else
{
/* source is file */
if (IsExistingFile (szDestPath))
{
/* destination exists */
if (GetFileAttributes (szDestPath) & FILE_ATTRIBUTE_DIRECTORY)
{
/* destination is existing directory */
/*build the dest string(accounts for *)*/
TCHAR szFullDestPath[MAX_PATH];
_tcscpy (szFullDestPath, szDestPath);
_tcscat (szFullDestPath, _T("\\"));
_tcscat (szFullDestPath, pszFile);
/*this line causes a one to many slashes, GetFullPathName must
be adding on a \ when it sees that is a dir*/
//_tcscat (szFullDestPath, _T("\\"));
_tcscat (szFullDestPath, findBuffer.cFileName);
/*checks to make sure user wanted/wants the override*/
if((dwFlags & MOVE_OVER_NO) && IsExistingFile (szFullDestPath))
continue;
if(!(dwFlags & MOVE_OVER_YES) && IsExistingFile (szFullDestPath))
nOverwrite = Overwrite (szFullDestPath);
if (nOverwrite == PROMPT_NO || nOverwrite == PROMPT_BREAK)
continue;
if (nOverwrite == PROMPT_ALL)
dwFlags |= MOVE_OVER_YES;
/*delete the file that might be there first*/
DeleteFile(szFullDestPath);
ConOutPrintf (_T("%s => %s"), szSrcPath, szFullDestPath);
if (!bNothing)
{
if ((dwFlags & MOVE_NOTHING))
continue;
/*delete the file that might be there first*/
DeleteFile(szFullDestPath);
/*move the file*/
if (MoveFile (szSrcPath, szFullDestPath))
LoadString(CMD_ModuleHandle, STRING_MOVE_ERROR1, szMsg, RC_STRING_MAX_SIZE);
else
LoadString(CMD_ModuleHandle, STRING_MOVE_ERROR2, szMsg, RC_STRING_MAX_SIZE);
ConOutPrintf(szMsg);
}
}
else
{
/* destination is existing file */
INT nOverwrite;
/* destination is a file */
/* must get the overwrite code */
if ((nOverwrite = Overwrite (szDestPath)))
if (_tcschr (arg[argc - 2], _T('*')) != NULL)
{
#if 0
if (nOverwrite == OVERWRITE_ALL)
*lpFlags |= FLAG_OVERWRITE_ALL;
#endif
/*'*' in src but there should't be one in the dest*/
error_parameter_format('1');
return 1;
}
/*bunch of checks to see if we the user wanted/wants
to really override the files*/
if((dwFlags & MOVE_OVER_NO) && IsExistingFile (szDestPath))
continue;
if(!(dwFlags & MOVE_OVER_YES) && IsExistingFile (szDestPath))
nOverwrite = Overwrite (szDestPath);
if (nOverwrite == PROMPT_NO || nOverwrite == PROMPT_BREAK)
continue;
if (nOverwrite == PROMPT_ALL)
dwFlags |= MOVE_OVER_YES;
ConOutPrintf (_T("%s => %s"), szSrcPath, szDestPath);
if (!bNothing)
{
if ((dwFlags & MOVE_NOTHING))
continue;
/*delete the file first just to get ride of it
if it was already there*/
DeleteFile(szDestPath);
/*do the moving*/
if (MoveFile (szSrcPath, szDestPath))
LoadString(CMD_ModuleHandle, STRING_MOVE_ERROR1, szMsg, RC_STRING_MAX_SIZE);
else
LoadString(CMD_ModuleHandle, STRING_MOVE_ERROR2, szMsg, RC_STRING_MAX_SIZE);
ConOutPrintf(szMsg);
}
}
}
}
else
{
/* destination does not exist */
TCHAR szFullDestPath[MAX_PATH];
GetFullPathName (szDestPath, MAX_PATH, szFullDestPath, NULL);
ConOutPrintf (_T("%s => %s"), szSrcPath, szFullDestPath);
if (!bNothing)
{
if (MoveFile (szSrcPath, szFullDestPath))
LoadString(CMD_ModuleHandle, STRING_MOVE_ERROR1, szMsg, RC_STRING_MAX_SIZE);
else
LoadString(CMD_ModuleHandle, STRING_MOVE_ERROR2, szMsg, RC_STRING_MAX_SIZE);
ConOutPrintf(szMsg);
}
}
}
}
while (FindNextFile (hFile, &findBuffer));
FindClose (hFile);
}
freep (arg);
return 0;
}