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; }
HRESULT CFieldPrinter::PrintItemInfo(const CArc &arc, UInt32 index, bool techMode) { /* if (techMode) { g_StdOut << "Index = "; g_StdOut << (UInt64)index; g_StdOut << endl; } */ for (int i = 0; i < _fields.Size(); i++) { const CFieldInfo &fieldInfo = _fields[i]; if (!techMode) PrintSpaces(fieldInfo.PrefixSpacesWidth); NCOM::CPropVariant prop; if (fieldInfo.PropID == kpidPath) { UString s; RINOK(arc.GetItemPath(index, s)); prop = s; } else { RINOK(arc.Archive->GetProperty(index, fieldInfo.PropID, &prop)); } if (techMode) { g_StdOut << fieldInfo.Name << " = "; } int width = (fieldInfo.PropID == kpidPath) ? 0: fieldInfo.Width; if (fieldInfo.PropID == kpidAttrib && (prop.vt == VT_EMPTY || prop.vt == VT_UI4)) { UInt32 attrib = (prop.vt == VT_EMPTY) ? 0 : prop.ulVal; bool isFolder; RINOK(IsArchiveItemFolder(arc.Archive, index, isFolder)); char s[8]; GetAttribString(attrib, isFolder, s); g_StdOut << s; } else if (prop.vt == VT_EMPTY) { if (!techMode) PrintSpaces(width); } else if (fieldInfo.PropID == kpidMTime) { PrintTime(prop); } else if (prop.vt == VT_BSTR) { if (techMode) g_StdOut << prop.bstrVal; else PrintString(fieldInfo.TextAdjustment, width, prop.bstrVal); } else { UString s = ConvertPropertyToString(prop, fieldInfo.PropID); s.Replace(wchar_t(0xA), L' '); s.Replace(wchar_t(0xD), L' '); if (techMode) g_StdOut << s; else PrintString(fieldInfo.TextAdjustment, width, s); } if (techMode) g_StdOut << endl; } return S_OK; }
static HRESULT DecompressArchive( const CArc &arc, UInt64 packSize, const NWildcard::CCensorNode &wildcardCensor, const CExtractOptions &options, IExtractCallbackUI *callback, CArchiveExtractCallback *extractCallbackSpec, UString &errorMessage, UInt64 &stdInProcessed) { stdInProcessed = 0; IInArchive *archive = arc.Archive; CRecordVector<UInt32> realIndices; if (!options.StdInMode) { UInt32 numItems; RINOK(archive->GetNumberOfItems(&numItems)); for (UInt32 i = 0; i < numItems; i++) { UString filePath; RINOK(arc.GetItemPath(i, filePath)); bool isFolder; RINOK(IsArchiveItemFolder(archive, i, isFolder)); if (!wildcardCensor.CheckPath(filePath, !isFolder)) continue; realIndices.Add(i); } if (realIndices.Size() == 0) { callback->ThereAreNoFiles(); return S_OK; } } UStringVector removePathParts; UString outDir = options.OutputDir; outDir.Replace(L"*", GetCorrectFsPath(arc.DefaultName)); #ifdef _WIN32 // GetCorrectFullFsPath doesn't like "..". // outDir.TrimRight(); // outDir = GetCorrectFullFsPath(outDir); #endif if (!outDir.IsEmpty()) if (!NFile::NDirectory::CreateComplexDirectory(outDir)) { HRESULT res = ::GetLastError(); if (res == S_OK) res = E_FAIL; errorMessage = ((UString)L"Can not create output directory ") + outDir; return res; } extractCallbackSpec->Init( options.StdInMode ? &wildcardCensor : NULL, &arc, callback, options.StdOutMode, options.TestMode, options.CalcCrc, outDir, removePathParts, packSize); #if !defined(_7ZIP_ST) && !defined(_SFX) RINOK(SetProperties(archive, options.Properties)); #endif HRESULT result; Int32 testMode = (options.TestMode && !options.CalcCrc) ? 1: 0; if (options.StdInMode) { result = archive->Extract(NULL, (UInt32)(Int32)-1, testMode, extractCallbackSpec); NCOM::CPropVariant prop; if (archive->GetArchiveProperty(kpidPhySize, &prop) == S_OK) if (prop.vt == VT_UI8 || prop.vt == VT_UI4) stdInProcessed = ConvertPropVariantToUInt64(prop); } else result = archive->Extract(&realIndices.Front(), realIndices.Size(), testMode, extractCallbackSpec); return callback->ExtractResult(result); }