mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-09 04:07:08 -06:00
4.37 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
8304895f29
commit
cb9eea7264
@@ -25,15 +25,40 @@ STDMETHODIMP CAgentFolder::GetAgentFolder(CAgentFolder **agentFolder)
|
||||
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()
|
||||
{
|
||||
_items.Clear();
|
||||
if (_flatMode)
|
||||
LoadFolder(_proxyFolderItem);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CAgentFolder::GetNumberOfItems(UINT32 *numItems)
|
||||
{
|
||||
*numItems = _proxyFolderItem->Folders.Size() +
|
||||
_proxyFolderItem->Files.Size();
|
||||
if (_flatMode)
|
||||
*numItems = _items.Size();
|
||||
else
|
||||
*numItems = _proxyFolderItem->Folders.Size() +_proxyFolderItem->Files.Size();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -45,12 +70,75 @@ STDMETHODIMP CAgentFolder::GetNumberOfSubFolders(UINT32 *aNumSubFolders)
|
||||
}
|
||||
*/
|
||||
|
||||
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(L"\\") + path;
|
||||
folder = folder->Parent;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
UString CAgentFolder::GetFullPathPrefixPlusPrefix(UInt32 index) const
|
||||
{
|
||||
return _proxyFolderItem->GetFullPathPrefix() + GetPrefix(index);
|
||||
}
|
||||
|
||||
void CAgentFolder::GetPrefixIfAny(UInt32 index, NCOM::CPropVariant &propVariant) const
|
||||
{
|
||||
if (!_flatMode)
|
||||
return;
|
||||
propVariant = GetPrefix(index);
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CAgentFolder::GetProperty(UINT32 itemIndex, PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
NCOM::CPropVariant propVariant;
|
||||
if (itemIndex < (UINT32)_proxyFolderItem->Folders.Size())
|
||||
const CProxyFolder *folder;
|
||||
UInt32 realIndex;
|
||||
if (_flatMode)
|
||||
{
|
||||
const CProxyFolder &item = _proxyFolderItem->Folders[itemIndex];
|
||||
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];
|
||||
switch(propID)
|
||||
{
|
||||
case kpidIsFolder:
|
||||
@@ -59,6 +147,9 @@ STDMETHODIMP CAgentFolder::GetProperty(UINT32 itemIndex, PROPID propID, PROPVARI
|
||||
case kpidName:
|
||||
propVariant = item.Name;
|
||||
break;
|
||||
case kpidPrefix:
|
||||
GetPrefixIfAny(itemIndex, propVariant);
|
||||
break;
|
||||
default:
|
||||
if (item.IsLeaf)
|
||||
return _agentSpec->GetArchive()->GetProperty(item.Index, propID, value);
|
||||
@@ -66,8 +157,8 @@ STDMETHODIMP CAgentFolder::GetProperty(UINT32 itemIndex, PROPID propID, PROPVARI
|
||||
}
|
||||
else
|
||||
{
|
||||
itemIndex -= _proxyFolderItem->Folders.Size();
|
||||
const CProxyFile &item = _proxyFolderItem->Files[itemIndex];
|
||||
realIndex -= folder->Folders.Size();
|
||||
const CProxyFile &item = folder->Files[realIndex];
|
||||
switch(propID)
|
||||
{
|
||||
case kpidIsFolder:
|
||||
@@ -76,26 +167,53 @@ STDMETHODIMP CAgentFolder::GetProperty(UINT32 itemIndex, PROPID propID, PROPVARI
|
||||
case kpidName:
|
||||
propVariant = item.Name;
|
||||
break;
|
||||
case kpidPrefix:
|
||||
GetPrefixIfAny(itemIndex, propVariant);
|
||||
break;
|
||||
default:
|
||||
return _agentSpec->GetArchive()->GetProperty(item.Index,
|
||||
propID, value);
|
||||
return _agentSpec->GetArchive()->GetProperty(item.Index, propID, value);
|
||||
}
|
||||
}
|
||||
propVariant.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
|
||||
if (index >= (UINT32)_proxyFolderItem->Folders.Size())
|
||||
|
||||
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;
|
||||
CAgentFolder *folderSpec = new CAgentFolder;
|
||||
CMyComPtr<IFolderFolder> agentFolder = folderSpec;
|
||||
folderSpec->Init(_proxyArchive, &_proxyFolderItem->Folders[index],
|
||||
this, _agentSpec);
|
||||
*resultFolder = agentFolder.Detach();
|
||||
return S_OK;
|
||||
return BindToFolder(&folder->Folders[realIndex], resultFolder);
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
@@ -138,7 +256,10 @@ struct CArchiveItemPropertyTemp
|
||||
STDMETHODIMP CAgentFolder::GetNumberOfProperties(UINT32 *numProperties)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
return _agentSpec->GetArchive()->GetNumberOfProperties(numProperties);
|
||||
RINOK(_agentSpec->GetArchive()->GetNumberOfProperties(numProperties));
|
||||
if (_flatMode)
|
||||
(*numProperties)++;
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
@@ -146,9 +267,20 @@ STDMETHODIMP CAgentFolder::GetPropertyInfo(UINT32 index,
|
||||
BSTR *name, PROPID *propID, VARTYPE *varType)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
RINOK(_agentSpec->GetArchive()->GetPropertyInfo(index, name, propID, varType));
|
||||
if (*propID == kpidPath)
|
||||
*propID = kpidName;
|
||||
UINT32 numProperties;
|
||||
_agentSpec->GetArchive()->GetNumberOfProperties(&numProperties);
|
||||
if (index < numProperties)
|
||||
{
|
||||
RINOK(_agentSpec->GetArchive()->GetPropertyInfo(index, name, propID, varType));
|
||||
if (*propID == kpidPath)
|
||||
*propID = kpidName;
|
||||
}
|
||||
else
|
||||
{
|
||||
*name = NULL;
|
||||
*propID = kpidPrefix;
|
||||
*varType = VT_BSTR;
|
||||
}
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
@@ -195,6 +327,25 @@ STDMETHODIMP CAgentFolder::GetPath(BSTR *path)
|
||||
}
|
||||
#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);
|
||||
}
|
||||
realIndices.Sort();
|
||||
}
|
||||
|
||||
STDMETHODIMP CAgentFolder::Extract(const UINT32 *indices,
|
||||
UINT32 numItems,
|
||||
@@ -214,6 +365,12 @@ STDMETHODIMP CAgentFolder::Extract(const UINT32 *indices,
|
||||
pathParts.Insert(0, currentProxyFolder->Name);
|
||||
currentProxyFolder = currentProxyFolder->Parent;
|
||||
}
|
||||
|
||||
/*
|
||||
if (_flatMode)
|
||||
pathMode = NExtract::NPathMode::kNoPathnames;
|
||||
*/
|
||||
|
||||
extractCallbackSpec->Init(_agentSpec->GetArchive(),
|
||||
extractCallback2,
|
||||
false,
|
||||
@@ -227,12 +384,18 @@ STDMETHODIMP CAgentFolder::Extract(const UINT32 *indices,
|
||||
// ,_agentSpec->_srcDirectoryPrefix
|
||||
);
|
||||
CUIntVector realIndices;
|
||||
_proxyFolderItem->GetRealIndices(indices, numItems, realIndices);
|
||||
GetRealIndices(indices, numItems, realIndices);
|
||||
return _agentSpec->GetArchive()->Extract(&realIndices.Front(),
|
||||
realIndices.Size(), testMode, extractCallback);
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDMETHODIMP CAgentFolder::SetFlatMode(Int32 flatMode)
|
||||
{
|
||||
_flatMode = IntToBool(flatMode);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////
|
||||
// CAgent
|
||||
|
||||
@@ -32,6 +32,12 @@ public:
|
||||
STDMETHOD(GetAgentFolder)(CAgentFolder **agentFolder) PURE;
|
||||
};
|
||||
|
||||
struct CProxyItem
|
||||
{
|
||||
CProxyFolder *Folder;
|
||||
UInt32 Index;
|
||||
};
|
||||
|
||||
class CAgent;
|
||||
|
||||
class CAgentFolder:
|
||||
@@ -43,6 +49,7 @@ class CAgentFolder:
|
||||
public IFolderGetTypeID,
|
||||
public IFolderGetPath,
|
||||
public IFolderOperations,
|
||||
public IFolderSetFlatMode,
|
||||
#endif
|
||||
public CMyUnknownImp
|
||||
{
|
||||
@@ -57,12 +64,17 @@ public:
|
||||
MY_QUERYINTERFACE_ENTRY(IFolderGetTypeID)
|
||||
MY_QUERYINTERFACE_ENTRY(IFolderGetPath)
|
||||
MY_QUERYINTERFACE_ENTRY(IFolderOperations)
|
||||
MY_QUERYINTERFACE_ENTRY(IFolderSetFlatMode)
|
||||
#endif
|
||||
MY_QUERYINTERFACE_END
|
||||
MY_ADDREF_RELEASE
|
||||
|
||||
// IFolderFolder
|
||||
|
||||
|
||||
void LoadFolder(CProxyFolder *folder);
|
||||
HRESULT BindToFolder(CProxyFolder *folder, IFolderFolder **resultFolder);
|
||||
void GetRealIndices(const UINT32 *indices, UINT32 numItems, CUIntVector &realIndices) const;
|
||||
|
||||
STDMETHOD(LoadItems)();
|
||||
STDMETHOD(GetNumberOfItems)(UINT32 *numItems);
|
||||
STDMETHOD(GetProperty)(UINT32 itemIndex, PROPID propID, PROPVARIANT *value);
|
||||
@@ -102,10 +114,10 @@ public:
|
||||
const wchar_t **itemsPaths, UINT32 numItems, IProgress *progress);
|
||||
STDMETHOD(SetProperty)(UINT32 index, PROPID propID, const PROPVARIANT *value, IProgress *progress);
|
||||
|
||||
STDMETHOD(SetFlatMode)(Int32 flatMode);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
CAgentFolder(): _proxyFolderItem(NULL) {}
|
||||
CAgentFolder(): _proxyFolderItem(NULL), _flatMode(0) {}
|
||||
|
||||
void Init(CProxyArchive *proxyHandler,
|
||||
CProxyFolder *proxyFolderItem,
|
||||
@@ -130,12 +142,20 @@ public:
|
||||
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:
|
||||
};
|
||||
|
||||
@@ -252,7 +272,7 @@ public:
|
||||
UString _folderPrefix;
|
||||
|
||||
UString _archiveNamePrefix;
|
||||
CProxyFolder *_archiveFolderItem;
|
||||
CAgentFolder *_agentFolder;
|
||||
|
||||
UString _archiveFilePath;
|
||||
|
||||
|
||||
@@ -36,25 +36,21 @@ STDMETHODIMP CAgent::SetFolder(IFolderFolder *folder)
|
||||
_archiveNamePrefix.Empty();
|
||||
if (folder == NULL)
|
||||
{
|
||||
_archiveFolderItem = NULL;
|
||||
_agentFolder = NULL;
|
||||
return S_OK;
|
||||
// folder = m_RootFolder;
|
||||
}
|
||||
else
|
||||
{
|
||||
CMyComPtr<IFolderFolder> archiveFolder = folder;
|
||||
CMyComPtr<IArchiveFolderInternal> archiveFolderInternal;
|
||||
RINOK(archiveFolder.QueryInterface(
|
||||
IID_IArchiveFolderInternal, &archiveFolderInternal));
|
||||
CAgentFolder *agentFolder;
|
||||
RINOK(archiveFolderInternal->GetAgentFolder(&agentFolder));
|
||||
_archiveFolderItem = agentFolder->_proxyFolderItem;
|
||||
RINOK(archiveFolder.QueryInterface(IID_IArchiveFolderInternal, &archiveFolderInternal));
|
||||
RINOK(archiveFolderInternal->GetAgentFolder(&_agentFolder));
|
||||
}
|
||||
|
||||
UStringVector pathParts;
|
||||
pathParts.Clear();
|
||||
CMyComPtr<IFolderFolder> folderItem = folder;
|
||||
if (_archiveFolderItem != NULL)
|
||||
if (folderItem != NULL)
|
||||
while (true)
|
||||
{
|
||||
CMyComPtr<IFolderFolder> newFolder;
|
||||
@@ -353,7 +349,7 @@ STDMETHODIMP CAgent::DeleteItems(
|
||||
CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);
|
||||
|
||||
CUIntVector realIndices;
|
||||
_archiveFolderItem->GetRealIndices(indices, numItems, realIndices);
|
||||
_agentFolder->GetRealIndices(indices, numItems, realIndices);
|
||||
CObjectVector<CUpdatePair2> updatePairs;
|
||||
int curIndex = 0;
|
||||
UInt32 numItemsInArchive;
|
||||
@@ -420,7 +416,7 @@ HRESULT CAgent::CreateFolder(
|
||||
|
||||
dirItem.Attributes = FILE_ATTRIBUTE_DIRECTORY;
|
||||
dirItem.Size = 0;
|
||||
dirItem.Name = _archiveFolderItem->GetFullPathPrefix() + folderName;
|
||||
dirItem.Name = _agentFolder->_proxyFolderItem->GetFullPathPrefix() + folderName;
|
||||
|
||||
SYSTEMTIME systemTime;
|
||||
FILETIME fileTime;
|
||||
@@ -455,11 +451,10 @@ HRESULT CAgent::RenameItem(
|
||||
CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);
|
||||
|
||||
CUIntVector realIndices;
|
||||
_archiveFolderItem->GetRealIndices(indices, numItems, realIndices);
|
||||
_agentFolder->GetRealIndices(indices, numItems, realIndices);
|
||||
|
||||
UString fullPrefix = _archiveFolderItem->GetFullPathPrefix();
|
||||
UString oldItemPath = fullPrefix +
|
||||
_archiveFolderItem->GetItemName(indices[0]);
|
||||
UString fullPrefix = _agentFolder->GetFullPathPrefixPlusPrefix(indices[0]);
|
||||
UString oldItemPath = fullPrefix + _agentFolder->GetName(indices[0]);
|
||||
UString newItemPath = fullPrefix + newItemName;
|
||||
|
||||
CObjectVector<CUpdatePair2> updatePairs;
|
||||
|
||||
@@ -41,11 +41,15 @@ STDMETHODIMP CAgentFolder::CopyTo(const UINT32 *indices, UINT32 numItems,
|
||||
IID_IFolderArchiveExtractCallback, &extractCallback2));
|
||||
}
|
||||
|
||||
NExtract::NPathMode::EEnum pathMode = _flatMode ?
|
||||
NExtract::NPathMode::kNoPathnames :
|
||||
NExtract::NPathMode::kCurrentPathnames;
|
||||
|
||||
extractCallbackSpec->Init(_agentSpec->GetArchive(),
|
||||
extractCallback2,
|
||||
false,
|
||||
path,
|
||||
NExtract::NPathMode::kCurrentPathnames,
|
||||
pathMode,
|
||||
NExtract::NOverwriteMode::kAskBefore,
|
||||
pathParts,
|
||||
_agentSpec->DefaultName,
|
||||
@@ -54,7 +58,7 @@ STDMETHODIMP CAgentFolder::CopyTo(const UINT32 *indices, UINT32 numItems,
|
||||
// ,_agentSpec->_srcDirectoryPrefix
|
||||
);
|
||||
CUIntVector realIndices;
|
||||
_proxyFolderItem->GetRealIndices(indices, numItems, realIndices);
|
||||
GetRealIndices(indices, numItems, realIndices);
|
||||
return _agentSpec->GetArchive()->Extract(&realIndices.Front(),
|
||||
realIndices.Size(), BoolToInt(false), extractCallback);
|
||||
COM_TRY_END
|
||||
|
||||
@@ -180,18 +180,15 @@ STDMETHODIMP CAgentFolder::CreateFolder(const wchar_t *name, IProgress *progress
|
||||
if (progress != 0)
|
||||
{
|
||||
CMyComPtr<IProgress> progressWrapper = progress;
|
||||
RINOK(progressWrapper.QueryInterface(
|
||||
IID_IFolderArchiveUpdateCallback, &updateCallback100));
|
||||
RINOK(progressWrapper.QueryInterface(IID_IFolderArchiveUpdateCallback, &updateCallback100));
|
||||
}
|
||||
return CommonUpdateOperation(false, true, false, name, NULL, NULL,
|
||||
0, 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 realIndices;
|
||||
CUIntVector indices;
|
||||
indices.Add(index);
|
||||
RINOK(_agentSpec->SetFolder(this));
|
||||
@@ -199,8 +196,7 @@ STDMETHODIMP CAgentFolder::Rename(UINT32 index, const wchar_t *newName, IProgres
|
||||
if (progress != 0)
|
||||
{
|
||||
CMyComPtr<IProgress> progressWrapper = progress;
|
||||
RINOK(progressWrapper.QueryInterface(
|
||||
IID_IFolderArchiveUpdateCallback, &updateCallback100));
|
||||
RINOK(progressWrapper.QueryInterface(IID_IFolderArchiveUpdateCallback, &updateCallback100));
|
||||
}
|
||||
return CommonUpdateOperation(false, false, true, newName, NULL, &indices.Front(),
|
||||
indices.Size(), updateCallback100);
|
||||
|
||||
Reference in New Issue
Block a user