void TestFourL() { g_test.Start(_L("Check that Settings are saved - killing ContactLockSrv")); g_test.Next(_L("Setting up...")); CLockServerTester* lockSrvTester = CLockServerTester::NewL(); CleanupStack::PushL(lockSrvTester); CContactDatabase* database = SetupLC(); g_test.Next( _L("Assign Speed Dial")); TInt error = KErrNone; TRAP(error, AssignSpeedDialL( KSpeedDialContact, KSpeedDialPositionOne, *database ) ); g_test(error == KErrNone); g_test.Next( _L("Update Speed Dial")); error = KErrNone; TRAP(error, UpdateSpeedDialL( KSpeedDialContact, KSpeedDialPositionTwo, *database ) ); g_test(error == KErrNone); g_test.Next( _L("Change Database Drive")); CContactDatabase::SetDatabaseDriveL(TDriveUnit(EDriveD),EFalse); CleanupStack::PopAndDestroy(database); // Kill ContactLockServer process g_test.Next( _L("Kill CntServer")); lockSrvTester->FindServerAndKillItL(); CleanupStack::PopAndDestroy( lockSrvTester ); g_test.Next( _L("Open Database")); database = CContactDatabase::OpenL(KDbFileName); CleanupStack::PushL(database); TDriveUnit driveUnit; CContactDatabase::DatabaseDrive(driveUnit); g_test.Next( _L("Check that Database Drive is changed")); g_test(driveUnit==TDriveUnit(EDriveD)); CContactItem* item = database->ReadContactL(KSpeedDialContact); CleanupStack::PushL(item); g_test.Next( _L("Check that Speed Dial is remembered")); g_test(item->Id() == KSpeedDialContact); // retored item should be a SpeedDial g_test(ContactIsASpeedDial( *item )); // reset Database Drive g_test.Next( _L("Reset Database Drive setting")); CContactDatabase::SetDatabaseDriveL(TDriveUnit(EDriveC),EFalse); CleanupStack::PopAndDestroy(item); CleanupStack::PopAndDestroy(database); g_test.End(); }
void TestThreeL() { g_test.Start(_L("Check that Settings are saved - normal shutdown")); g_test.Next(_L("Setting up...")); CContactDatabase* database = SetupLC(); g_test.Next( _L("Assign Speed Dial")); TInt error = KErrNone; TRAP(error, AssignSpeedDialL( KSpeedDialContact, KSpeedDialPositionOne, *database ) ); g_test(error == KErrNone); g_test.Next( _L("Update Speed Dial")); error = KErrNone; TRAP(error, UpdateSpeedDialL( KSpeedDialContact, KSpeedDialPositionTwo, *database ) ); g_test(error == KErrNone); g_test.Next( _L("Change Database Drive")); CContactDatabase::SetDatabaseDriveL(TDriveUnit(EDriveD),EFalse); CleanupStack::PopAndDestroy( database ); g_test.Next(_L("Wait for Contact Server to shutdown")); // wait until Contacts Lock Server shuts down // applicabale only in the case of transient server. User::After(6000000); g_test.Next( _L("Try to open Database again")); database = CContactDatabase::OpenL(KDbFileName); CleanupStack::PushL(database); TDriveUnit driveUnit; CContactDatabase::DatabaseDrive(driveUnit); g_test.Next( _L("Check that Database Drive is changed")); g_test(driveUnit==TDriveUnit(EDriveD)); CContactItem* item = database->ReadContactL(KSpeedDialContact); CleanupStack::PushL(item); g_test.Next( _L("Check that Speed Dial is remembered")); g_test(item->Id() == KSpeedDialContact); // retored item should be a SpeedDial g_test(ContactIsASpeedDial( *item )); // reset Database Drive g_test.Next( _L("Reset Database Drive setting")); CContactDatabase::SetDatabaseDriveL(TDriveUnit(EDriveC),EFalse); CleanupStack::PopAndDestroy(item); CleanupStack::PopAndDestroy(database); g_test.End(); }
void CMsvIndexContext::DoChangeDriveL(TUint aNewDriveIndex, TBool aIsRemovePartial, TDriveNumber& aNewDriveNumber) { iObserverStatus = NULL; TMsvPreferredDrive driveEntry; CMsvPreferredDriveList::GetDriveList()->DriveInfoL(aNewDriveIndex, driveEntry); aNewDriveNumber = driveEntry.driveNum; if(EMsvMessageStoreUnavailableStatus == driveEntry.status) { // Create the database and all standard table. CMsvDBAdapter::CreateDBL(driveEntry.driveNum); // Update the drive status. CMsvPreferredDriveList::GetDriveList()->UpdateDriveStatusL(aNewDriveIndex, EMsvMessageStoreAvailableStatus); TParse parse; TPtrC drive(TDriveUnit(driveEntry.driveNum).Name()); parse.Set(KMsvDefaultIndexFile2(), &drive, NULL); iMessageFolder = parse.DriveAndPath(); ResetAndCreateNewMailStoreL(); iRunMailInit = ETrue; // Perform ChangeDrive operation. iIndexAdapter->ChangeDriveL(aNewDriveIndex, aIsRemovePartial); // Read initial entries from resources CreateStandardEntriesFromResourceFileL(KCurrentDriveId); iIndexAdapter->SetLocalServiceComplete(); } else { // Update the message folder local variable. TParse parse; TPtrC drive(TDriveUnit(driveEntry.driveNum).Name()); parse.Set(KMsvDefaultIndexFile2(), &drive, NULL); iMessageFolder = parse.DriveAndPath(); ResetAndCreateNewMailStoreL(EFalse); // Perform ChangeDrive operation. iIndexAdapter->ChangeDriveL(aNewDriveIndex, aIsRemovePartial); iRunMailInit = EFalse; } // Create service directories in new drive. TRAP_IGNORE(DoCreateServiceDirsL(KCurrentDriveId)); TRAP_IGNORE(LocalizeStandardFoldersL()); }
void CMsvIndexContext::CreateStoreDeleteFile() #endif { #if (!defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT) TDriveNumber aDriveNum = (TDriveNumber)(TInt) Config().iDrive; #endif RFs& fs = iServer.FileSession(); TInt err = fs.SetSessionToPrivate(aDriveNum); if(err == KErrNone) { RFile storeDeletedFile; #if (defined SYMBIAN_MESSAGESTORE_UNIT_TESTCODE) TParse parse; TPtrC drive(TDriveUnit(aDriveNum).Name()); parse.Set(KStoreDeletedFile, &drive, NULL); TFileName fileName = parse.FullName(); #else TFileName fileName(KStoreDeletedFile); #endif // #if (defined SYMBIAN_MESSAGESTORE_UNIT_TESTCODE) err = storeDeletedFile.Replace(fs, fileName, EFileShareExclusive); if(err == KErrNone) { _LIT8(KMsvIndexStoreDeleted,"StoreDeleted"); storeDeletedFile.Write(KMsvIndexStoreDeleted); } storeDeletedFile.Close(); } }
static TDriveUnit writableExeDrive() { TDriveUnit drive = exeDrive(); if(drive.operator TInt() == EDriveZ) return TDriveUnit(EDriveC); return drive; }
//The function constructs a full path in aDestPath argument (from aDriveNumber and aPrivatePath arguments). //aDestPath must point to a big enough place (ideally TFileName object). static void ConstructDestPath(TDriveNumber aDriveNumber, const TDesC& aPrivatePath, TDes& aDestPath) { TDriveName destDriveName = TDriveUnit(aDriveNumber).Name(); TParse parse; parse.Set(aPrivatePath, &destDriveName, 0); aDestPath.Copy(parse.FullName()); }
//The function constructs a full file path in aFullPath argument (from aDriveNumber, aFileName and aPrivatePath arguments). //aFullPath must point to a big enough place (ideally TFileName object). static void ConstructFilePathByName(TDriveNumber aDriveNumber, const TDesC& aFileName, const TDesC& aPrivatePath, TDes& aFullPath) { TDriveName srcDriveName = TDriveUnit(aDriveNumber).Name(); aFullPath.Copy(srcDriveName); aFullPath.Append(aFileName); TParse parse; parse.Set(aPrivatePath, &aFullPath, 0); aFullPath.Copy(parse.FullName()); }
TInt PosixFilesystem::SetDefaultDir (RFs& aFs) { TParse parse; parse.Set(RProcess().FileName(), NULL, NULL); #ifdef __SECURE_DATA__ return aFs.SetSessionToPrivate(TDriveUnit(parse.Drive())); #else return aFs.SetSessionPath(parse.DriveAndPath()); #endif }
void CIniFileManager::GetIniFileNameL(TDes& aFileName, TBool aIncPrivatePath) { if (aIncPrivatePath) { User::LeaveIfError(iFs.PrivatePath(aFileName)); } // Drive name goes before the path. aFileName.Insert(0,TDriveUnit(EDriveC).Name()); // Filename goes after the path. aFileName.Append(KContactsIniFileName); }
void CanonicalizePathname(const TDesC& aName, TInt aDrive, TDes& n, THostFileName& aHostName) { DP(_L("** (SVPHOSTMNT) CanonicalizePathname (%S)"), &aName); n += TDriveUnit(aDrive).Name(); n += aName; TParse parse; parse.Set(n,NULL,NULL); n=parse.FullName(); aHostName.Copy(n); DP(_L("-> (%S)"), &aHostName); }
void CTestStore::SetupL() { _LIT(KFunction, ": Inside SetupL"); INFO_PRINTF1(KFunction); TParse parse; TPtrC drive = TDriveUnit(EDriveC).Name(); parse.Set(KDbFileName, &drive, NULL); TFileName dbFile = parse.FullName(); RSqlDatabase::Delete(dbFile); }
void CSVPHostMountCB::DirOpenL(const TDesC& aName ,CDirCB* aDir) { DP(_L("CFatMountCB::DirOpenL, drv:%d, %S"), DriveNumber(), &aName); CSVPHostDirCB& dir=(*((CSVPHostDirCB*)aDir)); TBuf<KMaxPath> name; TUint driveNumber = Drive().DriveNumber(); CanonicalizePathname(aName, driveNumber, name); TSVPHostFsDirOpenInfo info(driveNumber, name); TInt err = SVP_HOST_FS_DEVICE().DirOpen(info); User::LeaveIfError(err); dir.SetHandle(info.iHandle); TFileName n(TDriveUnit(Drive().DriveNumber()).Name()); n.Append(aName); dir.SetFullName(n); }
/** Restore server-wide settings from the contacts ini file. */ void CIniFileManager::RestoreIniFileSettingsL() { // Initial location for Default database SetDefaultDatabaseDrive(TDriveUnit(EDriveC),EFalse); TFileName iniFile; GetIniFileNameL(iniFile); CDictionaryFileStore* iniStore = IniFileStoreLC(iniFile); // Load settings iCurrentItemMap->RestoreL(*iniStore); iSpeedDialManager->RestoreL(*iniStore); // Current database RestoreCurrentDatabaseL(*iniStore); // Default database location RestoreDefaultDbDriveL(*iniStore); // Tidy up CleanupStack::PopAndDestroy(iniStore); }
int PosixFilesystem::stat (RFs& aFs, const wchar_t* name, struct stat *st, int& anErrno) { TFullName fullName; TInt err=GetFullFile(fullName,(const TText16*)name,aFs); if (!err) { TEntry entry; if (fullName.Length()==3) { entry.iAtt=KEntryAttDir; entry.iModified==TTime(0); } else err=aFs.Entry(fullName,entry); if (!err) { st->st_size = entry.iSize; st->st_dev = st->st_rdev = (dev_t)TDriveUnit(fullName); CFileDesc::MapStat(*st, entry.iModified, entry.iAtt); return 0; } } return MapError(err, anErrno); }
LOCAL_C void TestRemovingAllFilesL() { CDummyObserver ob; CMsvSession* session = CMsvSession::OpenSyncL(ob); CleanupStack::PushL(session); CMsvEntry* cEntry1 = CMsvEntry::NewL(*session, KMsvLocalServiceIndexEntryId, TMsvSelectionOrdering(KMsvNoGrouping, EMsvSortByNone, ETrue)); CleanupStack::PushL(cEntry1); CMsvEntrySelection* selection; CMsvOperation* opert; CTestActive* active = new (ELeave) CTestActive; CleanupStack::PushL(active); CDir* dir; TFileName filename; TInt count; // delete everything under the outbox cEntry1->SetEntryL(KMsvGlobalOutBoxIndexEntryId); selection = cEntry1->ChildrenL(); if (selection->Count()) { active->StartL(); opert = cEntry1->DeleteL(*selection, active->iStatus); CActiveScheduler::Start(); // operation complete delete opert; } delete selection; // delete everything under the inbox cEntry1->SetEntryL(KMsvGlobalInBoxIndexEntryId); selection = cEntry1->ChildrenL(); if (selection->Count()) { active->StartL(); opert = cEntry1->DeleteL(*selection, active->iStatus); CActiveScheduler::Start(); // operation complete delete opert; } delete selection; // delete everything under the draft cEntry1->SetEntryL(KMsvDraftEntryId); selection = cEntry1->ChildrenL(); if (selection->Count()) { active->StartL(); opert = cEntry1->DeleteL(*selection, active->iStatus); CActiveScheduler::Start(); // operation complete delete opert; } delete selection; // delete everything under the sent cEntry1->SetEntryL(KMsvSentEntryId); selection = cEntry1->ChildrenL(); if (selection->Count()) { active->StartL(); opert = cEntry1->DeleteL(*selection, active->iStatus); CActiveScheduler::Start(); // operation complete delete opert; } delete selection; // delete everything under the local service cEntry1->SetEntryL(KMsvLocalServiceIndexEntryId); selection = cEntry1->ChildrenL(); count=selection->Count(); while (count--) { TMsvId id = selection->At(count); #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT) id = UnmaskTMsvId(id); #endif if (id==KMsvGlobalOutBoxIndexEntryId || id==KMsvGlobalInBoxIndexEntryId || id==KMsvDraftEntryId || id==KMsvSentEntryId || id==KMsvDeletedEntryFolderEntryId) selection->Delete(count); } if (selection->Count()) { active->StartL(); opert = cEntry1->DeleteL(*selection, active->iStatus); CActiveScheduler::Start(); // operation complete delete opert; } delete selection; // test cEntry1->SetEntryL(KMsvRootIndexEntryId); cEntry1->SetEntryL(KMsvLocalServiceIndexEntryId); selection = cEntry1->ChildrenL(); test(selection->Count()==5); delete selection; RFs file; file.Connect(); CleanupClosePushL(file); TPtrC driveName = TDriveUnit(MessageServer::CurrentDriveL(file)).Name(); CleanupStack::PopAndDestroy(); file.Close(); filename = driveName; filename.Append(KMsvDefaultFolder2); MsvUtils::ConstructEntryName(KMsvLocalServiceIndexEntryId, KMsvLocalServiceIndexEntryId, filename, MsvUtils::EPath); REPORT_IF_ERROR(theUtils->FileSession().GetDir(filename, KEntryAttMaskSupported, ESortNone, dir)); test(dir->Count()==0); delete dir; // everything under the root cEntry1->SetEntryL(KMsvRootIndexEntryId); selection = cEntry1->ChildrenL(); count=selection->Count(); while (count--) { TMsvId id = selection->At(count); #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT) id = UnmaskTMsvId(id); #endif if (id==KMsvLocalServiceIndexEntryId) selection->Delete(count); } if (selection->Count()) { active->StartL(); opert = cEntry1->DeleteL(*selection, active->iStatus); CActiveScheduler::Start(); // operation complete delete opert; } delete selection; #if (!defined SYMBIAN_MESSAGESTORE_USING_SQLDB) // check corrupt index flag was set when index file was corrupted TBool corrupt=session->GetAndClearIndexCorruptFlagL(); test(corrupt!=EFalse); #endif // test cEntry1->SetEntryL(KMsvLocalServiceIndexEntryId); cEntry1->SetEntryL(KMsvRootIndexEntryId); selection = cEntry1->ChildrenL(); test(selection->Count()==1); delete selection; filename = driveName; filename.Append(KMsvDefaultFolder2); REPORT_IF_ERROR(theUtils->FileSession().GetDir(filename, KEntryAttMaskSupported, ESortNone, dir)); test(dir->Count()==1); //no Index file under Mail2 folder after PREQ1189. delete dir; CleanupStack::PopAndDestroy(3); }
static void TestL() { CHlpFileList* masterList = new(ELeave) CHlpFileList(5); CleanupStack::PushL(masterList); TInt i = EDriveY; FOREVER { // Make sure we go from Y -> C, then do Z last if (i < EDriveC) i = EDriveZ; if (DiskPresent(i)) { { TChar driveLetter = '?'; RFs::DriveToChar(i, driveLetter); TheTest.Printf(_L("\n\nDisk %c: is installed..."), static_cast<TUint>(driveLetter)); } // This generates a list for a specific directory on the specified drive. CHlpFileList* list = BuildListForDriveLC(TDriveUnit(i), TheFs); // We now compare this list with our 'master' list to check for duplicates, // better matches, etc. TInt masterCount = masterList->Count(); for(TInt j=masterCount-1; j>=0; j--) { CHlpFileEntry* entry = masterList->At(j); // This bit checks to see if an entry in the master list // collides with an entry in the list we have just generated... //TBool foundCollision = EFalse; TInt newListCount = list->Count(); for(TInt k=newListCount-1; k>=0; k--) { CHlpFileEntry* newEntry = list->At(k); __PRINT_FILE_NO(_L("Performing drive resolution on entry"), *newEntry, k); if (entry->Name().CompareF(newEntry->Name()) == 0) { // Names are the same, so compare priorities... if (newEntry->Type() == entry->Type()) { // A file with the same name AND extension is already present in the array, // but are the UID's the same? If they are NOT, then the file // should be treated as a different help file to that of the // existing array entry. TFileName file; TEntry existingTEntry; entry->GetFullNameAndPath(file); User::LeaveIfError(TheFs.Entry(file, existingTEntry)); TEntry newTEntry; newEntry->GetFullNameAndPath(file); User::LeaveIfError(TheFs.Entry(file, newTEntry)); if (existingTEntry.MostDerivedUid() == newTEntry.MostDerivedUid()) { // The uids and names of the files are the same. If the extensions are also the same // then we load the file on the drive tending to C:. However, if the extensions differ // we load the file with the extension tending to 01, i.e. UK English. if (entry->FileName().CompareF(newEntry->FileName()) == 0) { // Name, uid and extensions are the same, therefore load the file on the drive // nearest C:. We do this by setting the priority of the existing entry to // EDsicarded so that it will force the next 'if' statement to fire, and hence // the existing entry will be replaced by the new one. entry->SetType(CHlpFileEntry::EDiscarded); __PRINT_FILE(_L("Uid, name, extension match. Saving entry tending to C: which is"), *newEntry); } else { // Name and uid the same, extensions different therefore load the file with // extension nearest to 01. If the new entry is nearer 01, then we set the // existing entry to discarded and therefore it will be removed at the next // 'if' statement. if (entry->HelpFileLocale() > newEntry->HelpFileLocale()) { entry->SetType(CHlpFileEntry::EDiscarded); __PRINT_FILE(_L("Uid & name match, extensions differ.\n Saving entry tending to H01 which is"), *newEntry); } else { __PRINT_FILE(_L("Uid & name match, extensions differ.\n Discarding new entry because it tends to H99"), *newEntry); } } } else { // This entry should be treated as a separate entity from the current // existing entry because it has different uid's. Therefore, we just // move on to check against the next existing entry in the list __PRINT_FILE(_L("Duplicate name and extension, but different uids detected. New entry == "), *newEntry); continue; } } // Is the new entry a better match than the existing one? if (newEntry->Type() < entry->Type()) { // The new entry is of a better 'quality' than the existing // entry, so remove the old and add the new... __PRINT_FILE(_L("Removing stored (new better match found)"), *entry); //foundCollision = ETrue; masterList->Delete(j); delete entry; masterList->AppendL(newEntry); // Remove it from the new list as the master list now takes // ownership... list->Delete(k); break; } else { // This entry is of lower quality than an existing // entry in the master list, so we can safely discard it. delete newEntry; list->Delete(k); } continue; } } } // At this point, anything that is left int the new list should // be valid to add to the master list... TInt newListCount = list->Count(); for(TInt k=newListCount-1; k>=0; k--) { __PRINT_FILE_NO(_L("Saving entry"), *list->At(k), k); masterList->AppendL(list->At(k)); } // We only destroy the list, rather than list+contents because each element // in the new list is now guaranteed to be present in the master list. CleanupStack::PopAndDestroy(); // list } if (i-- == EDriveZ) break; } // Print out the master list TheTest.Printf(_L("\n\nThe help files that would be loaded are:-")); TheTest.Printf(_L("\n=========================================")); TInt masterCount = masterList->Count(); for(i=0; i<masterCount; i++) __PRINT_FILE_NO(_L("Entry"), *masterList->At(i), i); masterList->ResetAndDestroy(); CleanupStack::PopAndDestroy(); // masterList }
LOCAL_C void TestRemovingAllFilesL() { CDummyObserver ob; CMsvSession* session = CMsvSession::OpenSyncL(ob); CleanupStack::PushL(session); CMsvEntry* cEntry1 = CMsvEntry::NewL(*session, KMsvLocalServiceIndexEntryId, TMsvSelectionOrdering(KMsvNoGrouping, EMsvSortByNone, ETrue)); CleanupStack::PushL(cEntry1); CMsvEntrySelection* selection; CMsvOperation* opert; CTestActive* active = new (ELeave) CTestActive; CleanupStack::PushL(active); CDir* dir; TFileName filename; TInt count; // delete everything under the outbox cEntry1->SetEntryL(KMsvGlobalOutBoxIndexEntryId); selection = cEntry1->ChildrenL(); if (selection->Count()) { active->StartL(); opert = cEntry1->DeleteL(*selection, active->iStatus); CActiveScheduler::Start(); // operation complete delete opert; } delete selection; // delete everything under the inbox cEntry1->SetEntryL(KMsvGlobalInBoxIndexEntryId); selection = cEntry1->ChildrenL(); if (selection->Count()) { active->StartL(); opert = cEntry1->DeleteL(*selection, active->iStatus); CActiveScheduler::Start(); // operation complete delete opert; } delete selection; // delete everything under the draft cEntry1->SetEntryL(KMsvDraftEntryId); selection = cEntry1->ChildrenL(); if (selection->Count()) { active->StartL(); opert = cEntry1->DeleteL(*selection, active->iStatus); CActiveScheduler::Start(); // operation complete delete opert; } delete selection; // delete everything under the sent cEntry1->SetEntryL(KMsvSentEntryId); selection = cEntry1->ChildrenL(); if (selection->Count()) { active->StartL(); opert = cEntry1->DeleteL(*selection, active->iStatus); CActiveScheduler::Start(); // operation complete delete opert; } delete selection; // delete everything under the local service cEntry1->SetEntryL(KMsvLocalServiceIndexEntryId); selection = cEntry1->ChildrenL(); count=selection->Count(); while (count--) { TMsvId id = selection->At(count); #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT) id = UnmaskTMsvId(id); #endif if (id==KMsvGlobalOutBoxIndexEntryId || id==KMsvGlobalInBoxIndexEntryId || id==KMsvDraftEntryId || id==KMsvSentEntryId || id==KMsvDeletedEntryFolderEntryId) selection->Delete(count); } if (selection->Count()) { active->StartL(); opert = cEntry1->DeleteL(*selection, active->iStatus); CActiveScheduler::Start(); // operation complete delete opert; } delete selection; // test cEntry1->SetEntryL(KMsvRootIndexEntryId); cEntry1->SetEntryL(KMsvLocalServiceIndexEntryId); selection = cEntry1->ChildrenL(); test(selection->Count()==5); delete selection; TestNumberOfFilesInService(KMsvLocalServiceIndexEntryId,0); // everything under the root cEntry1->SetEntryL(KMsvRootIndexEntryId); selection = cEntry1->ChildrenL(); count=selection->Count(); while (count--) { TMsvId id = selection->At(count); #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT) if (UnmaskTMsvId(id)==KMsvLocalServiceIndexEntryId) #else if (id==KMsvLocalServiceIndexEntryId) #endif selection->Delete(count); } if (selection->Count()) { active->StartL(); opert = cEntry1->DeleteL(*selection, active->iStatus); CActiveScheduler::Start(); // operation complete delete opert; } delete selection; // test cEntry1->SetEntryL(KMsvLocalServiceIndexEntryId); cEntry1->SetEntryL(KMsvRootIndexEntryId); selection = cEntry1->ChildrenL(); test(selection->Count()==1); delete selection; RFs file; file.Connect(); CleanupClosePushL(file); TPtrC driveName = TDriveUnit(MessageServer::CurrentDriveL(file)).Name(); CleanupStack::PopAndDestroy(); file.Close(); filename = driveName; filename.Append(KMsvDefaultFolder2); REPORT_IF_ERROR(theUtils->FileSession().GetDir(filename, KEntryAttMaskSupported, ESortNone, dir)); //Index File Will not be created in case of SQL test(dir->Count()==1); delete dir; CleanupStack::PopAndDestroy(3); }
void CMsvIndexContext::CreateIndexL(TInt aDrive, TBool aSync) { __ASSERT_DEBUG(iProgress.iState == TMsvIndexLoadProgress::EIndexNotLoaded, PanicServer(EMsvBadIndexState)); __ASSERT_DEBUG(RFs::IsValidDrive(aDrive), PanicServer(EMsvInvalidDrive)); // Remember stuff iConfig.iDrive = TDriveUnit(aDrive); iObserverStatus = NULL; iRunMailInit = EFalse; // Set the drive for this index file TParse parse; TPtrC drive(iConfig.iDrive.Name()); parse.Set(KMsvDefaultIndexFile2(), &drive, NULL); // Construct the message folder name etc iMessageFolder = parse.DriveAndPath(); TFileName indexFileName = parse.FullName(); // Adding the new code // Now we are creating the new database adapter. // Find out if the db exists // Construct the db file name parse.Set(KDBFileName, &drive, NULL); TFileName dBFile = parse.FullName(); RSqlDatabase db; TRAPD(err,db.OpenL(dBFile)); TBool create=EFalse; // Database may be corrupted, so delete the old database and create a new one. if(err == KSqlErrCorrupt || err == KSqlErrNotDb ) { RSqlDatabase::Delete(dBFile); create = ETrue; } // Database is not present. We need to check if the store is an old one. // If it is, we check if it is corrupt. // If it is corrupt we can safely delete the store and create a new one // in its place. If not, then we leave with KErrNotSupported stating that // the old store is incompatible with this implementation of the message // store which uses an SQL database for the index. else if( err == KErrNotFound) { // Check if any of the old index files exist in the Mail2 folder. TParse parse1; parse1.Set(KMsvDefaultIndexFile, &drive, NULL); //old version of index file if( BaflUtils::FileExists(iServer.FileSession(), parse1.FullName()) || BaflUtils::FileExists(iServer.FileSession(), indexFileName)) { // Open index store. RFile file; TInt error = file.Open(iServer.FileSession(), indexFileName, EFileShareAny|EFileWrite); // Check if we have an old 'legacy' version of the index file. CPermanentFileStore* index = NULL; TRAPD(permError, index = CPermanentFileStore::FromL(file)); CleanupStack::PushL(index); if (KErrNone == permError) { // Check if the store is corrupt. If so then delete it. if (index->Type() != TUidType(KPermanentFileStoreLayoutUid, KUidMsvIndexFile)) { create = ETrue; } } // There was an error in getting a permanent filestore object. // Delete the message store. else { create = ETrue; } CleanupStack::PopAndDestroy(); //index file.Close(); // If the old store is valid, then throw an error. if(!create) { User::Leave(KErrNotSupported); } } //Index file does not exist in Mail2 folder. Go ahead with database creation. else { create = ETrue; } } else { db.Close(); User::LeaveIfError(err); } db.Close(); if(!create) { // Check for database version. TRAP(err, CMsvDBAdapter::ValidateDatabaseL(dBFile)); User::LeaveIfError(err); iIndexAdapter = CMsvIndexAdapter::OpenL(iServer, dBFile); ResetAndCreateNewMailStoreL(EFalse); } else { iIndexAdapter = CMsvIndexAdapter::NewL(iServer, dBFile); ResetAndCreateNewMailStoreL(); CreateStoreDeleteFile(); iRunMailInit = ETrue; TResourceReader reader; reader.SetBuffer(iBuf); // Read initial entries from resources const TInt numberOfEntries = reader.ReadInt16(); for (TInt index=0; index<numberOfEntries; ++index) { TMsvEntry newEntry; // Values from resource file newEntry.iId = reader.ReadInt32(); newEntry.iParentId = reader.ReadInt32(); newEntry.iServiceId = reader.ReadInt32(); newEntry.iType.iUid = reader.ReadInt32(); newEntry.iMtm.iUid = reader.ReadInt32(); newEntry.iData = reader.ReadInt32(); newEntry.iDescription.Set(reader.ReadTPtrC()); newEntry.iDetails.Set(reader.ReadTPtrC()); newEntry.iDate.UniversalTime(); newEntry.iSize=0; // Create the new entry // This is required to create associated service directory. TInt error = iServer.AddEntry(this, newEntry, KMsvServerId, EFalse); User::LeaveIfError(error); } iIndexAdapter->SetLocalServiceComplete(); } if(aSync) { IndexLoadingCompleted(KErrNone); } else { iStatus = KRequestPending; SetActive(); TRequestStatus* st = &iStatus; User::RequestComplete(st, KErrNone);// do we need to propogate the error from adapter to here } }
/** * DoCreateIndexL() * * Create the index adapter object. * Code added in PREQ 557. */ void CMsvIndexContext::DoCreateIndexL() { // Remember stuff iObserverStatus = NULL; iRunMailInit = EFalse; // Update drive status in preferred drive list. TDriveState driveStatus = EMsvInvalidDriveStatus; for(TUint index=0; index<CMsvPreferredDriveList::GetDriveList()->Count(); index++) { UpdateDriveStatusL(index, driveStatus); } // Look for the current drive. // The first drive in the preferred drive list, whose // status is either EMsvMessageStoreAvailable or // EMsvMessageStoreUnavailable will be the current drive. TMsvPreferredDrive driveEntry; CMsvPreferredDriveList *driveList = CMsvPreferredDriveList::GetDriveList(); for(TInt currentDriveIndex=0; currentDriveIndex<driveList->Count(); ++currentDriveIndex) { driveEntry = (*driveList)[currentDriveIndex]; if( (EMsvMessageStoreAvailableStatus == driveEntry.status) || (EMsvMessageStoreUnavailableStatus == driveEntry.status) ) { // Set the current drive index to server. CMsvPreferredDriveList::GetDriveList()->SetCurrentDriveIndex(currentDriveIndex); TParse parse; TPtrC drive(TDriveUnit(driveEntry.driveNum).Name()); parse.Set(KMsvDefaultIndexFile2(), &drive, NULL); iMessageFolder = parse.DriveAndPath(); // If the drive already has a message store... if(EMsvMessageStoreUnavailableStatus == driveEntry.status) { // Create the database and all standard table. CMsvDBAdapter::CreateDBL(driveEntry.driveNum); // Update the drive status. CMsvPreferredDriveList::GetDriveList()->UpdateDriveStatusL(currentDriveIndex, EMsvMessageStoreAvailableStatus); ResetAndCreateNewMailStoreL(); iRunMailInit = ETrue; // Creating index adapter object. iIndexAdapter = CMsvIndexAdapter::NewL(iServer); // Get updated drive id. CreateStandardEntriesFromResourceFileL(KCurrentDriveId); iIndexAdapter->SetLocalServiceComplete(); } else { // The drive already has a message store. // Creating index adapter object. iIndexAdapter = CMsvIndexAdapter::NewL(iServer); ResetAndCreateNewMailStoreL(EFalse); } break; } } }
/** * UpdateDriveStatusL() * @param TUint: The index of the said drive in preferred * drive list. */ void CMsvIndexContext::UpdateDriveStatusL(TUint aDriveIndex, TDriveState& aStoreStatus) { aStoreStatus = EMsvInvalidDriveStatus; TBool deleteStore = EFalse; TMsvPreferredDrive driveEntry; CMsvPreferredDriveList::GetDriveList()->DriveInfoL(aDriveIndex, driveEntry); // Check if the media is available in the drive. TVolumeInfo volume; if (iServer.FileSession().Volume(volume, driveEntry.driveNum) != KErrNone) { CMsvPreferredDriveList::GetDriveList()->UpdateDriveStatusL(aDriveIndex, EMsvDriveDiskNotAvailableStatus); aStoreStatus = EMsvDriveDiskNotAvailableStatus; return; } // Validate the database. The function opens the database // and check its version and returns appropriate error. TRAPD(err, CMsvDBAdapter::ValidateDatabaseL(driveEntry.driveNum)); // If no error, database is available. if(KErrNone == err) { CMsvPreferredDriveList::GetDriveList()->UpdateDriveStatusL(aDriveIndex, EMsvMessageStoreAvailableStatus); return; } // If the database is not found in the drive. if(KErrNotFound == err) { // Check if index file exists. RFile file; TParse parse; TPtrC drive(TDriveUnit(driveEntry.driveNum).Name()); parse.Set(KMsvDefaultIndexFile2, &drive, NULL); TFileName indexFileName = parse.FullName(); err = file.Open(iServer.FileSession(), indexFileName, EFileShareAny|EFileWrite); //file.Close(); // If index file exists, set drive status to NOT SUPPORTED. if(KErrNone == err) { CPermanentFileStore* fileStoreIndex = NULL; TRAPD(permError, fileStoreIndex = CPermanentFileStore::FromL(file)); if(KErrNone == permError) { // Check if the store is corrupt. If so then delete it. if (fileStoreIndex->Type() != TUidType(KPermanentFileStoreLayoutUid, KUidMsvIndexFile)) { deleteStore = ETrue; } } // There was an error in getting a permanent filestore object. // Mark the message store for deletion. else { deleteStore = ETrue; } delete fileStoreIndex; //If message store is corrupted, wipe it. if(deleteStore) { TFileName mail2Folder = parse.DriveAndPath(); CFileMan* fileMan = CFileMan::NewL(iServer.FileSession()); // Remove the readonly attribute.. (void)fileMan->Attribs(mail2Folder, 0, KEntryAttReadOnly, TTime(0), CFileMan::ERecurse); CleanupStack::PushL(fileMan); //Check if the mailfolder exists.. TBool mail2FolderExists = BaflUtils::FileExists(iServer.FileSession(), mail2Folder); if(mail2FolderExists) { // Remove old message store if exists.. User::LeaveIfError(fileMan->RmDir(mail2Folder)); } CleanupStack::PopAndDestroy(fileMan); CMsvPreferredDriveList::GetDriveList()->UpdateDriveStatusL(aDriveIndex, EMsvMessageStoreUnavailableStatus); aStoreStatus = EMsvMessageStoreCorruptStatus; // Create store delete file in the respective drive. CreateStoreDeleteFile(driveEntry.driveNum); } //Else only set status as EMsvMessageStoreNotSupportedStatus. else { CMsvPreferredDriveList::GetDriveList()->UpdateDriveStatusL(aDriveIndex, EMsvMessageStoreNotSupportedStatus); aStoreStatus = EMsvMessageStoreNotSupportedStatus; } file.Close(); return; } // If index file does not exists, set drive status to STORE UNAVAILABLE. if((KErrNotFound == err) || (KErrPathNotFound == err)) { CMsvPreferredDriveList::GetDriveList()->UpdateDriveStatusL(aDriveIndex, EMsvMessageStoreUnavailableStatus); aStoreStatus = EMsvMessageStoreUnavailableStatus; return; } User::Leave(err); } //If a database exists, but is corrupt. if( (KSqlErrCorrupt == err) || (KSqlErrNotDb == err) ) { // If the database is corrupt, delete // the database and old message store. // Delete the database. TParse parse; TPtrC drive(TDriveUnit(driveEntry.driveNum).Name()); parse.Set(KDBFileName, &drive, NULL); TFileName dBFile = parse.FullName(); RSqlDatabase::Delete(dBFile); // Delete the message store. //ISSUE Can we use ResetAndCreateNewMailStore()? parse.Set(KMsvDefaultIndexFile2, &drive, NULL); TFileName mail2Folder = parse.DriveAndPath(); CFileMan* fileMan = CFileMan::NewL(iServer.FileSession()); // Remove the readonly attribute.. (void)fileMan->Attribs(mail2Folder, 0, KEntryAttReadOnly, TTime(0), CFileMan::ERecurse); CleanupStack::PushL(fileMan); //Check if the mailfolder exists.. TBool mail2FolderExists = BaflUtils::FileExists(iServer.FileSession(), mail2Folder); if( mail2FolderExists) { // Remove old message store if exists.. User::LeaveIfError(fileMan->RmDir(mail2Folder)); } CleanupStack::PopAndDestroy(fileMan); // Update the drive status. CMsvPreferredDriveList::GetDriveList()->UpdateDriveStatusL(aDriveIndex, EMsvMessageStoreUnavailableStatus); aStoreStatus = EMsvMessageStoreCorruptStatus; // Create store delete file in the respective drive. CreateStoreDeleteFile(driveEntry.driveNum); return; } //If the database version is not supported. if(KErrNotSupported == err) { // If the drive as old version of database. CMsvPreferredDriveList::GetDriveList()->UpdateDriveStatusL(aDriveIndex, EMsvMessageStoreNotSupportedStatus); aStoreStatus = EMsvMessageStoreNotSupportedStatus; return; } // Do not return DB error. if(err <= KSqlErrGeneral) { // If DB Error, return KErrGeneral. User::LeaveIfError(KErrGeneral); } else { User::LeaveIfError(err); } }