void CODF::GetODFTextL(const TDesC& aFileName,CEikEdwin* aEdwin) { iEdwin = aEdwin; RFs aRFSession; aRFSession.Connect(); CZipFile* zipFile = CZipFile::NewL(aRFSession, aFileName); CleanupStack::PushL(zipFile); CZipFileMember* member = zipFile->CaseInsensitiveMemberL(content); CleanupStack::PushL(member); RZipFileMemberReaderStream* stream; zipFile->GetInputStreamL(member, stream); CleanupStack::PushL(stream); HBufC8* aBuffer = HBufC8::NewL(member->UncompressedSize()); TPtr8 aBufferPtr(aBuffer->Des()); User::LeaveIfError(stream->Read(aBufferPtr, member->UncompressedSize())); CleanupStack::PopAndDestroy(3); aRFSession.Close(); CleanupStack::PushL(aBuffer); _LIT8 (KMimeType, "text/xml"); CParser* aParser=CParser::NewL(KMimeType,*this); CleanupStack::PushL(aParser); aParser->ParseBeginL(); aParser->ParseL(aBufferPtr); aParser->ParseEndL(); CleanupStack::PopAndDestroy( aParser); CleanupStack::PopAndDestroy( aBuffer); };
void CZipFileDecompressor::DecompressNextMemberL(CZipFileMember& aMember) { __ASSERT_ALWAYS(!iUncompressedFile.SubSessionHandle(), User::Invariant()); __ASSERT_ALWAYS(!iUncompressedData, User::Invariant()); //Ignore entries that has zero uncompressed size. //(This includes e.g. directories) if (aMember.UncompressedSize() > 0) { const TChar KDirectorySeparator('\\'); TUint32 uncompressedSize = aMember.UncompressedSize(); HBufC8* uncompressedData = HBufC8::NewLC(uncompressedSize); RZipFileMemberReaderStream* readerStream; User::LeaveIfError(iZipFile->GetInputStreamL(&aMember, readerStream)); CleanupStack::PushL(readerStream); TPtr8 uncompressedDataPtr = uncompressedData->Des(); User::LeaveIfError(readerStream->Read(uncompressedDataPtr, uncompressedDataPtr.MaxLength())); CleanupStack::PopAndDestroy(readerStream); HBufC* fileName = aMember.Name()->AllocLC(); TPtr fileNamePtr= fileName->Des(); TInt lastDirectorySeparator = fileName->LocateReverse(KDirectorySeparator); if (lastDirectorySeparator >= 0) { fileNamePtr = fileName->Mid(lastDirectorySeparator+1); } TParsePtr fileNameParser(fileNamePtr); User::LeaveIfError(iUncompressedFile.Replace(iFileServer, fileNameParser.NameAndExt(), EFileWrite)); CleanupStack::PopAndDestroy(fileName); CleanupStack::Pop(uncompressedData); iUncompressedData = uncompressedData; iUncompressedFile.Write(*iUncompressedData, iStatus); SetActive(); } else { iStatus = KRequestPending; SetActive(); TRequestStatus* ownStatus = &iStatus; User::RequestComplete(ownStatus, KErrNone); } }
TBool WidgetUnzipUtilityS60::RunUnzipL() { CZipFileMember* member = iMembers->NextL(); if (member) { CleanupStack::PushL(member); RZipFileMemberReaderStream* stream; User::LeaveIfError(iZipFile->GetInputStreamL(member, stream)); CleanupStack::PushL(stream); HBufC8* buffer = HBufC8::NewLC(member->UncompressedSize()); TPtr8 bufferPtr(buffer->Des()); User::LeaveIfError(stream->Read(bufferPtr, member->UncompressedSize())); TFileName text; text.Copy(*iTempZipPath); text.Append(_L('\\')); text.Append(*member->Name()); HBufC* zipedFileNameAndPath = text.AllocLC(); TInt index = zipedFileNameAndPath->LocateReverse('\\'); if (index >= 0) { TPtrC path = zipedFileNameAndPath->Left(index + 1); iFs.MkDirAll(path); // errors are ok } if (zipedFileNameAndPath->Right(1).Compare(_L('\\')) != 0) { RFile file; CleanupClosePushL(file); file.Replace(iFs,*zipedFileNameAndPath,EFileWrite); User::LeaveIfError(file.Write(*buffer)); CleanupStack::PopAndDestroy(); // file } iUncompressedSize += member->UncompressedSize(); CleanupStack::PopAndDestroy(4); return ETrue; } else { return EFalse; } }
//static TUint32 WidgetUnzipUtilityS60::uncompressedSizeL(const QString& aZipFileName, const TChar& aDriveLetter) { RFs fs; User::LeaveIfError(fs.Connect()); // not possible to continue without RFs CleanupClosePushL(fs); TUint64 uncompressedSize(0); TInt allocUnitSize(8192); // use 8kb cluster size when no information is available TInt drive(0); TInt err = fs.CharToDrive(aDriveLetter, drive); // get cluster size to calculate uncompressed widget size more accurately if (!err) { TVolumeIOParamInfo ioInfo; err = fs.VolumeIOParam(drive, ioInfo); // VolumeIOParam.iClusterSize contains also possible error code if (!err && ioInfo.iClusterSize > 0) { allocUnitSize = ioInfo.iClusterSize; } } QString zipFileName = QDir::toNativeSeparators(aZipFileName); TPtrC16 zName(reinterpret_cast<const TUint16*>(zipFileName.utf16())); CZipFile *zipfile = CZipFile::NewL(fs, zName); CleanupStack::PushL(zipfile); CZipFileMemberIterator *members = zipfile->GetMembersL(); CleanupStack::PushL(members); CZipFileMember* member = members->NextL(); while (member != NULL) { TUint32 fileSize(member->UncompressedSize()); if(fileSize != UINT_MAX) fileSize = (fileSize + (allocUnitSize - (fileSize % allocUnitSize))); uncompressedSize += fileSize; delete member; member = members->NextL(); } CleanupStack::PopAndDestroy(3); // members, zipfile, fs.connect if(uncompressedSize > UINT_MAX) return UINT_MAX; return (TUint32)uncompressedSize; }
// static QString WidgetUnzipUtilityS60::fileContentsL(const QString& aZipFileName, const QString& aFileName, const Qt::CaseSensitivity& cs) { QString zipFileName = QDir::toNativeSeparators(aZipFileName); QString contents; TPtrC16 zName(reinterpret_cast<const TUint16*>(zipFileName.utf16())); RFs iFs; User::LeaveIfError(iFs.Connect()); CZipFile *zipfile = CZipFile::NewL(iFs, zName); CleanupStack::PushL(zipfile); CZipFileMemberIterator *members = zipfile->GetMembersL(); CZipFileMember* member; while ((member = members->NextL()) != 0) { QString filename = QString::fromUtf16(member->Name()->Ptr(), member->Name()->Length()); // If the member is the desired file, extract it if (!filename.compare(aFileName, cs)) { RZipFileMemberReaderStream *stream; zipfile->GetInputStreamL(member, stream); CleanupStack::PushL(stream); HBufC8 *buffer = HBufC8::NewLC(member->UncompressedSize()); TPtr8 bufferPtr(buffer->Des()); User::LeaveIfError(stream->Read(bufferPtr, member->UncompressedSize())); QByteArray data(reinterpret_cast<const char*>(buffer->Ptr()), buffer->Length()); QString ret(data); CleanupStack::PopAndDestroy(3); // zipfile, stream, buffer return ret; } } CleanupStack::PopAndDestroy(); return contents; }