From 76db3591205eea36d42ed9539110938f9d06cf37 Mon Sep 17 00:00:00 2001 From: shunf4 Date: Fri, 10 May 2024 15:52:53 +0800 Subject: [PATCH] feat: do not set time for sole folder in extraction --- CPP/7zip/UI/Agent/Agent.cpp | 3 +++ CPP/7zip/UI/Agent/ArchiveFolder.cpp | 3 ++- CPP/7zip/UI/Agent/IFolderArchive.h | 1 + CPP/7zip/UI/Common/ArchiveExtractCallback.cpp | 7 +++++-- CPP/7zip/UI/Common/ArchiveExtractCallback.h | 1 + CPP/7zip/UI/FileManager/App.cpp | 12 ++++++++++-- CPP/7zip/UI/FileManager/Panel.h | 4 +++- CPP/7zip/UI/FileManager/PanelCopy.cpp | 1 + CPP/7zip/UI/FileManager/PanelDrag.cpp | 14 ++++++++++++++ 9 files changed, 40 insertions(+), 6 deletions(-) diff --git a/CPP/7zip/UI/Agent/Agent.cpp b/CPP/7zip/UI/Agent/Agent.cpp index 6761b284..124d2521 100755 --- a/CPP/7zip/UI/Agent/Agent.cpp +++ b/CPP/7zip/UI/Agent/Agent.cpp @@ -1457,6 +1457,7 @@ Z7_COM7F_IMF(CAgentFolder::Extract(const UInt32 *indices, UInt32 numItems, Int32 includeAltStreams, Int32 replaceAltStreamColon, + Int64 soleFolderIndex, NExtract::NPathMode::EEnum pathMode, NExtract::NOverwriteMode::EEnum overwriteMode, const wchar_t *path, @@ -1535,6 +1536,8 @@ Z7_COM7F_IMF(CAgentFolder::Extract(const UInt32 *indices, // do we need another base folder for subfolders ? extractCallbackSpec->DirPathPrefix_for_HashFiles = _agentSpec->_hashBaseFolderPrefix; + extractCallbackSpec->SoleFolderIndex = soleFolderIndex; + CUIntVector realIndices; GetRealIndices(indices, numItems, IntToBool(includeAltStreams), false, // includeFolderSubItemsInFlatMode diff --git a/CPP/7zip/UI/Agent/ArchiveFolder.cpp b/CPP/7zip/UI/Agent/ArchiveFolder.cpp index 89b20dcb..cf933d23 100755 --- a/CPP/7zip/UI/Agent/ArchiveFolder.cpp +++ b/CPP/7zip/UI/Agent/ArchiveFolder.cpp @@ -24,7 +24,7 @@ Z7_COM7F_IMF(CAgentFolder::SetZoneIdMode(NExtract::NZoneIdMode::EEnum zoneMode)) Z7_COM7F_IMF(CAgentFolder::CopyTo(Int32 moveMode, const UInt32 *indices, UInt32 numItems, - Int32 includeAltStreams, Int32 replaceAltStreamCharsMode, + Int32 includeAltStreams, Int32 replaceAltStreamCharsMode, Int64 soleFolderIndex, const wchar_t *path, IFolderOperationsExtractCallback *callback)) { if (moveMode) @@ -45,6 +45,7 @@ Z7_COM7F_IMF(CAgentFolder::CopyTo(Int32 moveMode, const UInt32 *indices, UInt32 return Extract(indices, numItems, includeAltStreams, replaceAltStreamCharsMode, + soleFolderIndex, pathMode, NExtract::NOverwriteMode::kAsk, path, BoolToInt(false), extractCallback2); COM_TRY_END diff --git a/CPP/7zip/UI/Agent/IFolderArchive.h b/CPP/7zip/UI/Agent/IFolderArchive.h index 55f14234..79ceff02 100755 --- a/CPP/7zip/UI/Agent/IFolderArchive.h +++ b/CPP/7zip/UI/Agent/IFolderArchive.h @@ -27,6 +27,7 @@ IArchiveFolder is used by: x(Extract(const UInt32 *indices, UInt32 numItems, \ Int32 includeAltStreams, \ Int32 replaceAltStreamCharsMode, \ + Int64 soleFolderIndex, \ NExtract::NPathMode::EEnum pathMode, \ NExtract::NOverwriteMode::EEnum overwriteMode, \ const wchar_t *path, Int32 testMode, \ diff --git a/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp b/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp index 4b0cbeda..c9553756 100755 --- a/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp +++ b/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp @@ -275,7 +275,8 @@ CArchiveExtractCallback::CArchiveExtractCallback(): Write_CTime(true), Write_ATime(true), Write_MTime(true), - _multiArchives(false) + _multiArchives(false), + SoleFolderIndex(-1LL) { LocalProgressSpec = new CLocalProgress(); _localProgress = LocalProgressSpec; @@ -378,6 +379,8 @@ void CArchiveExtractCallback::Init( NDir::MyGetFullPathName(directoryPath, _dirPathPrefix_Full); NName::NormalizeDirPathPrefix(_dirPathPrefix_Full); } + + SoleFolderIndex = -1LL; } @@ -1142,7 +1145,7 @@ void CArchiveExtractCallback::CreateFolders() CDirPathTime pt; GetFiTimesCAM(pt); - if (pt.IsSomeTimeDefined()) + if (pt.IsSomeTimeDefined() && _index != SoleFolderIndex) { pt.Path = fullPathNew; pt.SetDirTime(); diff --git a/CPP/7zip/UI/Common/ArchiveExtractCallback.h b/CPP/7zip/UI/Common/ArchiveExtractCallback.h index 5ed20f3f..41e34258 100755 --- a/CPP/7zip/UI/Common/ArchiveExtractCallback.h +++ b/CPP/7zip/UI/Common/ArchiveExtractCallback.h @@ -455,6 +455,7 @@ public: #endif _keepAndReplaceEmptyDirPrefixes = keepAndReplaceEmptyDirPrefixes; NumFolders = NumFiles = NumAltStreams = UnpackSize = AltStreams_UnpackSize = 0; + SoleFolderIndex = -1LL; } #ifndef Z7_SFX diff --git a/CPP/7zip/UI/FileManager/App.cpp b/CPP/7zip/UI/FileManager/App.cpp index 35f5a60c..6cd43b87 100755 --- a/CPP/7zip/UI/FileManager/App.cpp +++ b/CPP/7zip/UI/FileManager/App.cpp @@ -496,7 +496,7 @@ static void AddPropValueToSum(IFolderFolder *folder, UInt32 index, PROPID propID sum = (UInt64)(Int64)-1; } -UString CPanel::GetItemsInfoString(const CRecordVector &indices, int *soleDir) +UString CPanel::GetItemsInfoString(const CRecordVector &indices, int *soleDir, Int64 &soleFolderIndex) { UString info; UInt64 numDirs, numFiles, filesSize, foldersSize; @@ -511,6 +511,7 @@ UString CPanel::GetItemsInfoString(const CRecordVector &indices, int *so { if (i == 0) { *soleDir = 1; + soleFolderIndex = (Int64)index; } else { *soleDir = 0; } @@ -525,6 +526,10 @@ UString CPanel::GetItemsInfoString(const CRecordVector &indices, int *so } } + if ((*soleDir) != 1) { + soleFolderIndex = -1LL; + } + AddValuePair2(info, IDS_PROP_FOLDERS, numDirs, foldersSize); AddValuePair2(info, IDS_PROP_FILES, numFiles, filesSize); int numDefined = ((foldersSize != (UInt64)(Int64)-1) && foldersSize != 0) ? 1: 0; @@ -629,6 +634,8 @@ void CApp::OnCopy(bool move, bool copyToSame, unsigned srcPanelIndex) const bool useFullItemPaths = srcPanel.Is_IO_FS_Folder(); // maybe we need flat also here ?? + Int64 soleFolderIndex = -1LL; // initially unset value + { CCopyDialog copyDialog; @@ -636,7 +643,7 @@ void CApp::OnCopy(bool move, bool copyToSame, unsigned srcPanelIndex) copyDialog.Value = destPath; LangString(move ? IDS_MOVE : IDS_COPY, copyDialog.Title); LangString(move ? IDS_MOVE_TO : IDS_COPY_TO, copyDialog.Static); - copyDialog.Info = srcPanel.GetItemsInfoString(indices, ©Dialog.soleDir); + copyDialog.Info = srcPanel.GetItemsInfoString(indices, ©Dialog.soleDir, soleFolderIndex); copyDialog.m_currentFolderPrefix = srcPanel._currentFolderPrefix; if (copyDialog.Create(srcPanel.GetParent()) != IDOK) @@ -815,6 +822,7 @@ void CApp::OnCopy(bool move, bool copyToSame, unsigned srcPanelIndex) options.includeAltStreams = true; options.replaceAltStreamChars = false; options.showErrorMessages = true; + options.soleFolderIndex = soleFolderIndex; result = srcPanel.CopyTo(options, indices, NULL); } diff --git a/CPP/7zip/UI/FileManager/Panel.h b/CPP/7zip/UI/FileManager/Panel.h index e4b6801e..6ccaa43a 100755 --- a/CPP/7zip/UI/FileManager/Panel.h +++ b/CPP/7zip/UI/FileManager/Panel.h @@ -265,6 +265,7 @@ struct CCopyToOptions NExtract::NZoneIdMode::EEnum ZoneIdMode; UString folder; + Int64 soleFolderIndex; UStringVector hashMethods; @@ -280,6 +281,7 @@ struct CCopyToOptions showErrorMessages(false), NeedRegistryZone(true), ZoneIdMode(NExtract::NZoneIdMode::kNone), + soleFolderIndex(-1LL), VirtFileSystemSpec(NULL), VirtFileSystem(NULL) {} @@ -971,7 +973,7 @@ public: void RefreshTitle(bool always = false) { _panelCallback->RefreshTitle(always); } void RefreshTitleAlways() { RefreshTitle(true); } - UString GetItemsInfoString(const CRecordVector &indices, int *soleDir); + UString GetItemsInfoString(const CRecordVector &indices, int *soleDir, Int64 &soleFolderIndex); }; class CMyBuffer diff --git a/CPP/7zip/UI/FileManager/PanelCopy.cpp b/CPP/7zip/UI/FileManager/PanelCopy.cpp index de3d7643..c2dfa07d 100755 --- a/CPP/7zip/UI/FileManager/PanelCopy.cpp +++ b/CPP/7zip/UI/FileManager/PanelCopy.cpp @@ -114,6 +114,7 @@ HRESULT CPanelCopyThread::ProcessVirt() &Indices.Front(), Indices.Size(), BoolToInt(options->includeAltStreams), BoolToInt(options->replaceAltStreamChars), + options->soleFolderIndex, options->folder, ExtractCallback); if (result2 == S_OK && !ExtractCallbackSpec->ThereAreMessageErrors) diff --git a/CPP/7zip/UI/FileManager/PanelDrag.cpp b/CPP/7zip/UI/FileManager/PanelDrag.cpp index 040444cb..5ad51e90 100755 --- a/CPP/7zip/UI/FileManager/PanelDrag.cpp +++ b/CPP/7zip/UI/FileManager/PanelDrag.cpp @@ -554,6 +554,7 @@ public: CRecordVector Indices; UString SrcDirPrefix_Temp; // FS directory with source files or Temp + Int64 SoleFolderIndex; UString DestDirPrefix_FromTarget; /* destination Path that was sent by Target via SetData(). it can be altstreams prefix. @@ -633,6 +634,7 @@ void CDataObject::CopyFromPanelTo_Folder() { CCopyToOptions options; options.folder = SrcDirPrefix_Temp; + options.soleFolderIndex = SoleFolderIndex; /* 15.13: fixed problem with mouse cursor for password window. DoDragDrop() probably calls SetCapture() to some hidden window. But it's problem, if we show some modal window, like MessageBox. @@ -1579,6 +1581,7 @@ void CPanel::OnDrag(LPNMLISTVIEW /* nmListView */, bool isRightButton) */ } + Int64 soleFolderIndex = -1LL; // initially unset value { UStringVector names; // names variable is USED for drag and drop from 7-zip to Explorer or to 7-zip archive folder. @@ -1592,6 +1595,15 @@ void CPanel::OnDrag(LPNMLISTVIEW /* nmListView */, bool isRightButton) else { s = GetItemName(index); + if (IsItem_Folder(index)) { + if (i == 0) { + soleFolderIndex = (Int64)index; + } else { + soleFolderIndex = -1LL; + } + } else { + soleFolderIndex = -1LL; + } /* // We use (keepAndReplaceEmptyPrefixes = true) in CAgentFolder::Extract // So the following code is not required. @@ -1620,6 +1632,7 @@ void CPanel::OnDrag(LPNMLISTVIEW /* nmListView */, bool isRightButton) dataObjectSpec->Panel = this; dataObjectSpec->Indices = indices; dataObjectSpec->SrcDirPrefix_Temp = dirPrefix; + dataObjectSpec->SoleFolderIndex = soleFolderIndex; dropSourceSpec->DataObjectSpec = dataObjectSpec; dropSourceSpec->DataObject = dataObjectSpec; @@ -1757,6 +1770,7 @@ void CPanel::OnDrag(LPNMLISTVIEW /* nmListView */, bool isRightButton) */ // options.moveMode = (moveIsAllowed && effect == DROPEFFECT_MOVE) // before v23.00: options.moveMode = moveIsAllowed; + options.soleFolderIndex = soleFolderIndex; if (moveIsAllowed) { if (dataObjectSpec->m_Transfer_WasSet)