void CVersitTest::StreamInL() //Convert the iVersit into stream format, save it as "ExpDelVersitIn" //and internalize it as a CVersitParser { RFile file; FileRegister->CreateTempFileLC(file, _L("ExpDelVersit2")); CDirectFileStore* store = CDirectFileStore::NewLC(file); store->SetTypeL(KDirectFileStoreLayoutUid); RStoreWriteStream outstream; TStreamId id = outstream.CreateLC(*store); TInt length=iVersit.Length(); for (TInt ii=0; ii<length; ii++) outstream.WriteInt8L(iVersit[ii]); outstream.CommitL(); CleanupStack::PopAndDestroy(); store->SetRootL(id); store->CommitL(); CleanupStack::PopAndDestroy(2); // store + file FileRegister->OpenTempFileLC(file, _L("ExpDelVersit2")); store = CDirectFileStore::NewLC(file); RStoreReadStream instream; instream.OpenLC(*store,store->Root()); iParser->InternalizeL(instream); CleanupStack::PopAndDestroy(3); //store + stream + file }
/** * Open the backup store (AlarmServer.ini) using the specified * file mode. * * @return A file store object which encapsulates the backup store. */ CDirectFileStore* CASSrvAlarmStore::OpenStoreL(TUint aMode) const { RFs& fsSession = ServerWideData().FsSession(); TFileName fileName; ASSrvStaticUtils::GetServerPathL(fsSession, fileName); CDirectFileStore* store = NULL; TInt error = KErrNone; // if (aMode == EFileRead) { // First try to open the store. If opening fails, then we // replace the store with a blank one. TRAP(error, store = CDirectFileStore::OpenL(fsSession, fileName, aMode)); } // if (!store || error != KErrNone) { store = CDirectFileStore::ReplaceLC(fsSession, fileName, aMode); // const TUidType type(KDirectFileStoreLayoutUid, KAlarmStoreUid, KNullUid); store->SetTypeL(type); // CleanupStack::Pop(store); } // return store; }
void CCreGenerator::CommitChangesToCreL(RFs& aFs,TUint8 aPersistVersion,CHeapRepository& aRep,const TDesC& aTargetFilePath) { HBufC* tmpFilePath=aTargetFilePath.AllocLC(); TPtr tmpFilePathPtr(tmpFilePath->Des()); tmpFilePathPtr.Replace(tmpFilePath->Length()-3,3,KTmpExtension()); CDirectFileStore* store = CDirectFileStore::ReplaceLC(aFs, *tmpFilePath,(EFileWrite | EFileShareExclusive)); const TUid uid2 = KNullUid ; store->SetTypeL(TUidType(KDirectFileStoreLayoutUid, uid2, KServerUid3)) ; // Write the stream index/dictionary as root stream within the store // so we can access it when we do a restore later on RStoreWriteStream rootStream ; TStreamId rootStreamId = rootStream.CreateLC(*store) ; ExternalizeCre(aPersistVersion,aRep, rootStream) ; rootStream.CommitL() ; CleanupStack::PopAndDestroy(&rootStream) ; store->SetRootL(rootStreamId); store->CommitL(); CleanupStack::PopAndDestroy(store) ; User::LeaveIfError(aFs.Replace(*tmpFilePath,aTargetFilePath)); CleanupStack::PopAndDestroy(); }
void CVersitTest::Stream2LC(RReadStream& aStream) { GetSampleVersit2L(); RFile file; FileRegister->CreateTempFileLC(file, _L("ExpDelVersitIn2")); CDirectFileStore* store = CDirectFileStore::NewLC(file); store->SetTypeL(KDirectFileStoreLayoutUid); RStoreWriteStream outstream; TStreamId id = outstream.CreateLC(*store); TInt length=iVersit.Length(); for (TInt ii=0; ii<length; ii++) outstream.WriteInt8L(iVersit[ii]); outstream.CommitL(); CleanupStack::PopAndDestroy(); store->SetRootL(id); store->CommitL(); CleanupStack::PopAndDestroy(); // store FileRegister->OpenTempFileLC(file, _L("ExpDelVersitIn2")); store = CDirectFileStore::NewLC(file); RStoreReadStream instream; instream.OpenLC(*store,store->Root()); CleanupStack::Pop(); // instream aStream=RReadStream(instream); }
LOCAL_C void DoTestsL() { // create test database test.Start(_L("@SYMTESTCaseID:PIM-T-EXPDEL-0001 Preparing tests")); FileRegister = CTestRegister::NewLC(); TheIds=CContactIdArray::NewLC(); TRAPD(err,CContactDatabase::DeleteDatabaseL(KDatabaseFileName)); if (err < KErrNotFound) { User::Leave(err); } CVersitTest* vtest=NULL; if (vtest) CleanupStack::PopAndDestroy(); //vtest; vtest=new(ELeave)CVCardTest; CleanupStack::PushL(vtest); CVersitTest* vtest2=NULL; vtest2=new(ELeave)CVCardTest; CleanupStack::PushL(vtest2); //Populating test.Next(_L("creating 20 contacts")); CContactDatabase *db=CntTest->CreateDatabaseL(); AddNewContactsL(); test(db->CountL()==20); test.Next(_L("Increase Access Count")); IncAccessCount(); test.Next(_L("Removing second contact")); TContactIter iter(*db); TContactItemId theid=iter.FirstL(); theid=iter.NextL(); db->DeleteContactL(theid); test(db->CountL()==19); test.Next(_L("Synchronizing")); Synchronize(); test(db->CountL()==19); test.Next(_L("Exporting")); TheIds=CContactIdArray::NewLC(); theid=iter.FirstL(); while(theid!=KNullContactId ) { TheIds->AddL(theid); theid=iter.NextL(); } RFile file; FileRegister->CreateTempFileLC(file, _L("expdela")); CDirectFileStore* store = CDirectFileStore::NewLC(file); store->SetTypeL(KDirectFileStoreLayoutUid); RStoreWriteStream outstream; TStreamId id = outstream.CreateLC(*store); TUid uid; uid.iUid=KVersitEntityUidVCard; db->ExportSelectedContactsL(uid,*TheIds,outstream,CContactDatabase::EIncludeX | CContactDatabase::EIncreaseAccessCount); outstream.CommitL(); store->SetRootL(id); store->CommitL(); CleanupStack::PopAndDestroy(3); // store, oustream, file CleanupStack::PopAndDestroy(); //TheIds test.Next(_L("Emptying database")); EmptyDatabase(); if (TheItems) TheItems->ResetAndDestroy(); delete TheItems; if (TheItems2) TheItems2->ResetAndDestroy(); delete TheItems2; CleanupStack::PopAndDestroy(2); // vtest, vtest2 CntTest->CloseDatabase(); CleanupStack::PopAndDestroy(); //TheIds CleanupStack::PopAndDestroy(FileRegister); }