From 3698532b892fee0608efd0d3c2673a9666de4b06 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Thu, 19 Aug 2004 10:43:15 +0000 Subject: [PATCH] PATCH: [ 982140 ] Merge7z : compress folders -Submitted by Laoran --- ArchiveSupport/Merge7z/Merge7z311.cpp | 88 +++++++++++++++++++++++++++++------ ArchiveSupport/Merge7z/Merge7z311.dsp | 8 ++++ ArchiveSupport/Merge7z/Merge7z312.dsp | 8 ++++ ArchiveSupport/Merge7z/Merge7z313.dsp | 8 ++++ Src/readme.txt | 5 ++ 5 files changed, 104 insertions(+), 13 deletions(-) diff --git a/ArchiveSupport/Merge7z/Merge7z311.cpp b/ArchiveSupport/Merge7z/Merge7z311.cpp index 9e06c85dc..a7dd52285 100755 --- a/ArchiveSupport/Merge7z/Merge7z311.cpp +++ b/ArchiveSupport/Merge7z/Merge7z311.cpp @@ -30,6 +30,8 @@ DATE: BY: DESCRIPTION: ========== ================== ================================================ 2004/03/15 Jochen Tucht Fix Visual Studio 2003 build issue +2004/08/19 Laurent Ganier Compression of folders + Through EnumerateDirectory (from code of 7zip) */ @@ -40,6 +42,7 @@ DATE: BY: DESCRIPTION: #include "7zip/FileManager/OpenCallback.h" #include "7zip/FileManager/ExtractCallback.h" #include "7zip/FileManager/UpdateCallback100.h" +#include "7zip/UI/Common/EnumDirItems.h" /** * @brief Extraction thread @@ -254,8 +257,37 @@ public: } }; + +/** + * @brief Fill in dirItems with the files from a folder and its subfolders + * + * @note Duplication from 7zip source (EnumDirItems.cpp), because the function is static + */ +using namespace NFile; +using namespace NName; +static void EnumerateDirectory( + const UString &baseFolderPrefix, + const UString &directory, + const UString &prefix, + CObjectVector &dirItems) +{ + NFind::CEnumeratorW enumerator(baseFolderPrefix + directory + wchar_t(kAnyStringWildcard)); + NFind::CFileInfoW fileInfo; + while (enumerator.Next(fileInfo)) + { + AddDirFileInfo(prefix, directory + fileInfo.Name, fileInfo, dirItems); + if (fileInfo.IsDirectory()) + { + EnumerateDirectory(baseFolderPrefix, directory + fileInfo.Name + wchar_t(kDirDelimiter), + prefix + fileInfo.Name + wchar_t(kDirDelimiter), dirItems); + } + } +} + /** * @brief Compression method accessible from outside + * + * @note See CAgent::DoOperation (in 7zip source) for model */ HRESULT Format7zDLL::Interface::CompressArchive(HWND hwndParent, LPCTSTR path, Merge7z::DirItemEnumerator *etor) { @@ -290,6 +322,10 @@ HRESULT Format7zDLL::Interface::CompressArchive(HWND hwndParent, LPCTSTR path, M false, // passwordIsDefined UString() // password ); + + // Get the fileTimeType to compare new files and files already in archive + // We do not really care because we consider that the dest archive is empty + /* NFileTimeType::EEnum fileTimeType; UINT32 value; if COMPLAIN(outArchive->GetFileTimeType(&value) != S_OK) @@ -306,17 +342,18 @@ HRESULT Format7zDLL::Interface::CompressArchive(HWND hwndParent, LPCTSTR path, M default: ComplainCantOpen(path); } + */ - UINT count = etor->Open(); - CObjectVector operationChain; - operationChain.Reserve(count); + // First fill the items to compress CObjectVector dirItems; - dirItems.Reserve(count); + UINT count = etor->Open(); while (count--) { Merge7z::DirItemEnumerator::Item etorItem; etorItem.Mask.Item = 0; Merge7z::Envelope *envelope = etor->Enum(etorItem); + + // fill in the default values from the enumerator CDirItem item; if (etorItem.Mask.Item & etorItem.Mask.Name) item.Name = GetUnicodeString(etorItem.Name); @@ -336,8 +373,10 @@ HRESULT Format7zDLL::Interface::CompressArchive(HWND hwndParent, LPCTSTR path, M { envelope->Free(); } + if (etorItem.Mask.Item && (etorItem.Mask.Item & (etorItem.Mask.NeedFindFile|etorItem.Mask.CheckIfPresent)) != etorItem.Mask.NeedFindFile) { + // Check the info from the disk NFile::NFind::CFileInfoW fileInfo; if (NFile::NFind::FindFile(item.FullPath, fileInfo)) { @@ -353,29 +392,52 @@ HRESULT Format7zDLL::Interface::CompressArchive(HWND hwndParent, LPCTSTR path, M item.LastAccessTime = fileInfo.LastAccessTime; if (!(etorItem.Mask.Item & etorItem.Mask.LastWriteTime)) item.LastWriteTime = fileInfo.LastWriteTime; + dirItems.Add(item); + + // Recurse into directories (call a function of 7zip) + const UString baseFolderPrefix = L""; + if (fileInfo.IsDirectory()) + { + EnumerateDirectory(baseFolderPrefix, item.FullPath + L'\\', + item.Name + L'\\', dirItems); + } } else { + // file not valid, forget it if COMPLAIN(!(etorItem.Mask.Item & etorItem.Mask.CheckIfPresent)) { ComplainCantOpen(GetSystemString(item.FullPath)); } - etorItem.Mask.Item = 0; } } - if (etorItem.Mask.Item) + else if (etorItem.Mask.Item) { - CUpdatePair2 pair2; - pair2.IsAnti = false; - pair2.DirItemIndex = dirItems.Add(item); - pair2.ExistInArchive = false; - pair2.ExistOnDisk = true; - pair2.NewData = pair2.NewProperties = true; - operationChain.Add(pair2); + // No check from disk, simply use info from enumerators (risky) + dirItems.Add(item); } } + // Build the operationChain. One element per item + CObjectVector operationChain; + CUpdatePair2 pair2; + pair2.IsAnti = false; + pair2.ExistInArchive = false; + pair2.ExistOnDisk = true; + pair2.NewData = pair2.NewProperties = true; + + operationChain.Reserve(dirItems.Size()); + int i; + for (i = 0 ; i < dirItems.Size() ; i++) + { + pair2.DirItemIndex = i; + operationChain.Add(pair2); + } + + // No items in dest archive. We always recreate the dest archive CObjectVector archiveItems; + + // Now compress... updateCallbackSpec->Init(UString()/*folderPrefix*/, &dirItems, &archiveItems, &operationChain, NULL, updateCallback100); diff --git a/ArchiveSupport/Merge7z/Merge7z311.dsp b/ArchiveSupport/Merge7z/Merge7z311.dsp index 4d198ce83..23d15c013 100755 --- a/ArchiveSupport/Merge7z/Merge7z311.dsp +++ b/ArchiveSupport/Merge7z/Merge7z311.dsp @@ -152,6 +152,10 @@ LINK32=link.exe # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File +SOURCE=..\..\..\7z313\7zip\UI\Common\EnumDirItems.cpp +# End Source File +# Begin Source File + SOURCE=.\Merge7z.def # End Source File # Begin Source File @@ -191,6 +195,10 @@ SOURCE=.\tools.h # Begin Group "Header-Dateien" # PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\..\..\7z313\7zip\UI\Common\EnumDirItems.h +# End Source File # End Group # Begin Group "Ressourcendateien" diff --git a/ArchiveSupport/Merge7z/Merge7z312.dsp b/ArchiveSupport/Merge7z/Merge7z312.dsp index 16db9f0c2..52a61b79e 100755 --- a/ArchiveSupport/Merge7z/Merge7z312.dsp +++ b/ArchiveSupport/Merge7z/Merge7z312.dsp @@ -152,6 +152,10 @@ LINK32=link.exe # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File +SOURCE=..\..\..\7z313\7zip\UI\Common\EnumDirItems.cpp +# End Source File +# Begin Source File + SOURCE=.\Merge7z.def # End Source File # Begin Source File @@ -191,6 +195,10 @@ SOURCE=.\tools.h # Begin Group "Header-Dateien" # PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\..\..\7z313\7zip\UI\Common\EnumDirItems.h +# End Source File # End Group # Begin Group "Ressourcendateien" diff --git a/ArchiveSupport/Merge7z/Merge7z313.dsp b/ArchiveSupport/Merge7z/Merge7z313.dsp index 94821968b..675f16932 100755 --- a/ArchiveSupport/Merge7z/Merge7z313.dsp +++ b/ArchiveSupport/Merge7z/Merge7z313.dsp @@ -152,6 +152,10 @@ LINK32=link.exe # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File +SOURCE=..\..\..\7z313\7zip\UI\Common\EnumDirItems.cpp +# End Source File +# Begin Source File + SOURCE=.\Merge7z.def # End Source File # Begin Source File @@ -191,6 +195,10 @@ SOURCE=.\tools.h # Begin Group "Header-Dateien" # PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\..\..\7z313\7zip\UI\Common\EnumDirItems.h +# End Source File # End Group # Begin Group "Ressourcendateien" diff --git a/Src/readme.txt b/Src/readme.txt index b408d9aae..71e0b3297 100644 --- a/Src/readme.txt +++ b/Src/readme.txt @@ -1,3 +1,8 @@ +2004-08-19 Kimmo + PATCH: [ 982140 ] Merge7z : compress folders + Submitted by Laoran + Merge7z: Merge7z311.cpp Merge7z311.dsp Merge7z312.dsp Merge7z313.dsp + 2004-08-18 Kimmo RFE: [ 952959 ] split Are you sure you want to copy into more lines Src: Merge.rc -- 2.11.0