mirror of
https://github.com/reactos/reactos.git
synced 2025-06-30 18:11:23 +00:00
MoveFileWithProgressW for movefolder
- change from CreateDirectoryW to CreateDirectoryExW - fix close handle bug - overwrite readonly file - make sure both dest and src are not set to readonly - Source cleanup - Remove goto svn path=/trunk/; revision=18155
This commit is contained in:
parent
514b606aee
commit
f16bc096ac
1 changed files with 162 additions and 284 deletions
|
@ -35,131 +35,6 @@ RemoveReadOnlyAttributeW(IN LPCWSTR lpFileName)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL
|
|
||||||
AdjustFileAttributes (
|
|
||||||
LPCWSTR ExistingFileName,
|
|
||||||
LPCWSTR NewFileName
|
|
||||||
)
|
|
||||||
{
|
|
||||||
IO_STATUS_BLOCK IoStatusBlock;
|
|
||||||
FILE_BASIC_INFORMATION ExistingInfo,
|
|
||||||
NewInfo;
|
|
||||||
HANDLE hFile;
|
|
||||||
DWORD Attributes;
|
|
||||||
NTSTATUS errCode;
|
|
||||||
BOOL Result = FALSE;
|
|
||||||
|
|
||||||
hFile = CreateFileW (ExistingFileName,
|
|
||||||
FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES,
|
|
||||||
FILE_SHARE_READ,
|
|
||||||
NULL,
|
|
||||||
OPEN_EXISTING,
|
|
||||||
FILE_ATTRIBUTE_NORMAL,
|
|
||||||
NULL);
|
|
||||||
if (INVALID_HANDLE_VALUE != hFile)
|
|
||||||
{
|
|
||||||
errCode = NtQueryInformationFile (hFile,
|
|
||||||
&IoStatusBlock,
|
|
||||||
&ExistingInfo,
|
|
||||||
sizeof(FILE_BASIC_INFORMATION),
|
|
||||||
FileBasicInformation);
|
|
||||||
if (NT_SUCCESS (errCode))
|
|
||||||
{
|
|
||||||
if (0 != (ExistingInfo.FileAttributes & FILE_ATTRIBUTE_READONLY))
|
|
||||||
{
|
|
||||||
Attributes = ExistingInfo.FileAttributes;
|
|
||||||
ExistingInfo.FileAttributes &= ~ FILE_ATTRIBUTE_READONLY;
|
|
||||||
if (0 == (ExistingInfo.FileAttributes &
|
|
||||||
(FILE_ATTRIBUTE_HIDDEN |
|
|
||||||
FILE_ATTRIBUTE_SYSTEM |
|
|
||||||
FILE_ATTRIBUTE_ARCHIVE)))
|
|
||||||
{
|
|
||||||
ExistingInfo.FileAttributes |= FILE_ATTRIBUTE_NORMAL;
|
|
||||||
}
|
|
||||||
errCode = NtSetInformationFile (hFile,
|
|
||||||
&IoStatusBlock,
|
|
||||||
&ExistingInfo,
|
|
||||||
sizeof(FILE_BASIC_INFORMATION),
|
|
||||||
FileBasicInformation);
|
|
||||||
if (!NT_SUCCESS(errCode))
|
|
||||||
{
|
|
||||||
DPRINT("Removing READONLY attribute from source failed with status 0x%08x\n", errCode);
|
|
||||||
}
|
|
||||||
ExistingInfo.FileAttributes = Attributes;
|
|
||||||
}
|
|
||||||
CloseHandle(hFile);
|
|
||||||
|
|
||||||
if (NT_SUCCESS(errCode))
|
|
||||||
{
|
|
||||||
hFile = CreateFileW (NewFileName,
|
|
||||||
FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES,
|
|
||||||
FILE_SHARE_READ,
|
|
||||||
NULL,
|
|
||||||
OPEN_EXISTING,
|
|
||||||
FILE_ATTRIBUTE_NORMAL,
|
|
||||||
NULL);
|
|
||||||
if (INVALID_HANDLE_VALUE != hFile)
|
|
||||||
{
|
|
||||||
errCode = NtQueryInformationFile(hFile,
|
|
||||||
&IoStatusBlock,
|
|
||||||
&NewInfo,
|
|
||||||
sizeof(FILE_BASIC_INFORMATION),
|
|
||||||
FileBasicInformation);
|
|
||||||
if (NT_SUCCESS(errCode))
|
|
||||||
{
|
|
||||||
NewInfo.FileAttributes = (NewInfo.FileAttributes &
|
|
||||||
~ (FILE_ATTRIBUTE_HIDDEN |
|
|
||||||
FILE_ATTRIBUTE_SYSTEM |
|
|
||||||
FILE_ATTRIBUTE_READONLY |
|
|
||||||
FILE_ATTRIBUTE_NORMAL)) |
|
|
||||||
(ExistingInfo.FileAttributes &
|
|
||||||
(FILE_ATTRIBUTE_HIDDEN |
|
|
||||||
FILE_ATTRIBUTE_SYSTEM |
|
|
||||||
FILE_ATTRIBUTE_READONLY |
|
|
||||||
FILE_ATTRIBUTE_NORMAL)) |
|
|
||||||
FILE_ATTRIBUTE_ARCHIVE;
|
|
||||||
NewInfo.CreationTime = ExistingInfo.CreationTime;
|
|
||||||
NewInfo.LastAccessTime = ExistingInfo.LastAccessTime;
|
|
||||||
NewInfo.LastWriteTime = ExistingInfo.LastWriteTime;
|
|
||||||
errCode = NtSetInformationFile (hFile,
|
|
||||||
&IoStatusBlock,
|
|
||||||
&NewInfo,
|
|
||||||
sizeof(FILE_BASIC_INFORMATION),
|
|
||||||
FileBasicInformation);
|
|
||||||
if (NT_SUCCESS(errCode))
|
|
||||||
{
|
|
||||||
Result = TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DPRINT("Setting attributes on dest file failed with status 0x%08x\n", errCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DPRINT("Obtaining attributes from dest file failed with status 0x%08x\n", errCode);
|
|
||||||
}
|
|
||||||
CloseHandle(hFile);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DPRINT("Opening dest file to set attributes failed with code %d\n", GetLastError());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DPRINT("Obtaining attributes from source file failed with status 0x%08x\n", errCode);
|
|
||||||
CloseHandle(hFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DPRINT("Opening source file to obtain attributes failed with code %d\n", GetLastError());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* add_boot_rename_entry
|
* add_boot_rename_entry
|
||||||
|
@ -412,7 +287,6 @@ MoveFileWithProgressW (
|
||||||
if (Result)
|
if (Result)
|
||||||
{
|
{
|
||||||
/* Cleanup the source file */
|
/* Cleanup the source file */
|
||||||
AdjustFileAttributes(lpExistingFileName, lpNewFileName);
|
|
||||||
Result = DeleteFileW (lpExistingFileName);
|
Result = DeleteFileW (lpExistingFileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,34 +294,38 @@ MoveFileWithProgressW (
|
||||||
{
|
{
|
||||||
/* move folder code start */
|
/* move folder code start */
|
||||||
WIN32_FIND_DATAW findBuffer;
|
WIN32_FIND_DATAW findBuffer;
|
||||||
LPCWSTR lpExistingFileName2 = NULL;
|
LPWSTR lpExistingFileName2 = NULL;
|
||||||
LPCWSTR lpNewFileName2 = NULL;
|
LPWSTR lpNewFileName2 = NULL;
|
||||||
LPCWSTR lpDeleteFile = NULL;
|
LPWSTR lpDeleteFile = NULL;
|
||||||
INT size;
|
INT size;
|
||||||
INT size2;
|
INT size2;
|
||||||
BOOL loop = TRUE;
|
BOOL loop = TRUE;
|
||||||
BOOL Result = FALSE;
|
BOOL Result = FALSE;
|
||||||
|
INT max_size = MAX_PATH;
|
||||||
|
|
||||||
|
|
||||||
/* Build the string */
|
/* Build the string */
|
||||||
size = wcslen(lpExistingFileName);
|
size = wcslen(lpExistingFileName);
|
||||||
|
if (size+6> max_size)
|
||||||
|
max_size = size + 6;
|
||||||
|
|
||||||
lpDeleteFile = (LPCWSTR) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,MAX_PATH * sizeof(WCHAR));
|
lpDeleteFile = (LPWSTR) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,max_size * sizeof(WCHAR));
|
||||||
if (lpDeleteFile == NULL)
|
if (lpDeleteFile == NULL)
|
||||||
goto FreeMemAndExit;
|
return FALSE;
|
||||||
|
|
||||||
lpNewFileName2 = (LPCWSTR) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,MAX_PATH * sizeof(WCHAR));
|
lpNewFileName2 = (LPWSTR) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,max_size * sizeof(WCHAR));
|
||||||
if (lpNewFileName2 == NULL)
|
if (lpNewFileName2 == NULL)
|
||||||
goto FreeMemAndExit;
|
|
||||||
|
|
||||||
lpExistingFileName2 = (LPCWSTR) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,MAX_PATH * sizeof(WCHAR));
|
|
||||||
if (lpExistingFileName2 == NULL)
|
|
||||||
goto FreeMemAndExit;
|
|
||||||
|
|
||||||
if ((size+6)*sizeof(WCHAR)>MAX_PATH)
|
|
||||||
{
|
{
|
||||||
HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(VOID *) lpExistingFileName2,(size+6)*sizeof(WCHAR));
|
HeapFree(GetProcessHeap(),0,(VOID *) lpDeleteFile);
|
||||||
if (lpExistingFileName2 == NULL)
|
return FALSE;
|
||||||
goto FreeMemAndExit;
|
}
|
||||||
|
|
||||||
|
lpExistingFileName2 = (LPWSTR) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,max_size * sizeof(WCHAR));
|
||||||
|
if (lpNewFileName2 == NULL)
|
||||||
|
{
|
||||||
|
HeapFree(GetProcessHeap(),0,(VOID *) lpNewFileName2);
|
||||||
|
HeapFree(GetProcessHeap(),0,(VOID *) lpDeleteFile);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wcscpy( (WCHAR *)lpExistingFileName2,lpExistingFileName);
|
wcscpy( (WCHAR *)lpExistingFileName2,lpExistingFileName);
|
||||||
|
@ -462,17 +340,15 @@ MoveFileWithProgressW (
|
||||||
if (findBuffer.cFileName[0] == L'\0')
|
if (findBuffer.cFileName[0] == L'\0')
|
||||||
loop=FALSE;
|
loop=FALSE;
|
||||||
|
|
||||||
DPRINT("MoveFileWithProgressW : lpExistingFileName1 = %S\n",lpExistingFileName);
|
|
||||||
DPRINT("MoveFileWithProgressW : lpExistingFileName2 = %S\n",lpExistingFileName2);
|
|
||||||
DPRINT("MoveFileWithProgressW : lpNewFileName = %S\n",lpNewFileName);
|
|
||||||
|
|
||||||
DPRINT("MoveFileWithProgressW : loop = %d %d %d\n",TRUE, FALSE, loop);
|
/* FIXME
|
||||||
|
* remove readonly flag from source folder and do not set the readonly flag to dest folder
|
||||||
|
*/
|
||||||
|
RemoveReadOnlyAttributeW(lpExistingFileName);
|
||||||
|
RemoveReadOnlyAttributeW(lpNewFileName);
|
||||||
|
CreateDirectoryExW(lpExistingFileName,lpNewFileName,NULL);
|
||||||
|
|
||||||
|
/* search the files/folders and move them */
|
||||||
CreateDirectoryW(lpNewFileName,NULL);
|
|
||||||
|
|
||||||
|
|
||||||
/* search the file */
|
|
||||||
while (loop==TRUE)
|
while (loop==TRUE)
|
||||||
{
|
{
|
||||||
Result = TRUE;
|
Result = TRUE;
|
||||||
|
@ -485,19 +361,25 @@ MoveFileWithProgressW (
|
||||||
{
|
{
|
||||||
size = wcslen(lpExistingFileName2)-4;
|
size = wcslen(lpExistingFileName2)-4;
|
||||||
FindClose(hFile);
|
FindClose(hFile);
|
||||||
wcscpy( (WCHAR *)&lpExistingFileName2[size],L"\0");
|
wcscpy( &lpExistingFileName2[size],L"\0");
|
||||||
|
|
||||||
if (wcsncmp(lpExistingFileName,lpExistingFileName2,size))
|
if (wcsncmp(lpExistingFileName,lpExistingFileName2,size))
|
||||||
{
|
{
|
||||||
|
DWORD Attributes;
|
||||||
|
|
||||||
FindClose(hFile);
|
FindClose(hFile);
|
||||||
|
|
||||||
/* delete folder */
|
/* delete folder */
|
||||||
DPRINT("MoveFileWithProgressW : folder : %s\n",lpDeleteFile);
|
DPRINT("MoveFileWithProgressW : Delete folder : %S\n",lpDeleteFile);
|
||||||
|
|
||||||
|
/* remove system folder flag other wise we can not delete the folder */
|
||||||
|
Attributes = GetFileAttributesW(lpExistingFileName2);
|
||||||
|
if (Attributes != INVALID_FILE_ATTRIBUTES)
|
||||||
|
{
|
||||||
|
SetFileAttributesW(lpExistingFileName2,(Attributes & ~FILE_ATTRIBUTE_SYSTEM));
|
||||||
|
}
|
||||||
|
|
||||||
Result = RemoveReadOnlyAttributeW(lpExistingFileName2);
|
RemoveReadOnlyAttributeW(lpExistingFileName2);
|
||||||
if (Result == FALSE)
|
|
||||||
break;
|
|
||||||
|
|
||||||
Result = RemoveDirectoryW(lpExistingFileName2);
|
Result = RemoveDirectoryW(lpExistingFileName2);
|
||||||
if (Result == FALSE)
|
if (Result == FALSE)
|
||||||
|
@ -506,20 +388,22 @@ MoveFileWithProgressW (
|
||||||
loop=TRUE;
|
loop=TRUE;
|
||||||
size = wcslen(lpExistingFileName);
|
size = wcslen(lpExistingFileName);
|
||||||
|
|
||||||
if ((size+6)*sizeof(WCHAR)>MAX_PATH)
|
if (size+6>max_size)
|
||||||
{
|
{
|
||||||
lpExistingFileName2 = (LPCWSTR) HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
|
if (lpNewFileName2 != NULL)
|
||||||
(VOID *)lpExistingFileName2,(size+6)*sizeof(WCHAR));
|
HeapFree(GetProcessHeap(),0,(VOID *) lpNewFileName2);
|
||||||
|
|
||||||
if (lpExistingFileName2 == NULL)
|
if (lpExistingFileName2 != NULL)
|
||||||
{
|
HeapFree(GetProcessHeap(),0,(VOID *) lpExistingFileName2);
|
||||||
Result = FALSE;
|
|
||||||
goto FreeMemAndExit;
|
if (lpDeleteFile != NULL)
|
||||||
}
|
HeapFree(GetProcessHeap(),0,(VOID *) lpDeleteFile);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wcscpy( (WCHAR *)lpExistingFileName2,lpExistingFileName);
|
wcscpy( lpExistingFileName2,lpExistingFileName);
|
||||||
wcscpy( (WCHAR *)&lpExistingFileName2[size],L"\\*.*\0");
|
wcscpy( &lpExistingFileName2[size],L"\\*.*\0");
|
||||||
|
|
||||||
/* Get the file name */
|
/* Get the file name */
|
||||||
memset(&findBuffer,0,sizeof(WIN32_FIND_DATAW));
|
memset(&findBuffer,0,sizeof(WIN32_FIND_DATAW));
|
||||||
|
@ -531,88 +415,74 @@ MoveFileWithProgressW (
|
||||||
|
|
||||||
if (findBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
if (findBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
{
|
{
|
||||||
DPRINT("MoveFileWithProgressW : 1: %S %S\n",lpExistingFileName2,findBuffer.cFileName);
|
|
||||||
|
|
||||||
/* Build the new string */
|
/* Build the new src string */
|
||||||
size = wcslen(findBuffer.cFileName);
|
size = wcslen(findBuffer.cFileName);
|
||||||
size2= wcslen(lpExistingFileName2);
|
size2= wcslen(lpExistingFileName2);
|
||||||
|
|
||||||
if ((size2+size+6)*sizeof(WCHAR)>MAX_PATH)
|
if (size2+size+6>max_size)
|
||||||
{
|
{
|
||||||
lpExistingFileName2 = (LPCWSTR) HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
|
FindClose(hFile);
|
||||||
(VOID *)lpExistingFileName2, (size2+size+6)*sizeof(WCHAR));
|
|
||||||
|
|
||||||
if (lpExistingFileName2 == NULL)
|
if (lpNewFileName2 != NULL)
|
||||||
{
|
HeapFree(GetProcessHeap(),0,(VOID *) lpNewFileName2);
|
||||||
Result = FALSE;
|
|
||||||
goto FreeMemAndExit;
|
if (lpExistingFileName2 != NULL)
|
||||||
}
|
HeapFree(GetProcessHeap(),0,(VOID *) lpExistingFileName2);
|
||||||
|
|
||||||
|
if (lpDeleteFile != NULL)
|
||||||
|
HeapFree(GetProcessHeap(),0,(VOID *) lpDeleteFile);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wcscpy( (WCHAR *)&lpExistingFileName2[size2-3],findBuffer.cFileName);
|
wcscpy( &lpExistingFileName2[size2-3],findBuffer.cFileName);
|
||||||
|
wcscpy( &lpExistingFileName2[size2+size-3],L"\0");
|
||||||
|
|
||||||
/* FIXME
|
|
||||||
* RemoveReadOnlyAttributeW(lpExistingFileName2); is a hack
|
|
||||||
* for to move readonly folders
|
|
||||||
*/
|
|
||||||
wcscpy( (WCHAR *)&lpExistingFileName2[size2+size-3],L"\0");
|
|
||||||
RemoveReadOnlyAttributeW(lpExistingFileName2);
|
|
||||||
|
|
||||||
|
|
||||||
/* Continue */
|
/* Continue */
|
||||||
wcscpy( (WCHAR *)&lpExistingFileName2[size2+size-3],L"\\*.*\0");
|
wcscpy( lpDeleteFile,lpExistingFileName2);
|
||||||
|
wcscpy( &lpExistingFileName2[size2+size-3],L"\\*.*\0");
|
||||||
|
|
||||||
|
|
||||||
/* Build the new dst string */
|
/* Build the new dst string */
|
||||||
size = wcslen(lpExistingFileName2) + wcslen(lpNewFileName);
|
size = wcslen(lpExistingFileName2) + wcslen(lpNewFileName);
|
||||||
size2 = wcslen(lpExistingFileName);
|
size2 = wcslen(lpExistingFileName);
|
||||||
|
|
||||||
if (size>MAX_PATH)
|
if (size>max_size)
|
||||||
{
|
{
|
||||||
lpNewFileName2 = (LPCWSTR) HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
|
FindClose(hFile);
|
||||||
(VOID *) lpNewFileName2, size*sizeof(WCHAR));
|
|
||||||
|
|
||||||
if (lpNewFileName2 == NULL)
|
if (lpNewFileName2 != NULL)
|
||||||
{
|
HeapFree(GetProcessHeap(),0,(VOID *) lpNewFileName2);
|
||||||
Result = FALSE;
|
|
||||||
goto FreeMemAndExit;
|
if (lpExistingFileName2 != NULL)
|
||||||
}
|
HeapFree(GetProcessHeap(),0,(VOID *) lpExistingFileName2);
|
||||||
|
|
||||||
|
if (lpDeleteFile != NULL)
|
||||||
|
HeapFree(GetProcessHeap(),0,(VOID *) lpDeleteFile);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wcscpy((WCHAR *) lpNewFileName2,lpNewFileName);
|
wcscpy( lpNewFileName2,lpNewFileName);
|
||||||
size = wcslen(lpNewFileName);
|
size = wcslen(lpNewFileName);
|
||||||
wcscpy((WCHAR *)&lpNewFileName2[size], (WCHAR *)&lpExistingFileName2[size2]);
|
wcscpy( &lpNewFileName2[size], &lpExistingFileName2[size2]);
|
||||||
size = wcslen(lpNewFileName2);
|
size = wcslen(lpNewFileName2);
|
||||||
wcscpy( (WCHAR *)&lpNewFileName2[size-4],L"\0");
|
wcscpy( &lpNewFileName2[size-4],L"\0");
|
||||||
|
|
||||||
/* build dest path */
|
|
||||||
/* remove this code when it will be out into kernel32.dll ? */
|
|
||||||
|
|
||||||
size = GetFullPathNameW(lpNewFileName2, MAX_PATH,(LPWSTR) lpDeleteFile, NULL);
|
|
||||||
if (MAX_PATH>size2)
|
|
||||||
{
|
|
||||||
lpDeleteFile = (LPCWSTR) HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
|
|
||||||
(VOID *) lpDeleteFile,size) ;
|
|
||||||
|
|
||||||
if (lpDeleteFile == NULL)
|
|
||||||
{
|
|
||||||
Result = FALSE;
|
|
||||||
goto FreeMemAndExit;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetFullPathNameW(lpNewFileName2, size,(LPWSTR) lpDeleteFile, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create Folder */
|
/* Create Folder */
|
||||||
|
|
||||||
DPRINT("MoveFileWithProgressW : CreateDirectoryW lpNewFileName2 : %S\n",lpNewFileName2);
|
/* FIXME
|
||||||
DPRINT("MoveFileWithProgressW : CreateDirectoryW : %S\n",lpDeleteFile);
|
* remove readonly flag from source folder and do not set the readonly flag to dest folder
|
||||||
|
*/
|
||||||
|
RemoveReadOnlyAttributeW(lpDeleteFile);
|
||||||
|
RemoveReadOnlyAttributeW(lpNewFileName2);
|
||||||
|
|
||||||
CreateDirectoryW(lpDeleteFile,NULL);
|
CreateDirectoryExW(lpDeleteFile, lpNewFileName2,NULL);
|
||||||
|
|
||||||
DPRINT("MoveFileWithProgressW : 1x: %S : %S \n",lpExistingFileName2, lpNewFileName2);
|
|
||||||
|
|
||||||
|
/* set new search path from src string */
|
||||||
FindClose(hFile);
|
FindClose(hFile);
|
||||||
memset(&findBuffer,0,sizeof(WIN32_FIND_DATAW));
|
memset(&findBuffer,0,sizeof(WIN32_FIND_DATAW));
|
||||||
hFile = FindFirstFileW(lpExistingFileName2, &findBuffer);
|
hFile = FindFirstFileW(lpExistingFileName2, &findBuffer);
|
||||||
|
@ -623,30 +493,44 @@ MoveFileWithProgressW (
|
||||||
/* Build the new string */
|
/* Build the new string */
|
||||||
size = wcslen(findBuffer.cFileName);
|
size = wcslen(findBuffer.cFileName);
|
||||||
size2= wcslen(lpExistingFileName2);
|
size2= wcslen(lpExistingFileName2);
|
||||||
wcscpy( (WCHAR *)lpDeleteFile,lpExistingFileName2);
|
wcscpy( lpDeleteFile,lpExistingFileName2);
|
||||||
wcscpy( (WCHAR *)&lpDeleteFile[size2-3],findBuffer.cFileName);
|
wcscpy( &lpDeleteFile[size2-3],findBuffer.cFileName);
|
||||||
|
|
||||||
/* Build dest string */
|
/* Build dest string */
|
||||||
size = wcslen(lpDeleteFile) + wcslen(lpNewFileName);
|
size = wcslen(lpDeleteFile) + wcslen(lpNewFileName);
|
||||||
size2 = wcslen(lpExistingFileName);
|
size2 = wcslen(lpExistingFileName);
|
||||||
|
|
||||||
if (size*sizeof(WCHAR)>MAX_PATH)
|
if (size>max_size)
|
||||||
{
|
{
|
||||||
lpNewFileName2 = (LPCWSTR) HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
|
FindClose(hFile);
|
||||||
(VOID *) lpNewFileName2, size*sizeof(WCHAR));
|
|
||||||
|
|
||||||
if (lpNewFileName2 == NULL)
|
if (lpNewFileName2 != NULL)
|
||||||
{
|
HeapFree(GetProcessHeap(),0,(VOID *) lpNewFileName2);
|
||||||
Result = FALSE;
|
|
||||||
goto FreeMemAndExit;
|
if (lpExistingFileName2 != NULL)
|
||||||
}
|
HeapFree(GetProcessHeap(),0,(VOID *) lpExistingFileName2);
|
||||||
|
|
||||||
|
if (lpDeleteFile != NULL)
|
||||||
|
HeapFree(GetProcessHeap(),0,(VOID *) lpDeleteFile);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wcscpy((WCHAR *) lpNewFileName2,lpNewFileName);
|
wcscpy( lpNewFileName2,lpNewFileName);
|
||||||
size = wcslen(lpNewFileName);
|
size = wcslen(lpNewFileName);
|
||||||
wcscpy((WCHAR *)&lpNewFileName2[size], (WCHAR *)&lpDeleteFile[size2]);
|
wcscpy(&lpNewFileName2[size],&lpDeleteFile[size2]);
|
||||||
|
|
||||||
|
|
||||||
|
/* overrite existsen file, if the file got the flag have readonly
|
||||||
|
* we need reomve that flag
|
||||||
|
*/
|
||||||
|
|
||||||
/* copy file */
|
/* copy file */
|
||||||
|
|
||||||
|
DPRINT("MoveFileWithProgressW : Copy file : %S to %S\n",lpDeleteFile, lpNewFileName2);
|
||||||
|
RemoveReadOnlyAttributeW(lpDeleteFile);
|
||||||
|
RemoveReadOnlyAttributeW(lpNewFileName2);
|
||||||
|
|
||||||
Result = CopyFileExW (lpDeleteFile,
|
Result = CopyFileExW (lpDeleteFile,
|
||||||
lpNewFileName2,
|
lpNewFileName2,
|
||||||
lpProgressRoutine,
|
lpProgressRoutine,
|
||||||
|
@ -655,48 +539,41 @@ MoveFileWithProgressW (
|
||||||
0);
|
0);
|
||||||
|
|
||||||
if (Result == FALSE)
|
if (Result == FALSE)
|
||||||
{
|
|
||||||
DPRINT("MoveFileWithProgressW : Fails\n");
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
/* delete file */
|
/* delete file */
|
||||||
DPRINT("MoveFileWithProgressW : Delete file : %S : %S\n",lpDeleteFile, lpNewFileName2);
|
DPRINT("MoveFileWithProgressW : remove readonly flag from file : %S\n",lpNewFileName2);
|
||||||
|
|
||||||
|
|
||||||
Result = RemoveReadOnlyAttributeW(lpDeleteFile);
|
Result = RemoveReadOnlyAttributeW(lpDeleteFile);
|
||||||
if (Result == FALSE)
|
if (Result == FALSE)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
DPRINT("MoveFileWithProgressW : Delete file : %S\n",lpDeleteFile);
|
||||||
Result = DeleteFileW(lpDeleteFile);
|
Result = DeleteFileW(lpDeleteFile);
|
||||||
if (Result == FALSE)
|
if (Result == FALSE)
|
||||||
{
|
|
||||||
DPRINT("MoveFileWithProgressW : Fails\n");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
DPRINT("MoveFileWithProgressW : 2 : %S : %S \n",lpExistingFileName2,findBuffer.cFileName);
|
|
||||||
loop = FindNextFileW(hFile, &findBuffer);
|
loop = FindNextFileW(hFile, &findBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
FindClose(hFile);
|
|
||||||
memset(&findBuffer,0,sizeof(WIN32_FIND_DATAW));
|
|
||||||
hFile = FindFirstFileW(lpExistingFileName2, &findBuffer);
|
|
||||||
if (hFile == NULL)
|
|
||||||
loop=TRUE;
|
|
||||||
|
|
||||||
if (findBuffer.cFileName[0] == L'\0')
|
/* Remove last folder */
|
||||||
loop=TRUE;
|
if ((loop == FALSE) && (Result != FALSE))
|
||||||
|
|
||||||
if (loop == FALSE)
|
|
||||||
{
|
{
|
||||||
|
DWORD Attributes;
|
||||||
|
|
||||||
FindClose(hFile);
|
FindClose(hFile);
|
||||||
Result = RemoveDirectoryW(lpExistingFileName);
|
Attributes = GetFileAttributesW(lpDeleteFile);
|
||||||
DPRINT("MoveFileWithProgressW RemoveDirectoryW :%S",lpExistingFileName);
|
if (Attributes != INVALID_FILE_ATTRIBUTES)
|
||||||
|
{
|
||||||
|
SetFileAttributesW(lpDeleteFile,(Attributes & ~FILE_ATTRIBUTE_SYSTEM));
|
||||||
}
|
}
|
||||||
|
|
||||||
FreeMemAndExit:
|
Result = RemoveDirectoryW(lpExistingFileName);
|
||||||
DPRINT("MoveFileWithProgressW : result : r=%d, T=%d, F=%d",Result,TRUE,FALSE);
|
}
|
||||||
|
|
||||||
|
/* Cleanup */
|
||||||
|
FindClose(hFile);
|
||||||
|
|
||||||
if (lpNewFileName2 != NULL)
|
if (lpNewFileName2 != NULL)
|
||||||
{
|
{
|
||||||
|
@ -717,6 +594,7 @@ FreeMemAndExit:
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
|
|
||||||
// end move folder code
|
// end move folder code
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue