Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/UI/FileManager/FSFolderCopy.cpp')
-rwxr-xr-xCPP/7zip/UI/FileManager/FSFolderCopy.cpp157
1 files changed, 74 insertions, 83 deletions
diff --git a/CPP/7zip/UI/FileManager/FSFolderCopy.cpp b/CPP/7zip/UI/FileManager/FSFolderCopy.cpp
index b6ffd574..c31498c7 100755
--- a/CPP/7zip/UI/FileManager/FSFolderCopy.cpp
+++ b/CPP/7zip/UI/FileManager/FSFolderCopy.cpp
@@ -102,13 +102,7 @@ typedef BOOL (WINAPI * CopyFileExPointerW)(
IN DWORD dwCopyFlags
);
-#ifndef _UNICODE
-static inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }
-static CSysString GetSysPath(LPCWSTR sysPath)
- { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }
-#endif
-
-static bool MyCopyFile(LPCWSTR existingFile, LPCWSTR newFile, IProgress *progress, UInt64 &completedSize)
+static bool MyCopyFile(CFSTR existingFile, CFSTR newFile, IProgress *progress, UInt64 &completedSize)
{
CProgressInfo progressInfo;
progressInfo.Progress = progress;
@@ -128,8 +122,8 @@ static bool MyCopyFile(LPCWSTR existingFile, LPCWSTR newFile, IProgress *progres
CopyFileExPointerW copyFunctionW = (CopyFileExPointerW)
My_GetProcAddress(::GetModuleHandleW(k_DllName), "CopyFileExW");
if (copyFunctionW == 0)
- return BOOLToBool(::CopyFileW(existingFile, newFile, TRUE));
- if (copyFunctionW(existingFile, newFile, CopyProgressRoutine,
+ return BOOLToBool(::CopyFileW(fs2us(existingFile), fs2us(newFile), TRUE));
+ if (copyFunctionW(fs2us(existingFile), fs2us(newFile), CopyProgressRoutine,
&progressInfo, &CancelFlag, COPY_FILE_FAIL_IF_EXISTS))
return true;
#ifdef WIN_LONG_PATH
@@ -150,13 +144,13 @@ static bool MyCopyFile(LPCWSTR existingFile, LPCWSTR newFile, IProgress *progres
"CopyFileExA");
if (copyFunction != 0)
{
- if (copyFunction(GetSysPath(existingFile), GetSysPath(newFile),
+ if (copyFunction(fs2fas(existingFile), fs2fas(newFile),
CopyProgressRoutine,&progressInfo, &CancelFlag, COPY_FILE_FAIL_IF_EXISTS))
return true;
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
return false;
}
- return BOOLToBool(::CopyFile(GetSysPath(existingFile), GetSysPath(newFile), TRUE));
+ return BOOLToBool(::CopyFile(fs2fas(existingFile), fs2fas(newFile), TRUE));
}
#endif
}
@@ -169,7 +163,7 @@ typedef BOOL (WINAPI * MoveFileWithProgressPointer)(
IN DWORD dwFlags
);
-static bool MyMoveFile(LPCWSTR existingFile, LPCWSTR newFile, IProgress *progress, UInt64 &completedSize)
+static bool MyMoveFile(CFSTR existingFile, CFSTR newFile, IProgress *progress, UInt64 &completedSize)
{
#ifndef UNDER_CE
// if (IsItWindows2000orHigher())
@@ -184,7 +178,7 @@ static bool MyMoveFile(LPCWSTR existingFile, LPCWSTR newFile, IProgress *progres
if (moveFunction != 0)
{
if (moveFunction(
- existingFile, newFile, CopyProgressRoutine,
+ fs2us(existingFile), fs2us(newFile), CopyProgressRoutine,
&progressInfo, MOVEFILE_COPY_ALLOWED))
return true;
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
@@ -207,41 +201,48 @@ static bool MyMoveFile(LPCWSTR existingFile, LPCWSTR newFile, IProgress *progres
return NDirectory::MyMoveFile(existingFile, newFile);
}
+static HRESULT SendMessageError(IFolderOperationsExtractCallback *callback,
+ const wchar_t *message, const FString &fileName)
+{
+ return callback->ShowMessage(message + fs2us(fileName));
+}
+
+static HRESULT SendMessageError(IFolderOperationsExtractCallback *callback,
+ const char *message, const FString &fileName)
+{
+ return SendMessageError(callback, MultiByteToUnicodeString(message), fileName);
+}
+
static HRESULT MyCopyFile(
- const UString &srcPath,
- const CFileInfoW &srcFileInfo,
- const UString &destPathSpec,
+ const FString &srcPath,
+ const CFileInfo &srcFileInfo,
+ const FString &destPathSpec,
IFolderOperationsExtractCallback *callback,
UInt64 &completedSize)
{
- UString destPath = destPathSpec;
+ FString destPath = destPathSpec;
if (destPath.CompareNoCase(srcPath) == 0)
{
- UString message = UString(L"can not move file \'") + destPath + UString(L"\' onto itself");
- RINOK(callback->ShowMessage(message));
+ RINOK(SendMessageError(callback, "can not copy file onto itself: ", destPath));
return E_ABORT;
}
Int32 writeAskResult;
CMyComBSTR destPathResult;
RINOK(callback->AskWrite(
- srcPath,
+ fs2us(srcPath),
BoolToInt(false),
&srcFileInfo.MTime, &srcFileInfo.Size,
- destPath,
+ fs2us(destPath),
&destPathResult,
&writeAskResult));
if (IntToBool(writeAskResult))
{
- UString destPathNew = UString(destPathResult);
- RINOK(callback->SetCurrentFilePath(srcPath));
+ FString destPathNew = us2fs(destPathResult);
+ RINOK(callback->SetCurrentFilePath(fs2us(srcPath)));
if (!MyCopyFile(srcPath, destPathNew, callback, completedSize))
{
- UString message = NError::MyFormatMessageW(GetLastError()) +
- UString(L" \'") +
- UString(destPathNew) +
- UString(L"\'");
- RINOK(callback->ShowMessage(message));
+ RINOK(SendMessageError(callback, NError::MyFormatMessageW(GetLastError()) + L" : ", destPathNew));
return E_ABORT;
}
}
@@ -249,44 +250,41 @@ static HRESULT MyCopyFile(
return callback->SetCompleted(&completedSize);
}
-static UString CombinePath(const UString &folderPath, const UString &fileName)
+static FString CombinePath(const FString &folderPath, const FString &fileName)
{
- return folderPath + UString(WCHAR_PATH_SEPARATOR) + fileName;
+ return folderPath + FCHAR_PATH_SEPARATOR + fileName;
}
static HRESULT CopyFolder(
- const UString &srcPath,
- const UString &destPathSpec,
+ const FString &srcPath,
+ const FString &destPathSpec,
IFolderOperationsExtractCallback *callback,
UInt64 &completedSize)
{
RINOK(callback->SetCompleted(&completedSize));
- const UString destPath = destPathSpec;
+ const FString destPath = destPathSpec;
int len = srcPath.Length();
if (destPath.Length() >= len && srcPath.CompareNoCase(destPath.Left(len)) == 0)
{
- if (destPath.Length() == len || destPath[len] == WCHAR_PATH_SEPARATOR)
+ if (destPath.Length() == len || destPath[len] == FCHAR_PATH_SEPARATOR)
{
- UString message = UString(L"can not copy folder \'") +
- destPath + UString(L"\' onto itself");
- RINOK(callback->ShowMessage(message));
+ RINOK(SendMessageError(callback, "can not copy folder onto itself: ", destPath));
return E_ABORT;
}
}
if (!NDirectory::CreateComplexDirectory(destPath))
{
- UString message = UString(L"can not create folder ") + destPath;
- RINOK(callback->ShowMessage(message));
+ RINOK(SendMessageError(callback, "can not create folder: ", destPath));
return E_ABORT;
}
- CEnumeratorW enumerator(CombinePath(srcPath, L"*"));
+ CEnumerator enumerator(CombinePath(srcPath, FSTRING_ANY_MASK));
CFileInfoEx fi;
while (enumerator.Next(fi))
{
- const UString srcPath2 = CombinePath(srcPath, fi.Name);
- const UString destPath2 = CombinePath(destPath, fi.Name);
+ const FString srcPath2 = CombinePath(srcPath, fi.Name);
+ const FString destPath2 = CombinePath(destPath, fi.Name);
if (fi.IsDir())
{
RINOK(CopyFolder(srcPath2, destPath2, callback, completedSize))
@@ -313,7 +311,7 @@ STDMETHODIMP CFSFolder::CopyTo(const UInt32 *indices, UInt32 numItems,
UString destPath = path;
if (destPath.IsEmpty())
return E_INVALIDARG;
- bool directName = (destPath[destPath.Length() - 1] != WCHAR_PATH_SEPARATOR);
+ bool directName = (destPath.Back() != WCHAR_PATH_SEPARATOR);
if (directName)
{
if (numItems > 1)
@@ -337,10 +335,10 @@ STDMETHODIMP CFSFolder::CopyTo(const UInt32 *indices, UInt32 numItems,
for (UInt32 i = 0; i < numItems; i++)
{
const CDirItem &fi = *_refs[indices[i]];
- UString destPath2 = destPath;
+ FString destPath2 = us2fs(destPath);
if (!directName)
destPath2 += fi.Name;
- UString srcPath = _path + GetPrefix(fi) + fi.Name;
+ FString srcPath = _path + GetPrefix(fi) + fi.Name;
if (fi.IsDir())
{
RINOK(CopyFolder(srcPath, destPath2, callback, completedSize));
@@ -356,40 +354,35 @@ STDMETHODIMP CFSFolder::CopyTo(const UInt32 *indices, UInt32 numItems,
/////////////////////////////////////////////////
// Move Operations
-HRESULT MyMoveFile(
- const UString &srcPath,
- const CFileInfoW &srcFileInfo,
- const UString &destPathSpec,
+static HRESULT MyMoveFile(
+ const FString &srcPath,
+ const CFileInfo &srcFileInfo,
+ const FString &destPath,
IFolderOperationsExtractCallback *callback,
UInt64 &completedSize)
{
- UString destPath = destPathSpec;
if (destPath.CompareNoCase(srcPath) == 0)
{
- UString message = UString(L"can not move file \'")
- + destPath +
- UString(L"\' onto itself");
- RINOK(callback->ShowMessage(message));
+ RINOK(SendMessageError(callback, "can not move file onto itself: ", srcPath));
return E_ABORT;
}
Int32 writeAskResult;
CMyComBSTR destPathResult;
RINOK(callback->AskWrite(
- srcPath,
+ fs2us(srcPath),
BoolToInt(false),
&srcFileInfo.MTime, &srcFileInfo.Size,
- destPath,
+ fs2us(destPath),
&destPathResult,
&writeAskResult));
if (IntToBool(writeAskResult))
{
- UString destPathNew = UString(destPathResult);
- RINOK(callback->SetCurrentFilePath(srcPath));
+ FString destPathNew = us2fs(destPathResult);
+ RINOK(callback->SetCurrentFilePath(fs2us(srcPath)));
if (!MyMoveFile(srcPath, destPathNew, callback, completedSize))
{
- UString message = UString(L"can not move to file ") + destPathNew;
- RINOK(callback->ShowMessage(message));
+ RINOK(SendMessageError(callback, "can not move to file: ", destPathNew));
}
}
completedSize += srcFileInfo.Size;
@@ -397,21 +390,18 @@ HRESULT MyMoveFile(
return S_OK;
}
-HRESULT MyMoveFolder(
- const UString &srcPath,
- const UString &destPathSpec,
+static HRESULT MyMoveFolder(
+ const FString &srcPath,
+ const FString &destPath,
IFolderOperationsExtractCallback *callback,
UInt64 &completedSize)
{
- UString destPath = destPathSpec;
int len = srcPath.Length();
if (destPath.Length() >= len && srcPath.CompareNoCase(destPath.Left(len)) == 0)
{
- if (destPath.Length() == len || destPath[len] == WCHAR_PATH_SEPARATOR)
+ if (destPath.Length() == len || destPath[len] == FCHAR_PATH_SEPARATOR)
{
- UString message = UString(L"can not move folder \'") +
- destPath + UString(L"\' onto itself");
- RINOK(callback->ShowMessage(message));
+ RINOK(SendMessageError(callback, "can not move folder onto itself: ", destPath));
return E_ABORT;
}
}
@@ -421,17 +411,16 @@ HRESULT MyMoveFolder(
if (!NDirectory::CreateComplexDirectory(destPath))
{
- UString message = UString(L"can not create folder ") + destPath;
- RINOK(callback->ShowMessage(message));
+ RINOK(SendMessageError(callback, "can not create folder: ", destPath));
return E_ABORT;
}
{
- CEnumeratorW enumerator(CombinePath(srcPath, L"*"));
+ CEnumerator enumerator(CombinePath(srcPath, FSTRING_ANY_MASK));
CFileInfoEx fi;
while (enumerator.Next(fi))
{
- const UString srcPath2 = CombinePath(srcPath, fi.Name);
- const UString destPath2 = CombinePath(destPath, fi.Name);
+ const FString srcPath2 = CombinePath(srcPath, fi.Name);
+ const FString destPath2 = CombinePath(destPath, fi.Name);
if (fi.IsDir())
{
RINOK(MyMoveFolder(srcPath2, destPath2, callback, completedSize));
@@ -444,8 +433,7 @@ HRESULT MyMoveFolder(
}
if (!NDirectory::MyRemoveDirectory(srcPath))
{
- UString message = UString(L"can not remove folder") + srcPath;
- RINOK(callback->ShowMessage(message));
+ RINOK(SendMessageError(callback, "can not remove folder: ", srcPath));
return E_ABORT;
}
return S_OK;
@@ -465,10 +453,10 @@ STDMETHODIMP CFSFolder::MoveTo(
RINOK(callback->SetTotal(totalSize));
RINOK(callback->SetNumFiles(numFiles));
- UString destPath = path;
+ FString destPath = us2fs(path);
if (destPath.IsEmpty())
return E_INVALIDARG;
- bool directName = (destPath[destPath.Length() - 1] != WCHAR_PATH_SEPARATOR);
+ bool directName = (destPath.Back() != FCHAR_PATH_SEPARATOR);
if (directName)
{
if (numItems > 1)
@@ -477,9 +465,7 @@ STDMETHODIMP CFSFolder::MoveTo(
else
if (!NDirectory::CreateComplexDirectory(destPath))
{
- UString message = UString(L"can not create folder ") +
- destPath;
- RINOK(callback->ShowMessage(message));
+ RINOK(SendMessageError(callback, "can not create folder: ", destPath));
return E_ABORT;
}
@@ -488,10 +474,10 @@ STDMETHODIMP CFSFolder::MoveTo(
for (UInt32 i = 0; i < numItems; i++)
{
const CDirItem &fi = *_refs[indices[i]];
- UString destPath2 = destPath;
+ FString destPath2 = destPath;
if (!directName)
destPath2 += fi.Name;
- UString srcPath = _path + GetPrefix(fi) + fi.Name;
+ FString srcPath = _path + GetPrefix(fi) + fi.Name;
if (fi.IsDir())
{
RINOK(MyMoveFolder(srcPath, destPath2, callback, completedSize));
@@ -515,7 +501,7 @@ STDMETHODIMP CFSFolder::CopyFrom(const wchar_t * /* fromFolderPath */,
{
UString path = (UString)fromFolderPath + itemsPaths[i];
- CFileInfoW fi;
+ CFileInfo fi;
if (!FindFile(path, fi))
return ::GetLastError();
if (fi.IsDir())
@@ -544,4 +530,9 @@ STDMETHODIMP CFSFolder::CopyFrom(const wchar_t * /* fromFolderPath */,
return E_NOTIMPL;
}
+STDMETHODIMP CFSFolder::CopyFromFile(UInt32 /* index */, const wchar_t * /* fullFilePath */, IProgress * /* progress */)
+{
+ return E_NOTIMPL;
+}
+
}