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 CProxyArc::AddRealIndices(unsigned dirIndex, CUIntVector &realIndices) const { const CProxyDir &dir = Dirs[dirIndex]; if (dir.IsLeaf()) realIndices.Add(dir.ArcIndex); unsigned i; for (i = 0; i < dir.SubDirs.Size(); i++) AddRealIndices(dir.SubDirs[i], realIndices); for (i = 0; i < dir.SubFiles.Size(); i++) realIndices.Add(dir.SubFiles[i]); }
void SortFileNames(const UStringVector &strings, CUIntVector &indices) { const unsigned numItems = strings.Size(); indices.ClearAndSetSize(numItems); if (numItems == 0) return; unsigned *vals = &indices[0]; for (unsigned i = 0; i < numItems; i++) vals[i] = i; indices.Sort(CompareStrings, (void *)&strings); }
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()); }
void CProxyArc::GetRealIndices(unsigned dirIndex, const UInt32 *indices, UInt32 numItems, CUIntVector &realIndices) const { const CProxyDir &dir = Dirs[dirIndex]; realIndices.Clear(); for (UInt32 i = 0; i < numItems; i++) { UInt32 index = indices[i]; unsigned numDirItems = dir.SubDirs.Size(); if (index < numDirItems) AddRealIndices(dir.SubDirs[index], realIndices); else realIndices.Add(dir.SubFiles[index - numDirItems]); } HeapSort(&realIndices.Front(), realIndices.Size()); }
void CProxyArc2::AddRealIndices_of_ArcItem(unsigned arcIndex, bool includeAltStreams, CUIntVector &realIndices) const { realIndices.Add(arcIndex); const CProxyFile2 &file = Files[arcIndex]; if (file.DirIndex >= 0) AddRealIndices_of_Dir(file.DirIndex, includeAltStreams, realIndices); if (includeAltStreams && file.AltDirIndex >= 0) AddRealIndices_of_Dir(file.AltDirIndex, includeAltStreams, realIndices); }
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::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(IsArchiveItemAnti(GetArchive(), i, up2.IsAnti)); up2.ArcIndex = i; UString oldFullPath; RINOK(GetArchiveItemPath(GetArchive(), i, DefaultName, 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); }