Bug 545316 - Make 7zip library return archive information. r=blassey

--HG--
extra : rebase_source : be0104c75a12a55826d62fb198ba0fd1e88896f7
This commit is contained in:
Alex Pakhotin 2010-05-19 16:37:11 -04:00
parent 2abfb422b2
commit 146163a5a8
2 changed files with 100 additions and 2 deletions

View File

@ -700,3 +700,98 @@ int SzExtractSfx(const WCHAR *archiveName, DWORD sfxStubSize,
}
return SZ_OK;
}
/**
* Get information about 7z-SFX-archive
*
* @param archiveFileName Name of the archive
* @param sfxStubSize Size of the stub at the beginning of the file before the actual archive data (could be 0)
*
* Output parameters:
* @param pUncompressedSize Pointer to 64 bit integer for the total uncompressed size
* @param pNumberOfFiles (optional) Pointer to a number of files in the archive
* @param pNumberOfDirs (optional) Pointer to a number of directories in the archive
*/
int SzGetSfxArchiveInfo(const WCHAR *archiveName, const DWORD sfxStubSize,
ULONGLONG *pUncompressedSize, DWORD *pNumberOfFiles, DWORD *pNumberOfDirs)
{
if (!archiveName || !pUncompressedSize)
return SZ_ERROR_PARAM;
*pUncompressedSize = 0;
Initialize7z();
CMyComPtr<IInArchive> archive;
if (CreateArchiver(&CLSID_CFormat7z, &IID_IInArchive, (void **)&archive) != S_OK)
{
PrintError("Can not get class object");
return SZ_ERROR_FAIL;
}
CInFileStream *fileSpec = new CInFileStream;
CMyComPtr<IInStream> file = fileSpec;
if (!fileSpec->Open(archiveName))
{
PrintError("Can not open archive file");
return SZ_ERROR_NO_ARCHIVE;
}
if (sfxStubSize > 0)
file->Seek(sfxStubSize, STREAM_SEEK_SET, NULL);
CArchiveOpenCallback *openCallbackSpec = new CArchiveOpenCallback;
CMyComPtr<IArchiveOpenCallback> openCallback(openCallbackSpec);
openCallbackSpec->PasswordIsDefined = false;
if (archive->Open(file, 0, openCallback) != S_OK)
{
PrintError("Can not open archive");
return SZ_ERROR_NO_ARCHIVE;
}
UInt32 numItems = 0;
archive->GetNumberOfItems(&numItems);
if (numItems == 0)
{
PrintError("No files found in the archive");
return SZ_ERROR_DATA;
}
if (pNumberOfFiles)
*pNumberOfFiles = 0;
if (pNumberOfDirs)
*pNumberOfDirs = 0;
// Iterate through all items
for (UInt32 i = 0; i < numItems; i++)
{
bool isDir = false;
RINOK(IsArchiveItemFolder(archive, i, isDir));
if (isDir)
{
if (pNumberOfDirs)
(*pNumberOfDirs)++;
continue;
}
UInt64 unpackSize = 0;
NWindows::NCOM::CPropVariant prop;
if (archive->GetProperty(i, kpidSize, &prop) != S_OK)
{
PrintError("Cannot get size property value");
return SZ_ERROR_DATA;
}
if (prop.vt != VT_EMPTY)
unpackSize = ConvertPropVariantToUInt64(prop);
(*pUncompressedSize) += unpackSize;
if (pNumberOfFiles)
(*pNumberOfFiles)++;
}
return SZ_OK;
}

View File

@ -35,7 +35,10 @@ int SzExtract(const WCHAR *archiveName,
SzExtractProgressCallback *progressCallback);
int SzExtractSfx(const WCHAR *archiveName, DWORD sfxStubSize,
const WCHAR *fileToExtract, const WCHAR *outputDir,
SzExtractProgressCallback *progressCallback);
const WCHAR *fileToExtract, const WCHAR *outputDir,
SzExtractProgressCallback *progressCallback);
int SzGetSfxArchiveInfo(const WCHAR *archiveName, const DWORD sfxStubSize,
ULONGLONG *pUncompressedSize, DWORD *pNumberOfFiles = NULL, DWORD *pNumberOfDirs = NULL);
#endif // __7ZLIB_H