diff options
Diffstat (limited to 'installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent')
11 files changed, 2288 insertions, 0 deletions
diff --git a/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/Agent.cpp b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/Agent.cpp new file mode 100644 index 000000000..0b8f7c370 --- /dev/null +++ b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/Agent.cpp @@ -0,0 +1,615 @@ +// Agent.cpp + +#include "StdAfx.h" + +#include "../../../../C/Sort.h" + +#include "Common/ComTry.h" + +#include "../Common/ArchiveExtractCallback.h" + +#include "Agent.h" + +using namespace NWindows; + +STDMETHODIMP CAgentFolder::GetAgentFolder(CAgentFolder **agentFolder) +{ + *agentFolder = this; + return S_OK; +} + +void CAgentFolder::LoadFolder(CProxyFolder *folder) +{ + int i; + CProxyItem item; + item.Folder = folder; + for (i = 0; i < folder->Folders.Size(); i++) + { + item.Index = i; + _items.Add(item); + LoadFolder(&folder->Folders[i]); + } + int start = folder->Folders.Size(); + for (i = 0; i < folder->Files.Size(); i++) + { + item.Index = start + i; + _items.Add(item); + } +} + +STDMETHODIMP CAgentFolder::LoadItems() +{ + if (!_agentSpec->_archiveLink.IsOpen) + return E_FAIL; + _items.Clear(); + if (_flatMode) + LoadFolder(_proxyFolderItem); + return S_OK; +} + +STDMETHODIMP CAgentFolder::GetNumberOfItems(UInt32 *numItems) +{ + if (_flatMode) + *numItems = _items.Size(); + else + *numItems = _proxyFolderItem->Folders.Size() +_proxyFolderItem->Files.Size(); + return S_OK; +} + +UString CAgentFolder::GetName(UInt32 index) const +{ + UInt32 realIndex; + const CProxyFolder *folder; + if (_flatMode) + { + const CProxyItem &item = _items[index]; + folder = item.Folder; + realIndex = item.Index; + } + else + { + folder = _proxyFolderItem; + realIndex = index; + } + + if (realIndex < (UInt32)folder->Folders.Size()) + return folder->Folders[realIndex].Name; + return folder->Files[realIndex - folder->Folders.Size()].Name; +} + +UString CAgentFolder::GetPrefix(UInt32 index) const +{ + if (!_flatMode) + return UString(); + const CProxyItem &item = _items[index]; + const CProxyFolder *folder = item.Folder; + UString path; + while (folder != _proxyFolderItem) + { + path = folder->Name + UString(WCHAR_PATH_SEPARATOR) + path; + folder = folder->Parent; + } + return path; +} + +UString CAgentFolder::GetFullPathPrefixPlusPrefix(UInt32 index) const +{ + return _proxyFolderItem->GetFullPathPrefix() + GetPrefix(index); +} + +void CAgentFolder::GetPrefixIfAny(UInt32 index, NCOM::CPropVariant &prop) const +{ + if (!_flatMode) + return; + prop = GetPrefix(index); +} + + +STDMETHODIMP CAgentFolder::GetProperty(UInt32 itemIndex, PROPID propID, PROPVARIANT *value) +{ + NCOM::CPropVariant prop; + const CProxyFolder *folder; + UInt32 realIndex; + if (_flatMode) + { + const CProxyItem &item = _items[itemIndex]; + folder = item.Folder; + realIndex = item.Index; + } + else + { + folder = _proxyFolderItem; + realIndex = itemIndex; + } + + if (realIndex < (UInt32)folder->Folders.Size()) + { + const CProxyFolder &item = folder->Folders[realIndex]; + if (!_flatMode && propID == kpidSize) + prop = item.Size; + else if (!_flatMode && propID == kpidPackSize) + prop = item.PackSize; + else + switch(propID) + { + case kpidIsDir: prop = true; break; + case kpidNumSubDirs: prop = item.NumSubFolders; break; + case kpidNumSubFiles: prop = item.NumSubFiles; break; + case kpidName: prop = item.Name; break; + case kpidCRC: + { + if (item.IsLeaf) + { + RINOK(_agentSpec->GetArchive()->GetProperty(item.Index, propID, value)); + } + if (item.CrcIsDefined && value->vt == VT_EMPTY) + prop = item.Crc; + break; + } + case kpidPrefix: GetPrefixIfAny(itemIndex, prop); break; + + default: + if (item.IsLeaf) + return _agentSpec->GetArchive()->GetProperty(item.Index, propID, value); + } + } + else + { + realIndex -= folder->Folders.Size(); + const CProxyFile &item = folder->Files[realIndex]; + switch(propID) + { + case kpidIsDir: prop = false; break; + case kpidName: prop = item.Name; break; + case kpidPrefix: GetPrefixIfAny(itemIndex, prop); break; + default: + return _agentSpec->GetArchive()->GetProperty(item.Index, propID, value); + } + } + prop.Detach(value); + return S_OK; +} + +HRESULT CAgentFolder::BindToFolder(CProxyFolder *folder, IFolderFolder **resultFolder) +{ + CMyComPtr<IFolderFolder> parentFolder; + if (folder->Parent != _proxyFolderItem) + { + RINOK(BindToFolder(folder->Parent, &parentFolder)); + } + else + parentFolder = this; + CAgentFolder *folderSpec = new CAgentFolder; + CMyComPtr<IFolderFolder> agentFolder = folderSpec; + folderSpec->Init(_proxyArchive, folder, parentFolder, _agentSpec); + *resultFolder = agentFolder.Detach(); + return S_OK; +} + +STDMETHODIMP CAgentFolder::BindToFolder(UInt32 index, IFolderFolder **resultFolder) +{ + COM_TRY_BEGIN + + CProxyFolder *folder; + UInt32 realIndex; + if (_flatMode) + { + const CProxyItem &item = _items[index]; + folder = item.Folder; + realIndex = item.Index; + } + else + { + folder = _proxyFolderItem; + realIndex = index; + } + if (realIndex >= (UInt32)folder->Folders.Size()) + return E_INVALIDARG; + return BindToFolder(&folder->Folders[realIndex], resultFolder); + COM_TRY_END +} + +STDMETHODIMP CAgentFolder::BindToFolder(const wchar_t *name, IFolderFolder **resultFolder) +{ + COM_TRY_BEGIN + int index = _proxyFolderItem->FindDirSubItemIndex(name); + if (index < 0) + return E_INVALIDARG; + return BindToFolder(index, resultFolder); + COM_TRY_END +} + +STDMETHODIMP CAgentFolder::BindToParentFolder(IFolderFolder **resultFolder) +{ + COM_TRY_BEGIN + CMyComPtr<IFolderFolder> parentFolder = _parentFolder; + *resultFolder = parentFolder.Detach(); + return S_OK; + COM_TRY_END +} + +STDMETHODIMP CAgentFolder::GetStream(UInt32 index, ISequentialInStream **stream) +{ + CMyComPtr<IInArchiveGetStream> getStream; + _agentSpec->GetArchive()->QueryInterface(IID_IInArchiveGetStream, (void **)&getStream); + if (!getStream) + return S_OK; + + const CProxyFolder *folder; + UInt32 realIndex; + if (_flatMode) + { + const CProxyItem &item = _items[index]; + folder = item.Folder; + realIndex = item.Index; + } + else + { + folder = _proxyFolderItem; + realIndex = index; + } + + UInt32 indexInArchive; + if (realIndex < (UInt32)folder->Folders.Size()) + { + const CProxyFolder &item = folder->Folders[realIndex]; + if (!item.IsLeaf) + return S_OK; + indexInArchive = item.Index; + } + else + indexInArchive = folder->Files[realIndex - folder->Folders.Size()].Index; + return getStream->GetStream(indexInArchive, stream); +} + +STATPROPSTG kProperties[] = +{ + { NULL, kpidNumSubDirs, VT_UI4}, + { NULL, kpidNumSubFiles, VT_UI4}, + { NULL, kpidPrefix, VT_BSTR} +}; + +static const UInt32 kNumProperties = sizeof(kProperties) / sizeof(kProperties[0]); + +struct CArchiveItemPropertyTemp +{ + UString Name; + PROPID ID; + VARTYPE Type; +}; + +STDMETHODIMP CAgentFolder::GetNumberOfProperties(UInt32 *numProperties) +{ + COM_TRY_BEGIN + RINOK(_agentSpec->GetArchive()->GetNumberOfProperties(numProperties)); + *numProperties += kNumProperties; + if (!_flatMode) + (*numProperties)--; + if (!_agentSpec->_proxyArchive->ThereIsPathProp) + (*numProperties)++; + return S_OK; + COM_TRY_END +} + +STDMETHODIMP CAgentFolder::GetPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) +{ + COM_TRY_BEGIN + UInt32 numProperties; + _agentSpec->GetArchive()->GetNumberOfProperties(&numProperties); + if (!_agentSpec->_proxyArchive->ThereIsPathProp) + { + if (index == 0) + { + *propID = kpidName; + *varType = VT_BSTR; + *name = 0; + return S_OK; + } + index--; + } + + if (index < numProperties) + { + RINOK(_agentSpec->GetArchive()->GetPropertyInfo(index, name, propID, varType)); + if (*propID == kpidPath) + *propID = kpidName; + } + else + { + const STATPROPSTG &srcItem = kProperties[index - numProperties]; + *propID = srcItem.propid; + *varType = srcItem.vt; + *name = 0; + } + return S_OK; + COM_TRY_END +} + +STATPROPSTG kFolderProps[] = +{ + { NULL, kpidSize, VT_UI8}, + { NULL, kpidPackSize, VT_UI8}, + { NULL, kpidNumSubDirs, VT_UI4}, + { NULL, kpidNumSubFiles, VT_UI4}, + { NULL, kpidCRC, VT_UI4} +}; + +static const UInt32 kNumFolderProps = sizeof(kFolderProps) / sizeof(kFolderProps[0]); + +STDMETHODIMP CAgentFolder::GetFolderProperty(PROPID propID, PROPVARIANT *value) +{ + COM_TRY_BEGIN + NWindows::NCOM::CPropVariant prop; + switch(propID) + { + case kpidSize: prop = _proxyFolderItem->Size; break; + case kpidPackSize: prop = _proxyFolderItem->PackSize; break; + case kpidNumSubDirs: prop = _proxyFolderItem->NumSubFolders; break; + case kpidNumSubFiles: prop = _proxyFolderItem->NumSubFiles; break; + case kpidName: prop = _proxyFolderItem->Name; break; + case kpidPath: prop = _proxyFolderItem->GetFullPathPrefix(); break; + case kpidType: prop = UString(L"7-Zip.") + _agentSpec->ArchiveType; break; + case kpidCRC: if (_proxyFolderItem->CrcIsDefined) prop = _proxyFolderItem->Crc; break; + } + prop.Detach(value); + return S_OK; + COM_TRY_END +} + +STDMETHODIMP CAgentFolder::GetNumberOfFolderProperties(UInt32 *numProperties) +{ + *numProperties = kNumFolderProps; + return S_OK; +} + +STDMETHODIMP CAgentFolder::GetFolderPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) +{ + // if (index < kNumFolderProps) + { + const STATPROPSTG &srcItem = kFolderProps[index]; + *propID = srcItem.propid; + *varType = srcItem.vt; + *name = 0; + return S_OK; + } +} + +STDMETHODIMP CAgentFolder::GetFolderArchiveProperties(IFolderArchiveProperties **object) +{ + CMyComPtr<IFolderArchiveProperties> temp = _agentSpec; + *object = temp.Detach(); + return S_OK; +} + +#ifdef NEW_FOLDER_INTERFACE + +STDMETHODIMP CAgentFolder::SetFlatMode(Int32 flatMode) +{ + _flatMode = IntToBool(flatMode); + return S_OK; +} + +#endif + +void CAgentFolder::GetRealIndices(const UInt32 *indices, UInt32 numItems, CUIntVector &realIndices) const +{ + if (!_flatMode) + { + _proxyFolderItem->GetRealIndices(indices, numItems, realIndices); + return; + } + realIndices.Clear(); + for(UInt32 i = 0; i < numItems; i++) + { + const CProxyItem &item = _items[indices[i]]; + const CProxyFolder *folder = item.Folder; + UInt32 realIndex = item.Index; + if (realIndex < (UInt32)folder->Folders.Size()) + continue; + realIndices.Add(folder->Files[realIndex - folder->Folders.Size()].Index); + } + HeapSort(&realIndices.Front(), realIndices.Size()); +} + +STDMETHODIMP CAgentFolder::Extract(const UInt32 *indices, + UInt32 numItems, + NExtract::NPathMode::EEnum pathMode, + NExtract::NOverwriteMode::EEnum overwriteMode, + const wchar_t *path, + Int32 testMode, + IFolderArchiveExtractCallback *extractCallback2) +{ + COM_TRY_BEGIN + CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback; + CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec; + UStringVector pathParts; + CProxyFolder *currentProxyFolder = _proxyFolderItem; + while (currentProxyFolder->Parent) + { + pathParts.Insert(0, currentProxyFolder->Name); + currentProxyFolder = currentProxyFolder->Parent; + } + + /* + if (_flatMode) + pathMode = NExtract::NPathMode::kNoPathnames; + */ + + extractCallbackSpec->InitForMulti(false, pathMode, overwriteMode); + + extractCallbackSpec->Init(NULL, &_agentSpec->GetArc(), + extractCallback2, + false, testMode ? true : false, false, + (path ? path : L""), + pathParts, + (UInt64)(Int64)-1); + CUIntVector realIndices; + GetRealIndices(indices, numItems, realIndices); + return _agentSpec->GetArchive()->Extract(&realIndices.Front(), + realIndices.Size(), testMode, extractCallback); + COM_TRY_END +} + +///////////////////////////////////////// +// CAgent + +CAgent::CAgent(): + _proxyArchive(NULL), + _codecs(0) +{ +} + +CAgent::~CAgent() +{ + if (_proxyArchive != NULL) + delete _proxyArchive; +} + +STDMETHODIMP CAgent::Open( + IInStream *inStream, + const wchar_t *filePath, + BSTR *archiveType, + IArchiveOpenCallback *openArchiveCallback) +{ + COM_TRY_BEGIN + _archiveFilePath = filePath; + NFile::NFind::CFileInfoW fi; + if (!inStream) + { + if (!fi.Find(_archiveFilePath)) + return ::GetLastError(); + if (fi.IsDir()) + return E_FAIL; + } + CArcInfoEx archiverInfo0, archiverInfo1; + + _compressCodecsInfo.Release(); + _codecs = new CCodecs; + _compressCodecsInfo = _codecs; + RINOK(_codecs->Load()); + + RINOK(_archiveLink.Open(_codecs, CIntVector(), false, inStream, _archiveFilePath, openArchiveCallback)); + + CArc &arc = _archiveLink.Arcs.Back(); + if (!inStream) + { + arc.MTimeDefined = !fi.IsDevice; + arc.MTime = fi.MTime; + } + + ArchiveType = _codecs->Formats[arc.FormatIndex].Name; + if (archiveType == 0) + return S_OK; + return StringToBstr(ArchiveType, archiveType); + COM_TRY_END +} + +STDMETHODIMP CAgent::ReOpen(IArchiveOpenCallback *openArchiveCallback) +{ + COM_TRY_BEGIN + if (_proxyArchive != NULL) + { + delete _proxyArchive; + _proxyArchive = NULL; + } + RINOK(_archiveLink.ReOpen(_codecs, _archiveFilePath, openArchiveCallback)); + return ReadItems(); + COM_TRY_END +} + +STDMETHODIMP CAgent::Close() +{ + COM_TRY_BEGIN + return _archiveLink.Close(); + COM_TRY_END +} + +/* +STDMETHODIMP CAgent::EnumProperties(IEnumSTATPROPSTG **EnumProperties) +{ + return _archive->EnumProperties(EnumProperties); +} +*/ + +HRESULT CAgent::ReadItems() +{ + if (_proxyArchive != NULL) + return S_OK; + _proxyArchive = new CProxyArchive(); + return _proxyArchive->Load(GetArc(), NULL); +} + +STDMETHODIMP CAgent::BindToRootFolder(IFolderFolder **resultFolder) +{ + COM_TRY_BEGIN + RINOK(ReadItems()); + CAgentFolder *folderSpec = new CAgentFolder; + CMyComPtr<IFolderFolder> rootFolder = folderSpec; + folderSpec->Init(_proxyArchive, &_proxyArchive->RootFolder, NULL, this); + *resultFolder = rootFolder.Detach(); + return S_OK; + COM_TRY_END +} + + +STDMETHODIMP CAgent::Extract( + NExtract::NPathMode::EEnum pathMode, + NExtract::NOverwriteMode::EEnum overwriteMode, + const wchar_t *path, + Int32 testMode, + IFolderArchiveExtractCallback *extractCallback2) +{ + COM_TRY_BEGIN + CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback; + CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec; + extractCallbackSpec->InitForMulti(false, pathMode, overwriteMode); + extractCallbackSpec->Init(NULL, &GetArc(), + extractCallback2, + false, testMode ? true : false, false, + path, + UStringVector(), + (UInt64)(Int64)-1); + return GetArchive()->Extract(0, (UInt32)(Int32)-1, testMode, extractCallback); + COM_TRY_END +} + +STDMETHODIMP CAgent::GetNumberOfProperties(UInt32 *numProperties) +{ + COM_TRY_BEGIN + return GetArchive()->GetNumberOfProperties(numProperties); + COM_TRY_END +} + +STDMETHODIMP CAgent::GetPropertyInfo(UInt32 index, + BSTR *name, PROPID *propID, VARTYPE *varType) +{ + COM_TRY_BEGIN + RINOK(GetArchive()->GetPropertyInfo(index, name, propID, varType)); + if (*propID == kpidPath) + *propID = kpidName; + return S_OK; + COM_TRY_END +} + +STDMETHODIMP CAgent::GetArchiveProperty(PROPID propID, PROPVARIANT *value) +{ + COM_TRY_BEGIN + return GetArchive()->GetArchiveProperty(propID, value); + COM_TRY_END +} + +STDMETHODIMP CAgent::GetNumberOfArchiveProperties(UInt32 *numProperties) +{ + COM_TRY_BEGIN + return GetArchive()->GetNumberOfArchiveProperties(numProperties); + COM_TRY_END +} + +STDMETHODIMP CAgent::GetArchivePropertyInfo(UInt32 index, + BSTR *name, PROPID *propID, VARTYPE *varType) +{ + COM_TRY_BEGIN + return GetArchive()->GetArchivePropertyInfo(index, + name, propID, varType); + COM_TRY_END +} diff --git a/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/Agent.h b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/Agent.h new file mode 100644 index 000000000..b95725e49 --- /dev/null +++ b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/Agent.h @@ -0,0 +1,232 @@ +// Agent/Agent.h + +#ifndef __AGENT_AGENT_H +#define __AGENT_AGENT_H + +#include "Common/MyCom.h" + +#include "Windows/PropVariant.h" + +#include "../Common/OpenArchive.h" +#include "../Common/UpdateAction.h" + +#ifdef NEW_FOLDER_INTERFACE +#include "../FileManager/IFolder.h" +#include "../Common/LoadCodecs.h" +#endif + +#include "AgentProxy.h" +#include "IFolderArchive.h" + +class CAgentFolder; + +DECL_INTERFACE(IArchiveFolderInternal, 0x01, 0xC) +{ + STDMETHOD(GetAgentFolder)(CAgentFolder **agentFolder) PURE; +}; + +struct CProxyItem +{ + CProxyFolder *Folder; + UInt32 Index; +}; + +class CAgent; + +class CAgentFolder: + public IFolderFolder, + public IFolderProperties, + public IGetFolderArchiveProperties, + public IArchiveFolder, + public IArchiveFolderInternal, + public IInArchiveGetStream, +#ifdef NEW_FOLDER_INTERFACE + public IFolderOperations, + public IFolderSetFlatMode, +#endif + public CMyUnknownImp +{ +public: + + MY_QUERYINTERFACE_BEGIN + MY_QUERYINTERFACE_ENTRY(IFolderFolder) + MY_QUERYINTERFACE_ENTRY(IFolderProperties) + MY_QUERYINTERFACE_ENTRY(IGetFolderArchiveProperties) + MY_QUERYINTERFACE_ENTRY(IArchiveFolder) + MY_QUERYINTERFACE_ENTRY(IArchiveFolderInternal) + MY_QUERYINTERFACE_ENTRY(IInArchiveGetStream) + #ifdef NEW_FOLDER_INTERFACE + MY_QUERYINTERFACE_ENTRY(IFolderOperations) + MY_QUERYINTERFACE_ENTRY(IFolderSetFlatMode) + #endif + MY_QUERYINTERFACE_END + MY_ADDREF_RELEASE + + void LoadFolder(CProxyFolder *folder); + HRESULT BindToFolder(CProxyFolder *folder, IFolderFolder **resultFolder); + void GetRealIndices(const UINT32 *indices, UINT32 numItems, CUIntVector &realIndices) const; + + INTERFACE_FolderFolder(;) + INTERFACE_FolderProperties(;) + + STDMETHOD(GetFolderArchiveProperties)(IFolderArchiveProperties **object); + + // IArchiveFolder + STDMETHOD(Extract)(const UINT32 *indices, UINT32 numItems, + NExtract::NPathMode::EEnum pathMode, + NExtract::NOverwriteMode::EEnum overwriteMode, + const wchar_t *path, + Int32 testMode, + IFolderArchiveExtractCallback *extractCallback); + + STDMETHOD(GetAgentFolder)(CAgentFolder **agentFolder); + + STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream); + + #ifdef NEW_FOLDER_INTERFACE + INTERFACE_FolderOperations(;) + + STDMETHOD(SetFlatMode)(Int32 flatMode); + #endif + + CAgentFolder(): _proxyFolderItem(NULL), _flatMode(0) {} + + void Init(CProxyArchive *proxyHandler, + CProxyFolder *proxyFolderItem, + IFolderFolder *parentFolder, + CAgent *agent) + { + _proxyArchive = proxyHandler; + _proxyFolderItem = proxyFolderItem; + _parentFolder = parentFolder; + _agent = (IInFolderArchive *)agent; + _agentSpec = agent; + } + + void GetPathParts(UStringVector &pathParts); + HRESULT CommonUpdateOperation( + bool deleteOperation, + bool createFolderOperation, + bool renameOperation, + const wchar_t *newItemName, + const NUpdateArchive::CActionSet *actionSet, + const UINT32 *indices, UINT32 numItems, + IFolderArchiveUpdateCallback *updateCallback100); + + + UString GetPrefix(UInt32 index) const; + UString GetName(UInt32 index) const; + UString GetFullPathPrefixPlusPrefix(UInt32 index) const; + void GetPrefixIfAny(UInt32 index, NWindows::NCOM::CPropVariant &propVariant) const; + +public: + CProxyArchive *_proxyArchive; + CProxyFolder *_proxyFolderItem; + CMyComPtr<IFolderFolder> _parentFolder; + CMyComPtr<IInFolderArchive> _agent; + CAgent *_agentSpec; + + CRecordVector<CProxyItem> _items; + bool _flatMode; +private: +}; + +class CAgent: + public IInFolderArchive, + public IFolderArchiveProperties, + #ifndef EXTRACT_ONLY + public IOutFolderArchive, + public ISetProperties, + #endif + public CMyUnknownImp +{ +public: + + MY_QUERYINTERFACE_BEGIN + MY_QUERYINTERFACE_ENTRY(IInFolderArchive) + MY_QUERYINTERFACE_ENTRY(IFolderArchiveProperties) + #ifndef EXTRACT_ONLY + MY_QUERYINTERFACE_ENTRY(IOutFolderArchive) + MY_QUERYINTERFACE_ENTRY(ISetProperties) + #endif + MY_QUERYINTERFACE_END + MY_ADDREF_RELEASE + + INTERFACE_IInFolderArchive(;) + INTERFACE_IFolderArchiveProperties(;) + + #ifndef EXTRACT_ONLY + INTERFACE_IOutFolderArchive(;) + + HRESULT CommonUpdate( + const wchar_t *newArchiveName, + int numUpdateItems, + IArchiveUpdateCallback *updateCallback); + + HRESULT CreateFolder( + const wchar_t *newArchiveName, + const wchar_t *folderName, + IFolderArchiveUpdateCallback *updateCallback100); + + HRESULT RenameItem( + const wchar_t *newArchiveName, + const UINT32 *indices, UINT32 numItems, + const wchar_t *newItemName, + IFolderArchiveUpdateCallback *updateCallback100); + + // ISetProperties + STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties); + #endif + + CCodecs *_codecs; + CMyComPtr<ICompressCodecsInfo> _compressCodecsInfo; + + CAgent(); + ~CAgent(); +private: + HRESULT ReadItems(); +public: + CProxyArchive *_proxyArchive; + CArchiveLink _archiveLink; + + + UString ArchiveType; + + UStringVector _names; + UString _folderPrefix; + + UString _archiveNamePrefix; + CAgentFolder *_agentFolder; + + UString _archiveFilePath; + + #ifndef EXTRACT_ONLY + CObjectVector<UString> m_PropNames; + CObjectVector<NWindows::NCOM::CPropVariant> m_PropValues; + #endif + + const CArc &GetArc() { return _archiveLink.Arcs.Back(); } + IInArchive *GetArchive() { return GetArc().Archive; } + bool CanUpdate() const { return _archiveLink.Arcs.Size() == 1; } +}; + +#ifdef NEW_FOLDER_INTERFACE +class CArchiveFolderManager: + public IFolderManager, + public CMyUnknownImp +{ +public: + MY_UNKNOWN_IMP1(IFolderManager) + + INTERFACE_IFolderManager(;) + + CArchiveFolderManager(): _codecs(0) {} +private: + void LoadFormats(); + int FindFormat(const UString &type); + CCodecs *_codecs; + CMyComPtr<ICompressCodecsInfo> _compressCodecsInfo; +}; +#endif + +#endif diff --git a/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/AgentOut.cpp b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/AgentOut.cpp new file mode 100644 index 000000000..51a5affa1 --- /dev/null +++ b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/AgentOut.cpp @@ -0,0 +1,535 @@ +// AgentOut.cpp + +#include "StdAfx.h" + +#include "Common/IntToString.h" +#include "Common/StringConvert.h" + +#include "Windows/Defs.h" +#include "Windows/FileDir.h" +#include "Windows/PropVariant.h" +#include "Windows/PropVariantConversions.h" +#include "Windows/Time.h" + +#include "../../Compress/CopyCoder.h" + +#include "../../Common/FileStreams.h" + +#include "../Common/EnumDirItems.h" +#include "../Common/HandlerLoader.h" +#include "../Common/OpenArchive.h" +#include "../Common/UpdateCallback.h" +#include "../Common/UpdatePair.h" + +#include "Agent.h" +#include "UpdateCallbackAgent.h" + +using namespace NWindows; +using namespace NCOM; + +STDMETHODIMP CAgent::SetFolder(IFolderFolder *folder) +{ + _archiveNamePrefix.Empty(); + if (folder == NULL) + { + _agentFolder = NULL; + return S_OK; + } + else + { + CMyComPtr<IFolderFolder> archiveFolder = folder; + CMyComPtr<IArchiveFolderInternal> archiveFolderInternal; + RINOK(archiveFolder.QueryInterface(IID_IArchiveFolderInternal, &archiveFolderInternal)); + RINOK(archiveFolderInternal->GetAgentFolder(&_agentFolder)); + } + + UStringVector pathParts; + pathParts.Clear(); + CMyComPtr<IFolderFolder> folderItem = folder; + if (folderItem != NULL) + for (;;) + { + CMyComPtr<IFolderFolder> newFolder; + folderItem->BindToParentFolder(&newFolder); + if (newFolder == NULL) + break; + + NCOM::CPropVariant prop; + if (folderItem->GetFolderProperty(kpidName, &prop) == S_OK) + if (prop.vt == VT_BSTR) + pathParts.Insert(0, (const wchar_t *)prop.bstrVal); + folderItem = newFolder; + } + + for (int i = 0; i < pathParts.Size(); i++) + { + _archiveNamePrefix += pathParts[i]; + _archiveNamePrefix += WCHAR_PATH_SEPARATOR; + } + return S_OK; +} + +STDMETHODIMP CAgent::SetFiles(const wchar_t *folderPrefix, + const wchar_t **names, UInt32 numNames) +{ + _folderPrefix = folderPrefix; + _names.Clear(); + _names.Reserve(numNames); + for (UInt32 i = 0; i < numNames; i++) + _names.Add(names[i]); + return S_OK; +} + +static HRESULT EnumerateArchiveItems(CAgent *agent, + const CProxyFolder &item, + const UString &prefix, + CObjectVector<CArcItem> &arcItems) +{ + int i; + for (i = 0; i < item.Files.Size(); i++) + { + const CProxyFile &fileItem = item.Files[i]; + CArcItem ai; + RINOK(agent->GetArc().GetItemMTime(fileItem.Index, ai.MTime, ai.MTimeDefined)); + + CPropVariant property; + agent->GetArchive()->GetProperty(fileItem.Index, kpidSize, &property); + ai.SizeDefined = (property.vt != VT_EMPTY); + if (ai.SizeDefined) + ai.Size = ConvertPropVariantToUInt64(property); + ai.IsDir = false; + ai.Name = prefix + fileItem.Name; + ai.Censored = true; // test it + ai.IndexInServer = fileItem.Index; + arcItems.Add(ai); + } + for (i = 0; i < item.Folders.Size(); i++) + { + const CProxyFolder &dirItem = item.Folders[i]; + UString fullName = prefix + dirItem.Name; + if (dirItem.IsLeaf) + { + CArcItem ai; + RINOK(agent->GetArc().GetItemMTime(dirItem.Index, ai.MTime, ai.MTimeDefined)); + ai.IsDir = true; + ai.SizeDefined = false; + ai.Name = fullName; + ai.Censored = true; // test it + ai.IndexInServer = dirItem.Index; + arcItems.Add(ai); + } + RINOK(EnumerateArchiveItems(agent, dirItem, fullName + UString(WCHAR_PATH_SEPARATOR), arcItems)); + } + return S_OK; +} + +struct CAgUpCallbackImp: public IUpdateProduceCallback +{ + const CObjectVector<CArcItem> *_arcItems; + IFolderArchiveUpdateCallback *_callback; + + CAgUpCallbackImp(const CObjectVector<CArcItem> *a, + IFolderArchiveUpdateCallback *callback): _arcItems(a), _callback(callback) {} + HRESULT ShowDeleteFile(int arcIndex); +}; + +HRESULT CAgUpCallbackImp::ShowDeleteFile(int arcIndex) +{ + return _callback->DeleteOperation((*_arcItems)[arcIndex].Name); +} + +STDMETHODIMP CAgent::DoOperation( + CCodecs *codecs, + int formatIndex, + const wchar_t *newArchiveName, + const Byte *stateActions, + const wchar_t *sfxModule, + IFolderArchiveUpdateCallback *updateCallback100) +{ + if (!CanUpdate()) + return E_NOTIMPL; + NUpdateArchive::CActionSet actionSet; + int i; + for (i = 0; i < NUpdateArchive::NPairState::kNumValues; i++) + actionSet.StateActions[i] = (NUpdateArchive::NPairAction::EEnum)stateActions[i]; + + CDirItems dirItems; + + { + UString folderPrefix = _folderPrefix; + NFile::NName::NormalizeDirPathPrefix(folderPrefix); + UStringVector errorPaths; + CRecordVector<DWORD> errorCodes; + dirItems.EnumerateDirItems2(folderPrefix, _archiveNamePrefix, _names, errorPaths, errorCodes); + if (errorCodes.Size() > 0) + return errorCodes.Front(); + } + + CMyComPtr<IOutArchive> outArchive; + if (GetArchive()) + { + RINOK(GetArchive()->QueryInterface(IID_IOutArchive, (void **)&outArchive)); + } + else + { + if (formatIndex < 0) + return E_FAIL; + RINOK(codecs->CreateOutArchive(formatIndex, outArchive)); + #ifdef EXTERNAL_CODECS + { + CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo; + outArchive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo); + if (setCompressCodecsInfo) + { + RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs)); + } + } + #endif + + } + + NFileTimeType::EEnum fileTimeType; + UInt32 value; + RINOK(outArchive->GetFileTimeType(&value)); + + switch(value) + { + case NFileTimeType::kWindows: + case NFileTimeType::kDOS: + case NFileTimeType::kUnix: + fileTimeType = NFileTimeType::EEnum(value); + break; + default: + return E_FAIL; + } + + + CObjectVector<CArcItem> arcItems; + if (GetArchive()) + { + RINOK(ReadItems()); + EnumerateArchiveItems(this, _proxyArchive->RootFolder, L"", arcItems); + } + + CRecordVector<CUpdatePair2> updatePairs2; + + { + CRecordVector<CUpdatePair> updatePairs; + GetUpdatePairInfoList(dirItems, arcItems, fileTimeType, updatePairs); + CAgUpCallbackImp upCallback(&arcItems, updateCallback100); + UpdateProduce(updatePairs, actionSet, updatePairs2, &upCallback); + } + + UInt32 numFiles = 0; + for (i = 0; i < updatePairs2.Size(); i++) + if (updatePairs2[i].NewData) + numFiles++; + + if (updateCallback100) + { + RINOK(updateCallback100->SetNumFiles(numFiles)); + } + + CUpdateCallbackAgent updateCallbackAgent; + updateCallbackAgent.SetCallback(updateCallback100); + CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback; + CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec ); + + updateCallbackSpec->DirItems = &dirItems; + updateCallbackSpec->ArcItems = &arcItems; + updateCallbackSpec->UpdatePairs = &updatePairs2; + updateCallbackSpec->Archive = GetArchive(); + updateCallbackSpec->Callback = &updateCallbackAgent; + + COutFileStream *outStreamSpec = new COutFileStream; + CMyComPtr<IOutStream> outStream(outStreamSpec); + UString archiveName = newArchiveName; + { + UString resultPath; + int pos; + if (!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos)) + return E_FAIL; + NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos)); + } + if (!outStreamSpec->Create(archiveName, true)) + { + // ShowLastErrorMessage(); + return E_FAIL; + } + + CMyComPtr<ISetProperties> setProperties; + if (outArchive->QueryInterface(IID_ISetProperties, (void **)&setProperties) == S_OK) + { + if (m_PropNames.Size() == 0) + { + RINOK(setProperties->SetProperties(0, 0, 0)); + } + else + { + CRecordVector<const wchar_t *> names; + for(i = 0; i < m_PropNames.Size(); i++) + names.Add((const wchar_t *)m_PropNames[i]); + + NWindows::NCOM::CPropVariant *propValues = new NWindows::NCOM::CPropVariant[m_PropValues.Size()]; + try + { + for (int i = 0; i < m_PropValues.Size(); i++) + propValues[i] = m_PropValues[i]; + RINOK(setProperties->SetProperties(&names.Front(), propValues, names.Size())); + } + catch(...) + { + delete []propValues; + return E_FAIL; + } + delete []propValues; + } + } + m_PropNames.Clear(); + m_PropValues.Clear(); + + if (sfxModule != NULL) + { + CInFileStream *sfxStreamSpec = new CInFileStream; + CMyComPtr<IInStream> sfxStream(sfxStreamSpec); + if (!sfxStreamSpec->Open(sfxModule)) + return E_FAIL; + // throw "Can't open sfx module"; + RINOK(NCompress::CopyStream(sfxStream, outStream, NULL)); + } + + RINOK(outArchive->UpdateItems(outStream, updatePairs2.Size(),updateCallback)); + return outStreamSpec->Close(); +} + +STDMETHODIMP CAgent::DoOperation2( + const wchar_t *newArchiveName, + const Byte *stateActions, + const wchar_t *sfxModule, + IFolderArchiveUpdateCallback *updateCallback100) +{ + return DoOperation(_codecs, -1, newArchiveName, + stateActions, sfxModule, updateCallback100); +} + +HRESULT CAgent::CommonUpdate( + const wchar_t *newArchiveName, + int numUpdateItems, + IArchiveUpdateCallback *updateCallback) +{ + if (!CanUpdate()) + return E_NOTIMPL; + CMyComPtr<IOutArchive> outArchive; + RINOK(GetArchive()->QueryInterface(IID_IOutArchive, (void **)&outArchive)); + + COutFileStream *outStreamSpec = new COutFileStream; + CMyComPtr<IOutStream> outStream(outStreamSpec); + + UString archiveName = newArchiveName; + { + UString resultPath; + int pos; + if (!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos)) + throw 141716; + NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos)); + } + + /* + bool isOK = false; + for (int i = 0; i < (1 << 16); i++) + { + resultName = newArchiveName; + if (i > 0) + { + wchar_t s[16]; + ConvertUInt32ToString(i, s); + resultName += s; + } + if (outStreamSpec->Open(realPath)) + { + isOK = true; + break; + } + if (::GetLastError() != ERROR_FILE_EXISTS) + return ::GetLastError(); + } + if (!isOK) + return ::GetLastError(); + */ + if (!outStreamSpec->Create(archiveName, true)) + { + // ShowLastErrorMessage(); + return E_FAIL; + } + + RINOK(outArchive->UpdateItems(outStream, numUpdateItems, updateCallback)); + return outStreamSpec->Close(); +} + + +STDMETHODIMP CAgent::DeleteItems( + const wchar_t *newArchiveName, + const UInt32 *indices, UInt32 numItems, + IFolderArchiveUpdateCallback *updateCallback100) +{ + if (!CanUpdate()) + return E_NOTIMPL; + CUpdateCallbackAgent updateCallbackAgent; + updateCallbackAgent.SetCallback(updateCallback100); + CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback; + CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec); + + CUIntVector realIndices; + _agentFolder->GetRealIndices(indices, numItems, realIndices); + CRecordVector<CUpdatePair2> updatePairs; + int curIndex = 0; + UInt32 numItemsInArchive; + RINOK(GetArchive()->GetNumberOfItems(&numItemsInArchive)); + for (UInt32 i = 0; i < numItemsInArchive; i++) + { + if (curIndex < realIndices.Size()) + if (realIndices[curIndex] == i) + { + curIndex++; + continue; + } + CUpdatePair2 up2; + up2.NewData = up2.NewProps = false; + up2.IsAnti = false; // check it. Maybe it can be undefined + up2.ArcIndex = i; + updatePairs.Add(up2); + } + updateCallbackSpec->UpdatePairs = &updatePairs; + updateCallbackSpec->Archive = GetArchive(); + updateCallbackSpec->Callback = &updateCallbackAgent; + return CommonUpdate(newArchiveName, updatePairs.Size(), updateCallback); +} + +HRESULT CAgent::CreateFolder( + const wchar_t *newArchiveName, + const wchar_t *folderName, + IFolderArchiveUpdateCallback *updateCallback100) +{ + if (!CanUpdate()) + return E_NOTIMPL; + CUpdateCallbackAgent updateCallbackAgent; + updateCallbackAgent.SetCallback(updateCallback100); + CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback; + CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec); + + CRecordVector<CUpdatePair2> updatePairs; + UInt32 numItemsInArchive; + RINOK(GetArchive()->GetNumberOfItems(&numItemsInArchive)); + for (UInt32 i = 0; i < numItemsInArchive; i++) + { + CUpdatePair2 up2; + up2.NewData = up2.NewProps = false; + up2.IsAnti = false; // check it. + up2.ArcIndex = i; + updatePairs.Add(up2); + } + CUpdatePair2 up2; + up2.NewData = up2.NewProps = true; + up2.IsAnti = false; + up2.DirIndex = 0; + + updatePairs.Add(up2); + + updatePairs.ReserveDown(); + + CDirItems dirItems; + CDirItem di; + + di.Attrib = FILE_ATTRIBUTE_DIRECTORY; + di.Size = 0; + di.Name = _agentFolder->_proxyFolderItem->GetFullPathPrefix() + folderName; + + FILETIME ft; + NTime::GetCurUtcFileTime(ft); + di.CTime = di.ATime = di.MTime = ft; + + dirItems.Items.Add(di); + + updateCallbackSpec->Callback = &updateCallbackAgent; + updateCallbackSpec->DirItems = &dirItems; + updateCallbackSpec->UpdatePairs = &updatePairs; + updateCallbackSpec->Archive = GetArchive(); + return CommonUpdate(newArchiveName, updatePairs.Size(), updateCallback); +} + + +HRESULT CAgent::RenameItem( + const wchar_t *newArchiveName, + const UInt32 *indices, UInt32 numItems, + const wchar_t *newItemName, + IFolderArchiveUpdateCallback *updateCallback100) +{ + if (!CanUpdate()) + return E_NOTIMPL; + if (numItems != 1) + return E_INVALIDARG; + CUpdateCallbackAgent updateCallbackAgent; + updateCallbackAgent.SetCallback(updateCallback100); + CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback; + CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec); + + CUIntVector realIndices; + _agentFolder->GetRealIndices(indices, numItems, realIndices); + + UString fullPrefix = _agentFolder->GetFullPathPrefixPlusPrefix(indices[0]); + UString oldItemPath = fullPrefix + _agentFolder->GetName(indices[0]); + UString newItemPath = fullPrefix + newItemName; + + CRecordVector<CUpdatePair2> updatePairs; + UStringVector newNames; + + int curIndex = 0; + UInt32 numItemsInArchive; + RINOK(GetArchive()->GetNumberOfItems(&numItemsInArchive)); + for (UInt32 i = 0; i < numItemsInArchive; i++) + { + if (curIndex < realIndices.Size()) + if (realIndices[curIndex] == i) + { + CUpdatePair2 up2; + up2.NewData = false; + up2.NewProps = true; + RINOK(GetArc().IsItemAnti(i, up2.IsAnti)); + up2.ArcIndex = i; + + UString oldFullPath; + RINOK(GetArc().GetItemPath(i, oldFullPath)); + + if (oldItemPath.CompareNoCase(oldFullPath.Left(oldItemPath.Length())) != 0) + return E_INVALIDARG; + + up2.NewNameIndex = newNames.Add(newItemPath + oldFullPath.Mid(oldItemPath.Length())); + updatePairs.Add(up2); + curIndex++; + continue; + } + CUpdatePair2 up2; + up2.NewData = up2.NewProps = false; + up2.IsAnti = false; + up2.ArcIndex = i; + updatePairs.Add(up2); + } + updateCallbackSpec->Callback = &updateCallbackAgent; + updateCallbackSpec->UpdatePairs = &updatePairs; + updateCallbackSpec->NewNames = &newNames; + updateCallbackSpec->Archive = GetArchive(); + return CommonUpdate(newArchiveName, updatePairs.Size(), updateCallback); +} + +STDMETHODIMP CAgent::SetProperties(const wchar_t **names, + const PROPVARIANT *values, Int32 numProperties) +{ + m_PropNames.Clear(); + m_PropValues.Clear(); + for (int i = 0; i < numProperties; i++) + { + m_PropNames.Add(names[i]); + m_PropValues.Add(values[i]); + } + return S_OK; +} diff --git a/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/AgentProxy.cpp b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/AgentProxy.cpp new file mode 100644 index 000000000..9686cf345 --- /dev/null +++ b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/AgentProxy.cpp @@ -0,0 +1,246 @@ +// AgentProxy.cpp + +#include "StdAfx.h" + +#include "../../../../C/Sort.h" + +#include "Windows/PropVariant.h" +#include "Windows/PropVariantConversions.h" + +#include "../Common/OpenArchive.h" + +#include "AgentProxy.h" + +using namespace NWindows; + +int CProxyFolder::FindDirSubItemIndex(const UString &name, int &insertPos) const +{ + int left = 0, right = Folders.Size(); + for (;;) + { + if (left == right) + { + insertPos = left; + return -1; + } + int mid = (left + right) / 2; + int compare = name.CompareNoCase(Folders[mid].Name); + if (compare == 0) + return mid; + if (compare < 0) + right = mid; + else + left = mid + 1; + } +} + +int CProxyFolder::FindDirSubItemIndex(const UString &name) const +{ + int insertPos; + return FindDirSubItemIndex(name, insertPos); +} + +void CProxyFolder::AddFileSubItem(UInt32 index, const UString &name) +{ + Files.Add(CProxyFile()); + Files.Back().Name = name; + Files.Back().Index = index; +} + +CProxyFolder* CProxyFolder::AddDirSubItem(UInt32 index, bool leaf, const UString &name) +{ + int insertPos; + int folderIndex = FindDirSubItemIndex(name, insertPos); + if (folderIndex >= 0) + { + CProxyFolder *item = &Folders[folderIndex]; + if (leaf) + { + item->Index = index; + item->IsLeaf = true; + } + return item; + } + Folders.Insert(insertPos, CProxyFolder()); + CProxyFolder *item = &Folders[insertPos]; + item->Name = name; + item->Index = index; + item->Parent = this; + item->IsLeaf = leaf; + return item; +} + +void CProxyFolder::Clear() +{ + Folders.Clear(); + Files.Clear(); +} + +void CProxyFolder::GetPathParts(UStringVector &pathParts) const +{ + pathParts.Clear(); + UString result; + const CProxyFolder *current = this; + while (current->Parent != NULL) + { + pathParts.Insert(0, (const wchar_t *)current->Name); + current = current->Parent; + } +} + +UString CProxyFolder::GetFullPathPrefix() const +{ + UString result; + const CProxyFolder *current = this; + while (current->Parent != NULL) + { + result = current->Name + UString(WCHAR_PATH_SEPARATOR) + result; + current = current->Parent; + } + return result; +} + +UString CProxyFolder::GetItemName(UInt32 index) const +{ + if (index < (UInt32)Folders.Size()) + return Folders[index].Name; + return Files[index - Folders.Size()].Name; +} + +void CProxyFolder::AddRealIndices(CUIntVector &realIndices) const +{ + if (IsLeaf) + realIndices.Add(Index); + int i; + for (i = 0; i < Folders.Size(); i++) + Folders[i].AddRealIndices(realIndices); + for (i = 0; i < Files.Size(); i++) + realIndices.Add(Files[i].Index); +} + +void CProxyFolder::GetRealIndices(const UInt32 *indices, UInt32 numItems, CUIntVector &realIndices) const +{ + realIndices.Clear(); + for (UInt32 i = 0; i < numItems; i++) + { + int index = indices[i]; + int numDirItems = Folders.Size(); + if (index < numDirItems) + Folders[index].AddRealIndices(realIndices); + else + realIndices.Add(Files[index - numDirItems].Index); + } + HeapSort(&realIndices.Front(), realIndices.Size()); +} + +/////////////////////////////////////////////// +// CProxyArchive + +static UInt64 GetSize(IInArchive *archive, UInt32 index, PROPID propID) +{ + NCOM::CPropVariant prop; + if (archive->GetProperty(index, propID, &prop) == S_OK) + if (prop.vt != VT_EMPTY) + return ConvertPropVariantToUInt64(prop); + return 0; +} + +void CProxyFolder::CalculateSizes(IInArchive *archive) +{ + Size = PackSize = 0; + NumSubFolders = Folders.Size(); + NumSubFiles = Files.Size(); + CrcIsDefined = true; + Crc = 0; + int i; + for (i = 0; i < Files.Size(); i++) + { + UInt32 index = Files[i].Index; + Size += GetSize(archive, index, kpidSize); + PackSize += GetSize(archive, index, kpidPackSize); + { + NCOM::CPropVariant prop; + if (archive->GetProperty(index, kpidCRC, &prop) == S_OK && prop.vt == VT_UI4) + Crc += prop.ulVal; + else + CrcIsDefined = false; + } + } + for (i = 0; i < Folders.Size(); i++) + { + CProxyFolder &f = Folders[i]; + f.CalculateSizes(archive); + Size += f.Size; + PackSize += f.PackSize; + NumSubFiles += f.NumSubFiles; + NumSubFolders += f.NumSubFolders; + Crc += f.Crc; + if (!f.CrcIsDefined) + CrcIsDefined = false; + } +} + +HRESULT CProxyArchive::Load(const CArc &arc, IProgress *progress) +{ + RootFolder.Clear(); + IInArchive *archive = arc.Archive; + { + ThereIsPathProp = false; + UInt32 numProps; + archive->GetNumberOfProperties(&numProps); + for (UInt32 i = 0; i < numProps; i++) + { + CMyComBSTR name; + PROPID propID; + VARTYPE varType; + RINOK(archive->GetPropertyInfo(i, &name, &propID, &varType)); + if (propID == kpidPath) + { + ThereIsPathProp = true; + break; + } + } + } + + UInt32 numItems; + RINOK(archive->GetNumberOfItems(&numItems)); + if (progress != NULL) + { + UInt64 totalItems = numItems; + RINOK(progress->SetTotal(totalItems)); + } + UString fileName; + for (UInt32 i = 0; i < numItems; i++) + { + if (progress != NULL && (i & 0xFFFFF) == 0) + { + UInt64 currentItemIndex = i; + RINOK(progress->SetCompleted(¤tItemIndex)); + } + UString filePath; + RINOK(arc.GetItemPath(i, filePath)); + CProxyFolder *curItem = &RootFolder; + int len = filePath.Length(); + fileName.Empty(); + for (int j = 0; j < len; j++) + { + wchar_t c = filePath[j]; + if (c == WCHAR_PATH_SEPARATOR || c == L'/') + { + curItem = curItem->AddDirSubItem((UInt32)(Int32)-1, false, fileName); + fileName.Empty(); + } + else + fileName += c; + } + + bool isFolder; + RINOK(IsArchiveItemFolder(archive, i, isFolder)); + if (isFolder) + curItem->AddDirSubItem(i, true, fileName); + else + curItem->AddFileSubItem(i, fileName); + } + RootFolder.CalculateSizes(archive); + return S_OK; +} diff --git a/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/AgentProxy.h b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/AgentProxy.h new file mode 100644 index 000000000..d4caca164 --- /dev/null +++ b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/AgentProxy.h @@ -0,0 +1,53 @@ +// AgentProxy.h + +#ifndef __AGENT_PROXY_H +#define __AGENT_PROXY_H + +#include "Common/MyString.h" + +#include "../Common/OpenArchive.h" + +struct CProxyFile +{ + UInt32 Index; + UString Name; +}; + +struct CProxyFolder: public CProxyFile +{ + CProxyFolder *Parent; + CObjectVector<CProxyFolder> Folders; + CObjectVector<CProxyFile> Files; + bool IsLeaf; + + bool CrcIsDefined; + UInt64 Size; + UInt64 PackSize; + UInt32 Crc; + UInt32 NumSubFolders; + UInt32 NumSubFiles; + + CProxyFolder(): Parent(NULL) {}; + int FindDirSubItemIndex(const UString &name, int &insertPos) const; + int FindDirSubItemIndex(const UString &name) const; + CProxyFolder* AddDirSubItem(UInt32 index, bool leaf, const UString &name); + void AddFileSubItem(UInt32 index, const UString &name); + void Clear(); + + void GetPathParts(UStringVector &pathParts) const; + UString GetFullPathPrefix() const; + UString GetItemName(UInt32 index) const; + void AddRealIndices(CUIntVector &realIndices) const; + void GetRealIndices(const UInt32 *indices, UInt32 numItems, CUIntVector &realIndices) const; + void CalculateSizes(IInArchive *archive); +}; + +struct CProxyArchive +{ + CProxyFolder RootFolder; + bool ThereIsPathProp; + + HRESULT Load(const CArc &arc, IProgress *progress); +}; + +#endif diff --git a/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/ArchiveFolder.cpp b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/ArchiveFolder.cpp new file mode 100644 index 000000000..57975e7d4 --- /dev/null +++ b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/ArchiveFolder.cpp @@ -0,0 +1,59 @@ +// Agent/ArchiveFolder.cpp + +#include "StdAfx.h" + +#include "Common/ComTry.h" + +#include "../Common/ArchiveExtractCallback.h" + +#include "Agent.h" + +using namespace NWindows; +using namespace NCOM; + +STDMETHODIMP CAgentFolder::CopyTo(const UInt32 *indices, UInt32 numItems, + const wchar_t *path, IFolderOperationsExtractCallback *callback) +{ + COM_TRY_BEGIN + CArchiveExtractCallback *extractCallbackSpec = new + CArchiveExtractCallback; + CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec; + UStringVector pathParts; + CProxyFolder *currentProxyFolder = _proxyFolderItem; + while (currentProxyFolder->Parent) + { + pathParts.Insert(0, currentProxyFolder->Name); + currentProxyFolder = currentProxyFolder->Parent; + } + + CMyComPtr<IFolderArchiveExtractCallback> extractCallback2; + { + CMyComPtr<IFolderOperationsExtractCallback> callbackWrap = callback; + RINOK(callbackWrap.QueryInterface( + IID_IFolderArchiveExtractCallback, &extractCallback2)); + } + + NExtract::NPathMode::EEnum pathMode = _flatMode ? + NExtract::NPathMode::kNoPathnames : + NExtract::NPathMode::kCurrentPathnames; + + extractCallbackSpec->InitForMulti(false, pathMode, NExtract::NOverwriteMode::kAskBefore); + extractCallbackSpec->Init(NULL, &_agentSpec->GetArc(), + extractCallback2, + false, false, false, + path, + pathParts, + (UInt64)(Int64)-1); + CUIntVector realIndices; + GetRealIndices(indices, numItems, realIndices); + return _agentSpec->GetArchive()->Extract(&realIndices.Front(), + realIndices.Size(), BoolToInt(false), extractCallback); + COM_TRY_END +} + +STDMETHODIMP CAgentFolder::MoveTo(const UInt32 * /* indices */, UInt32 /* numItems */, + const wchar_t * /* path */, IFolderOperationsExtractCallback * /* callback */) +{ + return E_NOTIMPL; +} + diff --git a/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/ArchiveFolderOpen.cpp b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/ArchiveFolderOpen.cpp new file mode 100644 index 000000000..98c75f4d9 --- /dev/null +++ b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/ArchiveFolderOpen.cpp @@ -0,0 +1,121 @@ +// Zip/ArchiveFolder.cpp + +#include "StdAfx.h" + +#include "Agent.h" + +#include "Common/StringConvert.h" + +static inline UINT GetCurrentFileCodePage() + { return AreFileApisANSI() ? CP_ACP : CP_OEMCP; } + +void CArchiveFolderManager::LoadFormats() +{ + if (!_codecs) + { + _compressCodecsInfo = _codecs = new CCodecs; + _codecs->Load(); + } +} + +int CArchiveFolderManager::FindFormat(const UString &type) +{ + for (int i = 0; i < _codecs->Formats.Size(); i++) + if (type.CompareNoCase(_codecs->Formats[i].Name) == 0) + return i; + return -1; +} + +STDMETHODIMP CArchiveFolderManager::OpenFolderFile(IInStream *inStream, const wchar_t *filePath, + IFolderFolder **resultFolder, IProgress *progress) +{ + CMyComPtr<IArchiveOpenCallback> openArchiveCallback; + if (progress != 0) + { + CMyComPtr<IProgress> progressWrapper = progress; + progressWrapper.QueryInterface(IID_IArchiveOpenCallback, &openArchiveCallback); + } + CAgent *agent = new CAgent(); + CMyComPtr<IInFolderArchive> archive = agent; + RINOK(agent->Open(inStream, filePath, NULL, openArchiveCallback)); + return agent->BindToRootFolder(resultFolder); +} + +/* +HRESULT CAgent::FolderReOpen( + IArchiveOpenCallback *openArchiveCallback) +{ + return ReOpenArchive(_archive, _archiveFilePath); +} +*/ + + +/* +STDMETHODIMP CArchiveFolderManager::GetExtensions(const wchar_t *type, BSTR *extensions) +{ + *extensions = 0; + int formatIndex = FindFormat(type); + if (formatIndex < 0) + return E_INVALIDARG; + // Exts[0].Ext; + return StringToBstr(_codecs.Formats[formatIndex].GetAllExtensions(), extensions); +} +*/ +STDMETHODIMP CArchiveFolderManager::GetExtensions(BSTR *extensions) +{ + LoadFormats(); + *extensions = 0; + UString res; + for (int i = 0; i < _codecs->Libs.Size(); i++) + { + const CCodecLib &lib = _codecs->Libs[i]; + for (int j = 0; j < lib.IconPairs.Size(); j++) + { + if (!res.IsEmpty()) + res += L' '; + res += lib.IconPairs[j].Ext; + } + } + return StringToBstr(res, extensions); +} + +STDMETHODIMP CArchiveFolderManager::GetIconPath(const wchar_t *ext, BSTR *iconPath, Int32 *iconIndex) +{ + LoadFormats(); + *iconPath = 0; + *iconIndex = 0; + for (int i = 0; i < _codecs->Libs.Size(); i++) + { + const CCodecLib &lib = _codecs->Libs[i]; + int ii = lib.FindIconIndex(ext); + if (ii >= 0) + { + *iconIndex = ii; + return StringToBstr(GetUnicodeString(lib.Path, GetCurrentFileCodePage()), iconPath); + } + } + return S_OK; +} + +/* +STDMETHODIMP CArchiveFolderManager::GetTypes(BSTR *types) +{ + LoadFormats(); + UString typesStrings; + for(int i = 0; i < _codecs.Formats.Size(); i++) + { + const CArcInfoEx &ai = _codecs.Formats[i]; + if (ai.AssociateExts.Size() == 0) + continue; + if (i != 0) + typesStrings += L' '; + typesStrings += ai.Name; + } + return StringToBstr(typesStrings, types); +} +STDMETHODIMP CArchiveFolderManager::CreateFolderFile(const wchar_t * type, + const wchar_t * filePath, IProgress progress) +{ + return E_NOTIMPL; +} +*/ diff --git a/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/ArchiveFolderOut.cpp b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/ArchiveFolderOut.cpp new file mode 100644 index 000000000..8f03f44de --- /dev/null +++ b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/ArchiveFolderOut.cpp @@ -0,0 +1,214 @@ +// FolderOut.cpp + +#include "StdAfx.h" + +#include "Common/ComTry.h" + +#include "Windows/FileDir.h" + +#include "../Common/WorkDir.h" + +#include "Agent.h" + +using namespace NWindows; +using namespace NFile; +using namespace NDirectory; + +static LPCWSTR kTempArcivePrefix = L"7zA"; + +void CAgentFolder::GetPathParts(UStringVector &pathParts) +{ + _proxyFolderItem->GetPathParts(pathParts); +} + +HRESULT CAgentFolder::CommonUpdateOperation( + bool deleteOperation, + bool createFolderOperation, + bool renameOperation, + const wchar_t *newItemName, + const NUpdateArchive::CActionSet *actionSet, + const UINT32 *indices, UINT32 numItems, + IFolderArchiveUpdateCallback *updateCallback100) +{ + NWorkDir::CInfo workDirInfo; + ReadWorkDirInfo(workDirInfo); + UString archiveFilePath = _agentSpec->_archiveFilePath; + UString workDir = GetWorkDir(workDirInfo, archiveFilePath); + CreateComplexDirectory(workDir); + + CTempFileW tempFile; + UString tempFileName; + if (tempFile.Create(workDir, kTempArcivePrefix, tempFileName) == 0) + return E_FAIL; + + /* + if (SetOutProperties(anOutArchive, aCompressionInfo.Method) != S_OK) + return NFileOperationReturnCode::kError; + */ + + //////////////////////////// + // Save FolderItem; + + UStringVector pathParts; + GetPathParts(pathParts); + + HRESULT result; + if (deleteOperation) + result = _agentSpec->DeleteItems(tempFileName, + indices, numItems, updateCallback100); + else if (createFolderOperation) + { + result = _agentSpec->CreateFolder(tempFileName, + newItemName, updateCallback100); + } + else if (renameOperation) + { + result = _agentSpec->RenameItem( + tempFileName, + indices, numItems, + newItemName, + updateCallback100); + } + else + { + Byte actionSetByte[NUpdateArchive::NPairState::kNumValues]; + for (int i = 0; i < NUpdateArchive::NPairState::kNumValues; i++) + actionSetByte[i] = (Byte)actionSet->StateActions[i]; + result = _agentSpec->DoOperation2(tempFileName, actionSetByte, NULL, updateCallback100); + } + + if (result != S_OK) + return result; + + _agentSpec->Close(); + + // m_FolderItem = NULL; + + if (NFind::DoesFileExist(archiveFilePath)) + if (!DeleteFileAlways(archiveFilePath)) + return GetLastError(); + + tempFile.DisableDeleting(); + if (!MyMoveFile(tempFileName, archiveFilePath)) + return GetLastError(); + + { + CMyComPtr<IArchiveOpenCallback> openCallback; + if (updateCallback100) + { + RINOK(updateCallback100->QueryInterface(IID_IArchiveOpenCallback, (void **)&openCallback)); + } + RINOK(_agentSpec->ReOpen(openCallback)); + } + + //////////////////////////// + // Restore FolderItem; + + CMyComPtr<IFolderFolder> archiveFolder; + RINOK(_agentSpec->BindToRootFolder(&archiveFolder)); + for (int i = 0; i < pathParts.Size(); i++) + { + CMyComPtr<IFolderFolder> newFolder; + archiveFolder->BindToFolder(pathParts[i], &newFolder); + if(!newFolder) + break; + archiveFolder = newFolder; + } + + CMyComPtr<IArchiveFolderInternal> archiveFolderInternal; + RINOK(archiveFolder.QueryInterface(IID_IArchiveFolderInternal, &archiveFolderInternal)); + CAgentFolder *agentFolder; + RINOK(archiveFolderInternal->GetAgentFolder(&agentFolder)); + _proxyFolderItem = agentFolder->_proxyFolderItem; + _proxyArchive = agentFolder->_proxyArchive; + _parentFolder = agentFolder->_parentFolder; + + return S_OK; +} + +STDMETHODIMP CAgentFolder::CopyFrom( + const wchar_t *fromFolderPath, // test it + const wchar_t **itemsPaths, + UINT32 numItems, + IProgress *progress) +{ + COM_TRY_BEGIN + CMyComPtr<IFolderArchiveUpdateCallback> updateCallback100; + if (progress != 0) + { + RINOK(progress->QueryInterface(IID_IFolderArchiveUpdateCallback, (void **)&updateCallback100)); + } + try + { + RINOK(_agentSpec->SetFiles(fromFolderPath, itemsPaths, numItems)); + RINOK(_agentSpec->SetFolder(this)); + return CommonUpdateOperation(false, false, false, NULL, + &NUpdateArchive::kAddActionSet, 0, 0, updateCallback100); + } + catch(const UString &s) + { + RINOK(updateCallback100->UpdateErrorMessage(UString(L"Error: ") + s)); + return E_FAIL; + } + COM_TRY_END +} + +STDMETHODIMP CAgentFolder::Delete(const UINT32 *indices, UINT32 numItems, IProgress *progress) +{ + COM_TRY_BEGIN + RINOK(_agentSpec->SetFolder(this)); + CMyComPtr<IFolderArchiveUpdateCallback> updateCallback100; + if (progress != 0) + { + CMyComPtr<IProgress> progressWrapper = progress; + RINOK(progressWrapper.QueryInterface( + IID_IFolderArchiveUpdateCallback, &updateCallback100)); + } + return CommonUpdateOperation(true, false, false, NULL, + &NUpdateArchive::kDeleteActionSet, indices, numItems, updateCallback100); + COM_TRY_END +} + +STDMETHODIMP CAgentFolder::CreateFolder(const wchar_t *name, IProgress *progress) +{ + COM_TRY_BEGIN + if (_proxyFolderItem->FindDirSubItemIndex(name) >= 0) + return ERROR_ALREADY_EXISTS; + RINOK(_agentSpec->SetFolder(this)); + CMyComPtr<IFolderArchiveUpdateCallback> updateCallback100; + if (progress != 0) + { + CMyComPtr<IProgress> progressWrapper = progress; + RINOK(progressWrapper.QueryInterface(IID_IFolderArchiveUpdateCallback, &updateCallback100)); + } + return CommonUpdateOperation(false, true, false, name, NULL, NULL, 0, updateCallback100); + COM_TRY_END +} + +STDMETHODIMP CAgentFolder::Rename(UINT32 index, const wchar_t *newName, IProgress *progress) +{ + COM_TRY_BEGIN + CUIntVector indices; + indices.Add(index); + RINOK(_agentSpec->SetFolder(this)); + CMyComPtr<IFolderArchiveUpdateCallback> updateCallback100; + if (progress != 0) + { + CMyComPtr<IProgress> progressWrapper = progress; + RINOK(progressWrapper.QueryInterface(IID_IFolderArchiveUpdateCallback, &updateCallback100)); + } + return CommonUpdateOperation(false, false, true, newName, NULL, &indices.Front(), + indices.Size(), updateCallback100); + COM_TRY_END +} + +STDMETHODIMP CAgentFolder::CreateFile(const wchar_t * /* name */, IProgress * /* progress */) +{ + return E_NOTIMPL; +} + +STDMETHODIMP CAgentFolder::SetProperty(UINT32 /* index */, PROPID /* propID */, + const PROPVARIANT * /* value */, IProgress * /* progress */) +{ + return E_NOTIMPL; +} diff --git a/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/IFolderArchive.h b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/IFolderArchive.h new file mode 100644 index 000000000..91da1150b --- /dev/null +++ b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/IFolderArchive.h @@ -0,0 +1,73 @@ +// IFolderArchive.h + +#ifndef __IFOLDER_ARCHIVE_H +#define __IFOLDER_ARCHIVE_H + +#include "../../IDecl.h" +#include "../../Archive/IArchive.h" +#include "../../UI/Common/LoadCodecs.h" +#include "../../UI/FileManager/IFolder.h" + +#include "../Common/ExtractMode.h" +#include "../Common/IFileExtractCallback.h" + +#define FOLDER_ARCHIVE_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 0x01, x) +#define FOLDER_ARCHIVE_INTERFACE(i, x) FOLDER_ARCHIVE_INTERFACE_SUB(i, IUnknown, x) + +#define INTERFACE_IArchiveFolder(x) \ + STDMETHOD(Extract)(const UInt32 *indices, UInt32 numItems, \ + NExtract::NPathMode::EEnum pathMode, \ + NExtract::NOverwriteMode::EEnum overwriteMode, \ + const wchar_t *path, Int32 testMode, \ + IFolderArchiveExtractCallback *extractCallback2) x; \ + +FOLDER_ARCHIVE_INTERFACE(IArchiveFolder, 0x05) +{ + INTERFACE_IArchiveFolder(PURE) +}; + +#define INTERFACE_IInFolderArchive(x) \ + STDMETHOD(Open)(IInStream *inStream, const wchar_t *filePath, BSTR *archiveType, IArchiveOpenCallback *openArchiveCallback) x; \ + STDMETHOD(ReOpen)(IArchiveOpenCallback *openArchiveCallback) x; \ + STDMETHOD(Close)() x; \ + STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties) x; \ + STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x; \ + STDMETHOD(BindToRootFolder)(IFolderFolder **resultFolder) x; \ + STDMETHOD(Extract)(NExtract::NPathMode::EEnum pathMode, \ + NExtract::NOverwriteMode::EEnum overwriteMode, const wchar_t *path, \ + Int32 testMode, IFolderArchiveExtractCallback *extractCallback2) x; \ + +FOLDER_ARCHIVE_INTERFACE(IInFolderArchive, 0x0D) +{ + INTERFACE_IInFolderArchive(PURE) +}; + +#define INTERFACE_IFolderArchiveUpdateCallback(x) \ + STDMETHOD(CompressOperation)(const wchar_t *name) x; \ + STDMETHOD(DeleteOperation)(const wchar_t *name) x; \ + STDMETHOD(OperationResult)(Int32 operationResult) x; \ + STDMETHOD(UpdateErrorMessage)(const wchar_t *message) x; \ + STDMETHOD(SetNumFiles)(UInt64 numFiles) x; \ + +FOLDER_ARCHIVE_INTERFACE_SUB(IFolderArchiveUpdateCallback, IProgress, 0x0B) +{ + INTERFACE_IFolderArchiveUpdateCallback(PURE) +}; + +#define INTERFACE_IOutFolderArchive(x) \ + STDMETHOD(SetFolder)(IFolderFolder *folder) x; \ + STDMETHOD(SetFiles)(const wchar_t *folderPrefix, const wchar_t **names, UInt32 numNames) x; \ + STDMETHOD(DeleteItems)(const wchar_t *newArchiveName, \ + const UInt32 *indices, UInt32 numItems, IFolderArchiveUpdateCallback *updateCallback) x; \ + STDMETHOD(DoOperation)(CCodecs *codecs, int index, \ + const wchar_t *newArchiveName, const Byte *stateActions, const wchar_t *sfxModule, \ + IFolderArchiveUpdateCallback *updateCallback) x; \ + STDMETHOD(DoOperation2)(const wchar_t *newArchiveName, const Byte *stateActions, \ + const wchar_t *sfxModule, IFolderArchiveUpdateCallback *updateCallback) x; \ + +FOLDER_ARCHIVE_INTERFACE(IOutFolderArchive, 0x0A) +{ + INTERFACE_IOutFolderArchive(PURE) +}; + +#endif diff --git a/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/UpdateCallbackAgent.cpp b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/UpdateCallbackAgent.cpp new file mode 100644 index 000000000..21549c90f --- /dev/null +++ b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/UpdateCallbackAgent.cpp @@ -0,0 +1,121 @@ +// UpdateCallbackAgent.h + +#include "StdAfx.h" + +#include "Windows/Error.h" +#include "Common/IntToString.h" + +#include "UpdateCallbackAgent.h" + +using namespace NWindows; + +void CUpdateCallbackAgent::SetCallback(IFolderArchiveUpdateCallback *callback) +{ + Callback = callback; + _compressProgress.Release(); + if (Callback) + Callback.QueryInterface(IID_ICompressProgressInfo, &_compressProgress); +} + +HRESULT CUpdateCallbackAgent::SetNumFiles(UInt64 numFiles) +{ + if (Callback) + return Callback->SetNumFiles(numFiles); + return S_OK; +} + + +HRESULT CUpdateCallbackAgent::SetTotal(UINT64 size) +{ + if (Callback) + return Callback->SetTotal(size); + return S_OK; +} + +HRESULT CUpdateCallbackAgent::SetCompleted(const UINT64 *completeValue) +{ + if (Callback) + return Callback->SetCompleted(completeValue); + return S_OK; +} + +HRESULT CUpdateCallbackAgent::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize) +{ + if (_compressProgress) + return _compressProgress->SetRatioInfo(inSize, outSize); + return S_OK; +} + +HRESULT CUpdateCallbackAgent::CheckBreak() +{ + return S_OK; +} + +HRESULT CUpdateCallbackAgent::Finilize() +{ + return S_OK; +} + +HRESULT CUpdateCallbackAgent::OpenFileError(const wchar_t *name, DWORD systemError) +{ + // if (systemError == ERROR_SHARING_VIOLATION) + { + if (Callback) + { + RINOK(Callback->UpdateErrorMessage( + UString(L"WARNING: ") + + NError::MyFormatMessageW(systemError) + + UString(L": ") + + UString(name))); + return S_FALSE; + } + } + // FailedFiles.Add(name); + return systemError; +} + +HRESULT CUpdateCallbackAgent::GetStream(const wchar_t *name, bool /* isAnti */) +{ + if (Callback) + return Callback->CompressOperation(name); + return S_OK; +} + +HRESULT CUpdateCallbackAgent::SetOperationResult(Int32 operationResult) +{ + if (Callback) + return Callback->OperationResult(operationResult); + return S_OK; +} + +HRESULT CUpdateCallbackAgent::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password) +{ + *password = NULL; + *passwordIsDefined = BoolToInt(false); + if (!_cryptoGetTextPassword) + { + if (!Callback) + return S_OK; + Callback.QueryInterface(IID_ICryptoGetTextPassword2, &_cryptoGetTextPassword); + if (!_cryptoGetTextPassword) + return S_OK; + } + return _cryptoGetTextPassword->CryptoGetTextPassword2(passwordIsDefined, password); +} + +HRESULT CUpdateCallbackAgent::CryptoGetTextPassword(BSTR *password) +{ + *password = NULL; + CMyComPtr<ICryptoGetTextPassword> getTextPassword; + Callback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword); + if (!getTextPassword) + return E_NOTIMPL; + return getTextPassword->CryptoGetTextPassword(password); +} + +/* +HRESULT CUpdateCallbackAgent::ShowDeleteFile(const wchar_t *name) +{ + return Callback->DeleteOperation(name); +} +*/
\ No newline at end of file diff --git a/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/UpdateCallbackAgent.h b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/UpdateCallbackAgent.h new file mode 100644 index 000000000..1d5ed17a0 --- /dev/null +++ b/installerbuilder/libinstaller/3rdparty/p7zip_9.04/unix/CPP/7zip/UI/Agent/UpdateCallbackAgent.h @@ -0,0 +1,19 @@ +// UpdateCallbackAgent.h + +#ifndef __UPDATECALLBACKAGENT_H +#define __UPDATECALLBACKAGENT_H + +#include "../Common/UpdateCallback.h" +#include "IFolderArchive.h" + +class CUpdateCallbackAgent: public IUpdateCallbackUI +{ + INTERFACE_IUpdateCallbackUI(;) + CMyComPtr<ICryptoGetTextPassword2> _cryptoGetTextPassword; + CMyComPtr<IFolderArchiveUpdateCallback> Callback; + CMyComPtr<ICompressProgressInfo> _compressProgress; +public: + void SetCallback(IFolderArchiveUpdateCallback *callback); +}; + +#endif |