5 #include "Common/ComTry.h"
\r
6 #include "Common/IntToString.h"
\r
7 #include "Common/StringConvert.h"
\r
9 #include "Windows/PropVariant.h"
\r
10 #include "Windows/Time.h"
\r
12 #include "../../Common/LimitedStreams.h"
\r
13 #include "../../Common/ProgressUtils.h"
\r
15 #include "../../Compress/CopyCoder.h"
\r
17 #include "../Common/ItemNameUtils.h"
\r
19 #include "IsoHandler.h"
\r
21 using namespace NWindows;
\r
22 using namespace NTime;
\r
24 namespace NArchive {
\r
27 static const STATPROPSTG kProps[] =
\r
29 { NULL, kpidPath, VT_BSTR},
\r
30 { NULL, kpidIsDir, VT_BOOL},
\r
31 { NULL, kpidSize, VT_UI8},
\r
32 { NULL, kpidPackSize, VT_UI8},
\r
33 { NULL, kpidMTime, VT_FILETIME}
\r
36 static const STATPROPSTG kArcProps[] =
\r
38 { NULL, kpidComment, VT_BSTR},
\r
39 { NULL, kpidCTime, VT_FILETIME},
\r
40 { NULL, kpidMTime, VT_FILETIME}
\r
41 // { NULL, kpidPhySize, VT_UI8},
\r
42 // { NULL, kpidHeadersSize, VT_UI8}
\r
45 IMP_IInArchive_Props
\r
46 IMP_IInArchive_ArcProps
\r
48 STDMETHODIMP CHandler::Open(IInStream *stream,
\r
49 const UInt64 * /* maxCheckStartPosition */,
\r
50 IArchiveOpenCallback * /* openArchiveCallback */)
\r
56 if (_archive.Open(stream) != S_OK)
\r
60 // catch(...) { return S_FALSE; }
\r
65 STDMETHODIMP CHandler::Close()
\r
72 STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
\r
74 *numItems = _archive.Refs.Size() + _archive.BootEntries.Size();
\r
78 static void AddString(AString &s, const char *name, const Byte *p, int size)
\r
81 for (i = 0; i < size && p[i]; i++);
\r
82 for (; i > 0 && p[i - 1] == ' '; i--);
\r
86 memcpy(d.GetBuffer(i), p, i);
\r
95 #define ADD_STRING(n, v) AddString(s, n, vol. ## v, sizeof(vol. ## v))
\r
97 STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
\r
100 NWindows::NCOM::CPropVariant prop;
\r
101 const CVolumeDescriptor &vol = _archive.VolDescs[_archive.MainVolDescIndex];
\r
107 ADD_STRING("System", SystemId);
\r
108 ADD_STRING("Volume", VolumeId);
\r
109 ADD_STRING("VolumeSet", VolumeSetId);
\r
110 ADD_STRING("Publisher", PublisherId);
\r
111 ADD_STRING("Preparer", DataPreparerId);
\r
112 ADD_STRING("Application", ApplicationId);
\r
113 ADD_STRING("Copyright", CopyrightFileId);
\r
114 ADD_STRING("Abstract", AbstractFileId);
\r
115 ADD_STRING("Bib", BibFileId);
\r
119 case kpidCTime: { FILETIME utc; if (vol.CTime.GetFileTime(utc)) prop = utc; break; }
\r
120 case kpidMTime: { FILETIME utc; if (vol.MTime.GetFileTime(utc)) prop = utc; break; }
\r
121 // case kpidPhySize: break;
\r
122 // case kpidHeadersSize: break;
\r
123 case kpidError: if (_archive.IncorrectBigEndian) prop = "Incorrect big-endian headers"; break;
\r
125 prop.Detach(value);
\r
130 STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
\r
133 NWindows::NCOM::CPropVariant prop;
\r
134 if (index >= (UInt32)_archive.Refs.Size())
\r
136 index -= _archive.Refs.Size();
\r
137 const CBootInitialEntry &be = _archive.BootEntries[index];
\r
142 // wchar_t name[32];
\r
143 // ConvertUInt64ToString(index + 1, name);
\r
144 UString s = L"[BOOT]" WSTRING_PATH_SEPARATOR;
\r
148 prop = (const wchar_t *)s;
\r
151 case kpidIsDir: prop = false; break;
\r
154 prop = (UInt64)_archive.GetBootItemSize(index);
\r
160 const CRef &ref = _archive.Refs[index];
\r
161 const CDir &item = ref.Dir->_subItems[ref.Index];
\r
165 // if (item.FileId.GetCapacity() >= 0)
\r
168 if (_archive.IsJoliet())
\r
169 s = item.GetPathU();
\r
171 s = MultiByteToUnicodeString(item.GetPath(_archive.IsSusp, _archive.SuspSkipSize), CP_OEMCP);
\r
173 int pos = s.ReverseFind(L';');
\r
174 if (pos >= 0 && pos == s.Length() - 2)
\r
175 if (s[s.Length() - 1] == L'1')
\r
178 if (s[s.Length() - 1] == L'.')
\r
179 s = s.Left(s.Length() - 1);
\r
180 prop = (const wchar_t *)NItemName::GetOSName2(s);
\r
183 case kpidIsDir: prop = item.IsDir(); break;
\r
187 prop = (UInt64)item.DataLength;
\r
192 if (item.DateTime.GetFileTime(utc))
\r
198 prop.Detach(value);
\r
203 STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
\r
204 Int32 testMode, IArchiveExtractCallback *extractCallback)
\r
207 bool allFilesMode = (numItems == (UInt32)-1);
\r
209 numItems = _archive.Refs.Size();
\r
212 UInt64 totalSize = 0;
\r
214 for(i = 0; i < numItems; i++)
\r
216 UInt32 index = (allFilesMode ? i : indices[i]);
\r
217 if (index < (UInt32)_archive.Refs.Size())
\r
219 const CRef &ref = _archive.Refs[index];
\r
220 const CDir &item = ref.Dir->_subItems[ref.Index];
\r
221 totalSize += item.DataLength;
\r
225 totalSize += _archive.GetBootItemSize(index - _archive.Refs.Size());
\r
228 extractCallback->SetTotal(totalSize);
\r
230 UInt64 currentTotalSize = 0;
\r
231 UInt64 currentItemSize;
\r
233 NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
\r
234 CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
\r
236 CLocalProgress *lps = new CLocalProgress;
\r
237 CMyComPtr<ICompressProgressInfo> progress = lps;
\r
238 lps->Init(extractCallback, false);
\r
240 CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
\r
241 CMyComPtr<ISequentialInStream> inStream(streamSpec);
\r
242 streamSpec->SetStream(_stream);
\r
244 CLimitedSequentialOutStream *outStreamSpec = new CLimitedSequentialOutStream;
\r
245 CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
\r
247 for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
\r
249 lps->InSize = lps->OutSize = currentTotalSize;
\r
250 RINOK(lps->SetCur());
\r
251 currentItemSize = 0;
\r
252 CMyComPtr<ISequentialOutStream> realOutStream;
\r
253 Int32 askMode = testMode ?
\r
254 NExtract::NAskMode::kTest :
\r
255 NExtract::NAskMode::kExtract;
\r
256 UInt32 index = allFilesMode ? i : indices[i];
\r
258 RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
\r
261 if (index < (UInt32)_archive.Refs.Size())
\r
263 const CRef &ref = _archive.Refs[index];
\r
264 const CDir &item = ref.Dir->_subItems[ref.Index];
\r
267 RINOK(extractCallback->PrepareOperation(askMode));
\r
268 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
\r
271 currentItemSize = item.DataLength;
\r
272 blockIndex = item.ExtentLocation;
\r
276 int bootIndex = index - _archive.Refs.Size();
\r
277 const CBootInitialEntry &be = _archive.BootEntries[bootIndex];
\r
278 currentItemSize = _archive.GetBootItemSize(bootIndex);
\r
279 blockIndex = be.LoadRBA;
\r
282 if (!testMode && !realOutStream)
\r
284 RINOK(extractCallback->PrepareOperation(askMode));
\r
285 outStreamSpec->SetStream(realOutStream);
\r
286 realOutStream.Release();
\r
287 outStreamSpec->Init(currentItemSize);
\r
288 RINOK(_stream->Seek(blockIndex * _archive.BlockSize, STREAM_SEEK_SET, NULL));
\r
289 streamSpec->Init(currentItemSize);
\r
290 RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
\r
291 outStreamSpec->ReleaseStream();
\r
292 RINOK(extractCallback->SetOperationResult(outStreamSpec->IsFinishedOK() ?
\r
293 NExtract::NOperationResult::kOK:
\r
294 NExtract::NOperationResult::kDataError));
\r
300 STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
\r
305 UInt64 currentItemSize;
\r
306 if (index < (UInt32)_archive.Refs.Size())
\r
308 const CRef &ref = _archive.Refs[index];
\r
309 const CDir &item = ref.Dir->_subItems[ref.Index];
\r
312 currentItemSize = item.DataLength;
\r
313 blockIndex = item.ExtentLocation;
\r
317 int bootIndex = index - _archive.Refs.Size();
\r
318 const CBootInitialEntry &be = _archive.BootEntries[bootIndex];
\r
319 currentItemSize = _archive.GetBootItemSize(bootIndex);
\r
320 blockIndex = be.LoadRBA;
\r
322 return CreateLimitedInStream(_stream, blockIndex * _archive.BlockSize, currentItemSize, stream);
\r