mirror of
https://github.com/reactos/reactos.git
synced 2025-02-20 15:35:04 +00:00
Various cmd fixes by Carlo Bramini (carlo DOT bramix AT libero DOT it)
See issue #2232 for more details. svn path=/trunk/; revision=28022
This commit is contained in:
parent
8fd67d96e0
commit
ddfbe083e9
3 changed files with 29 additions and 47 deletions
|
@ -66,7 +66,6 @@ copy (TCHAR source[MAX_PATH],
|
|||
DWORD dwAttrib;
|
||||
DWORD dwRead;
|
||||
DWORD dwWritten;
|
||||
DWORD i;
|
||||
BOOL bEof = FALSE;
|
||||
TCHAR TrueDest[MAX_PATH];
|
||||
TCHAR TempSrc[MAX_PATH];
|
||||
|
@ -168,7 +167,6 @@ copy (TCHAR source[MAX_PATH],
|
|||
}
|
||||
|
||||
|
||||
|
||||
if (!IsExistingFile (dest))
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
|
@ -231,7 +229,9 @@ copy (TCHAR source[MAX_PATH],
|
|||
nErrorLevel = 1;
|
||||
return 0;
|
||||
}
|
||||
buffer = (LPBYTE)malloc (BUFF_SIZE);
|
||||
|
||||
/* A page-aligned buffer usually give more speed */
|
||||
buffer = (LPBYTE)VirtualAlloc(NULL, BUFF_SIZE, MEM_COMMIT, PAGE_READWRITE);
|
||||
if (buffer == NULL)
|
||||
{
|
||||
CloseHandle (hFileDest);
|
||||
|
@ -247,16 +247,13 @@ copy (TCHAR source[MAX_PATH],
|
|||
ReadFile (hFileSrc, buffer, BUFF_SIZE, &dwRead, NULL);
|
||||
if (lpdwFlags & COPY_ASCII)
|
||||
{
|
||||
for (i = 0; i < dwRead; i++)
|
||||
LPBYTE pEof = memchr(buffer, 0x1A, dwRead);
|
||||
if (pEof != NULL)
|
||||
{
|
||||
/* we're dealing with ASCII files! */
|
||||
if (((LPSTR)buffer)[i] == 0x1A)
|
||||
{
|
||||
bEof = TRUE;
|
||||
break;
|
||||
}
|
||||
bEof = TRUE;
|
||||
dwRead = pEof-buffer+1;
|
||||
break;
|
||||
}
|
||||
dwRead = i;
|
||||
}
|
||||
|
||||
if (dwRead == 0)
|
||||
|
@ -274,25 +271,24 @@ copy (TCHAR source[MAX_PATH],
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
while (dwRead && !bEof);
|
||||
while (!bEof);
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugPrintf (_T("setting time\n"));
|
||||
#endif
|
||||
SetFileTime (hFileDest, &srctime, NULL, NULL);
|
||||
|
||||
if (lpdwFlags & COPY_ASCII)
|
||||
if ((lpdwFlags & COPY_ASCII) && !bEof)
|
||||
{
|
||||
/* we're dealing with ASCII files! */
|
||||
((LPSTR)buffer)[0] = 0x1A;
|
||||
((LPSTR)buffer)[1] = '\0';
|
||||
buffer[0] = 0x1A;
|
||||
#ifdef _DEBUG
|
||||
DebugPrintf (_T("appending ^Z\n"));
|
||||
#endif
|
||||
WriteFile (hFileDest, buffer, sizeof(CHAR), &dwWritten, NULL);
|
||||
}
|
||||
|
||||
free (buffer);
|
||||
VirtualFree (buffer, 0, MEM_RELEASE);
|
||||
CloseHandle (hFileDest);
|
||||
CloseHandle (hFileSrc);
|
||||
|
||||
|
@ -318,8 +314,6 @@ copy (TCHAR source[MAX_PATH],
|
|||
if(lpdwFlags & COPY_DECRYPT)
|
||||
DeleteFile(TempSrc);
|
||||
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -877,7 +871,7 @@ INT cmd_copy (LPTSTR cmd, LPTSTR param)
|
|||
LoadString(CMD_ModuleHandle, STRING_COPY_FILE, szMsg, RC_STRING_MAX_SIZE);
|
||||
ConOutPrintf(szMsg, nFiles);
|
||||
|
||||
CloseHandle(hFile);
|
||||
FindClose(hFile);
|
||||
if (arg!=NULL)
|
||||
free(arg);
|
||||
|
||||
|
|
|
@ -473,7 +473,8 @@ VOID FindPrefixAndSuffix(LPTSTR strIN, LPTSTR szPrefix, LPTSTR szSuffix)
|
|||
_tcscpy(szSuffix,&strIN[SBreak]);
|
||||
strIN[PBreak] = _T('\0');
|
||||
_tcscpy(szPrefix,strIN);
|
||||
if(szPrefix[_tcslen(szPrefix) - 2] == _T('\"'))
|
||||
if (szPrefix[_tcslen(szPrefix) - 2] == _T('\"') &&
|
||||
szPrefix[_tcslen(szPrefix) - 1] != _T(' '))
|
||||
{
|
||||
/* need to remove the " right before a \ at the end to
|
||||
allow the next stuff to stay inside one set of quotes
|
||||
|
@ -604,21 +605,17 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor)
|
|||
}
|
||||
/* search for the files it might be */
|
||||
hFile = FindFirstFile (szSearchPath, &file);
|
||||
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
/* Assemble the orginal string and return */
|
||||
_tcscpy(strOut,szOrginal);
|
||||
return;
|
||||
}
|
||||
|
||||
/* aseemble a list of all files names */
|
||||
do
|
||||
{
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
/* Assemble the orginal string and return */
|
||||
_tcscpy(strOut,szOrginal);
|
||||
CloseHandle(hFile);
|
||||
if(FileList != NULL)
|
||||
free(FileList);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!_tcscmp (file.cFileName, _T(".")) ||
|
||||
if(!_tcscmp (file.cFileName, _T(".")) ||
|
||||
!_tcscmp (file.cFileName, _T("..")))
|
||||
continue;
|
||||
|
||||
|
@ -631,36 +628,28 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor)
|
|||
}
|
||||
|
||||
/* Add the file to the list of files */
|
||||
if(FileList == NULL)
|
||||
{
|
||||
FileListSize = 1;
|
||||
FileList = malloc(FileListSize * sizeof(FileName));
|
||||
}
|
||||
else
|
||||
{
|
||||
FileListSize++;
|
||||
FileList = realloc(FileList, FileListSize * sizeof(FileName));
|
||||
}
|
||||
FileList = realloc(FileList, ++FileListSize * sizeof(FileName));
|
||||
|
||||
if(FileList == NULL)
|
||||
{
|
||||
/* Assemble the orginal string and return */
|
||||
_tcscpy(strOut,szOrginal);
|
||||
CloseHandle(hFile);
|
||||
FindClose(hFile);
|
||||
ConOutFormatMessage (GetLastError());
|
||||
return;
|
||||
}
|
||||
/* Copies the file name into the struct */
|
||||
_tcscpy(FileList[FileListSize-1].Name,file.cFileName);
|
||||
|
||||
}while(FindNextFile(hFile,&file));
|
||||
} while(FindNextFile(hFile,&file));
|
||||
|
||||
FindClose(hFile);
|
||||
|
||||
/* Check the size of the list to see if we
|
||||
found any matches */
|
||||
if(FileListSize == 0)
|
||||
{
|
||||
_tcscpy(strOut,szOrginal);
|
||||
CloseHandle(hFile);
|
||||
if(FileList != NULL)
|
||||
free(FileList);
|
||||
return;
|
||||
|
@ -751,7 +740,6 @@ VOID CompleteFilename (LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor)
|
|||
_tcscpy(LastReturned,strOut);
|
||||
EndLength = _tcslen(strOut);
|
||||
DiffLength = EndLength - StartLength;
|
||||
CloseHandle(hFile);
|
||||
if(FileList != NULL)
|
||||
free(FileList);
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ VOID GetPathCase( TCHAR * Path, TCHAR * OutPath)
|
|||
_tcscat(TempPath, _T("\\"));
|
||||
_tcscat(OutPath, FindFileData.cFileName);
|
||||
_tcscat(OutPath, _T("\\"));
|
||||
CloseHandle(hFind);
|
||||
FindClose(hFind);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue