diff options
author | Igor Pavlov <ipavlov@users.sourceforge.net> | 2015-06-15 03:00:00 +0300 |
---|---|---|
committer | Kornel LesiĆski <kornel@geekhood.net> | 2016-05-28 02:16:54 +0300 |
commit | 54490d51d5c6b0d794dcbad2d634d4c95fc25b6c (patch) | |
tree | c3c413656432c0ef87b2841c80e42b55ad17d4e8 /CPP/7zip/UI/FileManager/App.cpp | |
parent | 0713a3ab803e57401f18432148b4139e5fe6e5dd (diff) |
15.0515.05
Diffstat (limited to 'CPP/7zip/UI/FileManager/App.cpp')
-rw-r--r-- | CPP/7zip/UI/FileManager/App.cpp | 201 |
1 files changed, 140 insertions, 61 deletions
diff --git a/CPP/7zip/UI/FileManager/App.cpp b/CPP/7zip/UI/FileManager/App.cpp index 51c8d2db..b6a66975 100644 --- a/CPP/7zip/UI/FileManager/App.cpp +++ b/CPP/7zip/UI/FileManager/App.cpp @@ -140,8 +140,8 @@ HRESULT CApp::CreateOnePanel(int panelIndex, const UString &mainPath, const UStr } static void CreateToolbar(HWND parent, - NWindows::NControl::CImageList &imageList, - NWindows::NControl::CToolBar &toolBar, + NControl::CImageList &imageList, + NControl::CToolBar &toolBar, bool largeButtons) { toolBar.Attach(::CreateWindowEx(0, TOOLBARCLASSNAME, NULL, 0 @@ -364,7 +364,8 @@ void CApp::Save() if (panel._parentFolders.IsEmpty()) path = panel._currentFolderPrefix; else - path = GetFolderPath(panel._parentFolders[0].ParentFolder); + path = panel._parentFolders[0].ParentFolderPath; + // GetFolderPath(panel._parentFolders[0].ParentFolder); SavePanelPath(i, path); listMode.Panels[i] = panel.GetListViewMode(); SaveFlatView(i, panel._flatModeForArc); @@ -380,9 +381,12 @@ void CApp::Release() Panels[i].Release(); } -// reduces path to part that exists on disk +// reduces path to part that exists on disk (or root prefix of path) +// output path is normalized (with WCHAR_PATH_SEPARATOR) static void ReducePathToRealFileSystemPath(UString &path) { + unsigned prefixSize = GetRootPrefixSize(path); + while (!path.IsEmpty()) { if (NFind::DoesDirExist(us2fs(path))) @@ -390,63 +394,59 @@ static void ReducePathToRealFileSystemPath(UString &path) NName::NormalizeDirPathPrefix(path); break; } - int pos = path.ReverseFind(WCHAR_PATH_SEPARATOR); + int pos = path.ReverseFind_PathSepar(); if (pos < 0) { path.Empty(); break; } path.DeleteFrom(pos + 1); - if (path.Len() == 3 && path[1] == L':') + if ((unsigned)pos + 1 == prefixSize) break; - if (path.Len() > 2 && path[0] == '\\' && path[1] == '\\') - { - int nextPos = path.Find(WCHAR_PATH_SEPARATOR, 2); // pos after \\COMPNAME - if (nextPos > 0 && path.Find(WCHAR_PATH_SEPARATOR, nextPos + 1) == pos) - break; - } path.DeleteFrom(pos); } } -// return true for dir\, if dir exist +// returns: true, if such dir exists or is root +/* static bool CheckFolderPath(const UString &path) { UString pathReduced = path; ReducePathToRealFileSystemPath(pathReduced); return (pathReduced == path); } +*/ extern UString ConvertSizeToString(UInt64 value); -static UString AddSizeValue(UInt64 size) +static void AddSizeValue(UString &s, UInt64 size) { - return MyFormatNew(IDS_FILE_SIZE, ConvertSizeToString(size)); + s += MyFormatNew(IDS_FILE_SIZE, ConvertSizeToString(size)); } static void AddValuePair1(UString &s, UINT resourceID, UInt64 size) { - s += LangString(resourceID); + AddLangString(s, resourceID); s += L": "; - s += AddSizeValue(size); - s += L'\n'; + AddSizeValue(s, size); + s.Add_LF(); } void AddValuePair2(UString &s, UINT resourceID, UInt64 num, UInt64 size) { if (num == 0) return; - s += LangString(resourceID); + AddLangString(s, resourceID); s += L": "; s += ConvertSizeToString(num); if (size != (UInt64)(Int64)-1) { s += L" ( "; - s += AddSizeValue(size); + AddSizeValue(s, size); s += L" )"; } - s += L'\n'; + s.Add_LF(); } static void AddPropValueToSum(IFolderFolder *folder, int index, PROPID propID, UInt64 &sum) @@ -490,7 +490,7 @@ UString CPanel::GetItemsInfoString(const CRecordVector<UInt32> &indices) if (numDefined == 2) AddValuePair1(info, IDS_PROP_SIZE, filesSize + foldersSize); - info += L"\n"; + info.Add_LF(); info += _currentFolderPrefix; for (i = 0; i < indices.Size() && (int)i < (int)kCopyDialog_NumInfoLines - 6; i++) @@ -499,7 +499,7 @@ UString CPanel::GetItemsInfoString(const CRecordVector<UInt32> &indices) int index = indices[i]; info += GetItemRelPath(index); if (IsItem_Folder(index)) - info += WCHAR_PATH_SEPARATOR; + info.Add_PathSepar(); } if (i != indices.Size()) info += L"\n ..."; @@ -508,6 +508,20 @@ UString CPanel::GetItemsInfoString(const CRecordVector<UInt32> &indices) bool IsCorrectFsName(const UString &name); + + +/* Returns true, if path is path that can be used as path for File System functions +*/ + +/* +static bool IsFsPath(const FString &path) +{ + if (!IsAbsolutePath(path)) + return false; + unsigned prefixSize = GetRootPrefixSize(path); +} +*/ + void CApp::OnCopy(bool move, bool copyToSame, int srcPanelIndex) { int destPanelIndex = (NumPanels <= 1) ? srcPanelIndex : (1 - srcPanelIndex); @@ -517,7 +531,12 @@ void CApp::OnCopy(bool move, bool copyToSame, int srcPanelIndex) CPanel::CDisableTimerProcessing disableTimerProcessing1(destPanel); CPanel::CDisableTimerProcessing disableTimerProcessing2(srcPanel); - if (!srcPanel.DoesItSupportOperations()) + if (move) + { + if (!srcPanel.CheckBeforeUpdate(IDS_MOVE)) + return; + } + else if (!srcPanel.DoesItSupportOperations()) { srcPanel.MessageBoxErrorLang(IDS_OPERATION_IS_NOT_SUPPORTED); return; @@ -544,13 +563,15 @@ void CApp::OnCopy(bool move, bool copyToSame, int srcPanelIndex) srcPanel.GetOperatedIndicesSmart(indices); if (indices.Size() == 0) return; - destPath = destPanel._currentFolderPrefix; + destPath = destPanel.GetFsPath(); if (NumPanels == 1) ReducePathToRealFileSystemPath(destPath); } } + UStringVector copyFolders; ReadCopyHistory(copyFolders); + { CCopyDialog copyDialog; @@ -583,10 +604,10 @@ void CApp::OnCopy(bool move, bool copyToSame, int srcPanelIndex) if (IsAbsolutePath(destPath)) destPath.Empty(); else - destPath = srcPanel._currentFolderPrefix; + destPath = srcPanel.GetFsPath(); destPath += correctName; - #ifndef UNDER_CE + #if defined(_WIN32) && !defined(UNDER_CE) if (destPath.Len() > 0 && destPath[0] == '\\') if (destPath.Len() == 1 || destPath[1] != '\\') { @@ -595,59 +616,112 @@ void CApp::OnCopy(bool move, bool copyToSame, int srcPanelIndex) } #endif - if (indices.Size() > 1 || - (!destPath.IsEmpty() && destPath.Back() == WCHAR_PATH_SEPARATOR) || - NFind::DoesDirExist(us2fs(destPath)) || - srcPanel.IsArcFolder()) + bool possibleToUseDestPanel = false; + + if (CompareFileNames(destPath, destPanel.GetFsPath()) == 0) { - CreateComplexDir(us2fs(destPath)); - NName::NormalizeDirPathPrefix(destPath); - if (!CheckFolderPath(destPath)) + if (NumPanels == 1 || CompareFileNames(destPath, srcPanel.GetFsPath()) == 0) { - if (NumPanels < 2 || destPath != destPanel._currentFolderPrefix || !destPanel.DoesItSupportOperations()) - { - srcPanel.MessageBoxErrorLang(IDS_OPERATION_IS_NOT_SUPPORTED); - return; - } - useDestPanel = true; + srcPanel.MessageBoxMyError(L"Can not copy files onto itself"); + return; } + + if (destPanel.DoesItSupportOperations()) + possibleToUseDestPanel = true; } - else + + bool destIsFsPath = false; + + if (possibleToUseDestPanel) { - if (!IsCorrectFsName(destPath)) + if (destPanel.IsFSFolder() || destPanel.IsAltStreamsFolder()) + destIsFsPath = true; + else if (destPanel.IsFSDrivesFolder() || destPanel.IsRootFolder()) { - srcPanel.MessageBoxError(E_INVALIDARG); + srcPanel.MessageBoxErrorLang(IDS_OPERATION_IS_NOT_SUPPORTED); return; } - int pos = destPath.ReverseFind(WCHAR_PATH_SEPARATOR); - if (pos >= 0) + } + else + { + if (IsAltPathPrefix(us2fs(destPath))) { - UString prefix = destPath.Left(pos + 1); - CreateComplexDir(us2fs(prefix)); - if (!CheckFolderPath(prefix)) + // we allow alt streams dest only to alt stream folder in second panel + srcPanel.MessageBoxErrorLang(IDS_OPERATION_IS_NOT_SUPPORTED); + return; + /* + FString basePath = us2fs(destPath); + basePath.DeleteBack(); + if (!DoesFileOrDirExist(basePath)) { - srcPanel.MessageBoxErrorLang(IDS_OPERATION_IS_NOT_SUPPORTED); + srcPanel.MessageBoxError2Lines(basePath, ERROR_FILE_NOT_FOUND); // GetLastError() return; } + destIsFsPath = true; + */ + } + else + { + if (indices.Size() == 1 && + !destPath.IsEmpty() && destPath.Back() != WCHAR_PATH_SEPARATOR) + { + int pos = destPath.ReverseFind_PathSepar(); + if (pos < 0) + { + srcPanel.MessageBoxErrorLang(IDS_OPERATION_IS_NOT_SUPPORTED); + return; + } + { + /* + #ifdef _WIN32 + UString name = destPath.Ptr(pos + 1); + if (name.Find(L':') >= 0) + { + srcPanel.MessageBoxErrorLang(IDS_OPERATION_IS_NOT_SUPPORTED); + return; + } + #endif + */ + UString prefix = destPath.Left(pos + 1); + if (!CreateComplexDir(us2fs(prefix))) + { + srcPanel.MessageBoxError2Lines(prefix, GetLastError()); + return; + } + } + // bool isFolder = srcPanael.IsItem_Folder(indices[0]); + } + else + { + NName::NormalizeDirPathPrefix(destPath); + if (!CreateComplexDir(us2fs(destPath))) + { + srcPanel.MessageBoxError2Lines(destPath, GetLastError()); + return; + } + } + destIsFsPath = true; } } + if (!destIsFsPath) + useDestPanel = true; + AddUniqueStringToHeadOfList(copyFolders, destPath); while (copyFolders.Size() > 20) copyFolders.DeleteBack(); SaveCopyHistory(copyFolders); } - /* - if (destPath == destPanel._currentFolderPrefix) - { - if (destPanel.GetFolderTypeID() == L"PhysDrive") - useDestPanel = true; - } - */ + bool useSrcPanel = !useDestPanel || !srcPanel.Is_IO_FS_Folder(); - bool useSrcPanel = (!useDestPanel || !srcPanel.IsFsOrDrivesFolder() || destPanel.IsFSFolder()); bool useTemp = useSrcPanel && useDestPanel; + if (useTemp && NumPanels == 1) + { + srcPanel.MessageBoxErrorLang(IDS_OPERATION_IS_NOT_SUPPORTED); + return; + } + CTempDir tempDirectory; FString tempDirPrefix; if (useTemp) @@ -666,6 +740,7 @@ void CApp::OnCopy(bool move, bool copyToSame, int srcPanelIndex) CPanel::CDisableNotify disableNotify2(srcPanel); HRESULT result = S_OK; + if (useSrcPanel) { CCopyToOptions options; @@ -685,12 +760,13 @@ void CApp::OnCopy(bool move, bool copyToSame, int srcPanelIndex) if (useTemp) folderPrefix = fs2us(tempDirPrefix); else - folderPrefix = srcPanel._currentFolderPrefix; + folderPrefix = srcPanel.GetFsPath(); filePaths.ClearAndReserve(indices.Size()); FOR_VECTOR (i, indices) - filePaths.AddInReserved(srcPanel.GetItemRelPath(indices[i])); + filePaths.AddInReserved(srcPanel.GetItemRelPath2(indices[i])); result = destPanel.CopyFrom(move, folderPrefix, filePaths, true, 0); } + if (result != S_OK) { // disableNotify1.Restore(); @@ -705,15 +781,18 @@ void CApp::OnCopy(bool move, bool copyToSame, int srcPanelIndex) } RefreshTitleAlways(); + if (copyToSame || move) { srcPanel.RefreshListCtrl(srcSelState); } + if (!copyToSame) { destPanel.RefreshListCtrl(destSelState); srcPanel.KillSelection(); } + disableNotify1.Restore(); disableNotify2.Restore(); srcPanel.SetFocusToList(); @@ -831,7 +910,7 @@ void CApp::RefreshTitle(int panelIndex, bool always) void AddUniqueStringToHead(UStringVector &list, const UString &s) { for (unsigned i = 0; i < list.Size();) - if (s.IsEqualToNoCase(list[i])) + if (s.IsEqualTo_NoCase(list[i])) list.Delete(i); else i++; @@ -848,7 +927,7 @@ void CFolderHistory::Normalize() void CFolderHistory::AddString(const UString &s) { - NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); + NSynchronization::CCriticalSectionLock lock(_criticalSection); AddUniqueStringToHead(Strings, s); Normalize(); } |