6 #include "7zFolderOutStream.h"
9 // #include "7z1Decode.h"
11 #include "../../../Common/ComTry.h"
12 #include "../../Common/StreamObjects.h"
13 #include "../../Common/ProgressUtils.h"
14 #include "../../Common/LimitedStreams.h"
19 struct CExtractFolderInfo
26 CBoolVector ExtractStatuses
;
32 CNum fileIndex
, CNum folderIndex
):
34 VolumeIndex(volumeIndex
),
37 FolderIndex(folderIndex
),
40 if (fileIndex
!= kNumNoIndex
)
42 ExtractStatuses
.Reserve(1);
43 ExtractStatuses
.Add(true);
48 STDMETHODIMP
CHandler::Extract(const UInt32
* indices
, UInt32 numItems
,
49 Int32 testModeSpec
, IArchiveExtractCallback
*extractCallbackSpec
)
52 bool testMode
= (testModeSpec
!= 0);
53 CMyComPtr
<IArchiveExtractCallback
> extractCallback
= extractCallbackSpec
;
54 UInt64 importantTotalUnPacked
= 0;
56 bool allFilesMode
= (numItems
== UInt32(-1));
62 _database
.Files
.Size();
69 if(_volumes.Size() != 1)
71 const CVolume &volume = _volumes.Front();
72 const CArchiveDatabaseEx &_database = volume.Database;
73 IInStream *_inStream = volume.Stream;
76 CObjectVector
<CExtractFolderInfo
> extractFolderInfoVector
;
77 for(UInt32 ii
= 0; ii
< numItems
; ii
++)
79 // UInt32 fileIndex = allFilesMode ? indexIndex : indices[indexIndex];
80 UInt32 ref2Index
= allFilesMode
? ii
: indices
[ii
];
81 // const CRef2 &ref2 = _refs[ref2Index];
83 // for(UInt32 ri = 0; ri < ref2.Refs.Size(); ri++)
86 // const CRef &ref = ref2.Refs[ri];
87 const CRef
&ref
= _refs
[ref2Index
];
89 int volumeIndex
= ref
.VolumeIndex
;
90 const CVolume
&volume
= _volumes
[volumeIndex
];
91 const CArchiveDatabaseEx
&database
= volume
.Database
;
92 UInt32 fileIndex
= ref
.ItemIndex
;
94 const CArchiveDatabaseEx
&database
= _database
;
95 UInt32 fileIndex
= ref2Index
;
98 CNum folderIndex
= database
.FileIndexToFolderIndexMap
[fileIndex
];
99 if (folderIndex
== kNumNoIndex
)
101 extractFolderInfoVector
.Add(CExtractFolderInfo(
105 fileIndex
, kNumNoIndex
));
108 if (extractFolderInfoVector
.IsEmpty() ||
109 folderIndex
!= extractFolderInfoVector
.Back().FolderIndex
111 || volumeIndex
!= extractFolderInfoVector
.Back().VolumeIndex
115 extractFolderInfoVector
.Add(CExtractFolderInfo(
119 kNumNoIndex
, folderIndex
));
120 const CFolder
&folderInfo
= database
.Folders
[folderIndex
];
121 UInt64 unPackSize
= folderInfo
.GetUnPackSize();
122 importantTotalUnPacked
+= unPackSize
;
123 extractFolderInfoVector
.Back().UnPackSize
= unPackSize
;
126 CExtractFolderInfo
&efi
= extractFolderInfoVector
.Back();
128 // const CFolderInfo &folderInfo = m_dam_Folders[folderIndex];
129 CNum startIndex
= database
.FolderStartFileIndex
[folderIndex
];
130 for (CNum index
= efi
.ExtractStatuses
.Size();
131 index
<= fileIndex
- startIndex
; index
++)
133 // UInt64 unPackSize = _database.Files[startIndex + index].UnPackSize;
134 // Count partial_folder_size
135 // efi.UnPackSize += unPackSize;
136 // importantTotalUnPacked += unPackSize;
137 efi
.ExtractStatuses
.Add(index
== fileIndex
- startIndex
);
142 extractCallback
->SetTotal(importantTotalUnPacked
);
151 // CDecoder1 decoder;
153 UInt64 currentImportantTotalUnPacked
= 0;
154 UInt64 totalFolderUnPacked
;
156 for(int i
= 0; i
< extractFolderInfoVector
.Size(); i
++,
157 currentImportantTotalUnPacked
+= totalFolderUnPacked
)
159 const CExtractFolderInfo
&efi
= extractFolderInfoVector
[i
];
160 totalFolderUnPacked
= efi
.UnPackSize
;
162 RINOK(extractCallback
->SetCompleted(¤tImportantTotalUnPacked
));
164 CFolderOutStream
*folderOutStream
= new CFolderOutStream
;
165 CMyComPtr
<ISequentialOutStream
> outStream(folderOutStream
);
168 const CVolume
&volume
= _volumes
[efi
.VolumeIndex
];
169 const CArchiveDatabaseEx
&database
= volume
.Database
;
171 const CArchiveDatabaseEx
&database
= _database
;
175 if (efi
.FileIndex
!= kNumNoIndex
)
176 startIndex
= efi
.FileIndex
;
178 startIndex
= database
.FolderStartFileIndex
[efi
.FolderIndex
];
181 HRESULT result
= folderOutStream
->Init(&database
,
183 volume
.StartRef2Index
,
188 &efi
.ExtractStatuses
, extractCallback
, testMode
);
192 if (efi
.FileIndex
!= kNumNoIndex
)
195 CNum folderIndex
= efi
.FolderIndex
;
196 const CFolder
&folderInfo
= database
.Folders
[folderIndex
];
198 CLocalProgress
*localProgressSpec
= new CLocalProgress
;
199 CMyComPtr
<ICompressProgressInfo
> progress
= localProgressSpec
;
200 localProgressSpec
->Init(extractCallback
, false);
202 CLocalCompressProgressInfo
*localCompressProgressSpec
=
203 new CLocalCompressProgressInfo
;
204 CMyComPtr
<ICompressProgressInfo
> compressProgress
= localCompressProgressSpec
;
205 localCompressProgressSpec
->Init(progress
, NULL
, ¤tImportantTotalUnPacked
);
207 CNum packStreamIndex
= database
.FolderStartPackStreamIndex
[folderIndex
];
208 UInt64 folderStartPackPos
= database
.GetFolderStreamPos(folderIndex
, 0);
211 CMyComPtr
<ICryptoGetTextPassword
> getTextPassword
;
213 extractCallback
.QueryInterface(IID_ICryptoGetTextPassword
, &getTextPassword
);
218 HRESULT result
= decoder
.Decode(
225 &database
.PackSizes
[packStreamIndex
],
237 if (result
== S_FALSE
)
239 RINOK(folderOutStream
->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError
));
242 if (result
== E_NOTIMPL
)
244 RINOK(folderOutStream
->FlushCorrupted(NArchive::NExtract::NOperationResult::kUnSupportedMethod
));
249 if (folderOutStream
->WasWritingFinished() != S_OK
)
251 RINOK(folderOutStream
->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError
));
257 RINOK(folderOutStream
->FlushCorrupted(NArchive::NExtract::NOperationResult::kDataError
));