char* CAppConfig::LoadGameL(midend *aME, const game *aGame) { TPtrC8 name((const TUint8*)aGame->name); RDbTable table; TDbSeekKey seekKey(name); char *errmsg = ""; User::LeaveIfError(table.Open(iDb, KAutosaveTable, table.EReadOnly)); CleanupClosePushL(table); User::LeaveIfError(table.SetIndex(KAutosaveIndex)); CDbColSet* colSet = table.ColSetL(); CleanupStack::PushL(colSet); TInt saveColNo = colSet->ColNo(KAutosaveSaveCol); if (table.SeekL(seekKey)) { table.GetL(); RDbColReadStream stream; stream.OpenLC(table,saveColNo); errmsg = midend_deserialise(aME, read_game, &stream); CleanupStack::PopAndDestroy(&stream); } CleanupStack::PopAndDestroy(colSet); CleanupStack::PopAndDestroy(&table); return errmsg; }
void CAppConfig::GetConfigL(const TDesC &aKey, const TConfig &aConfig) { RDbTable table; TDbSeekKey seekKey(aKey); User::LeaveIfError(table.Open(iDb, KConfigTable, table.EReadOnly)); CleanupClosePushL(table); User::LeaveIfError(table.SetIndex(KConfigIndex)); CDbColSet* colSet = table.ColSetL(); CleanupStack::PushL(colSet); TInt valueColNo = colSet->ColNo(KConfigValueCol); if (table.SeekL(seekKey)) { table.GetL(); TPtrC value = table.ColDes(valueColNo); switch (aConfig.iType) { case EConfigBool: *aConfig.iValue.iBool = value.Compare(KBoolTrue) == 0 ? ETrue : EFalse; break; case EConfigInt: { TLex lex(value); TInt lvalue; if (lex.Val(lvalue) == KErrNone) { *aConfig.iValue.iInt = lvalue; } break; } case EConfigText: if (aConfig.iValue.iText->MaxLength() > value.Length()) { aConfig.iValue.iText->Copy(value.Left(aConfig.iValue.iText->MaxLength())); } else { aConfig.iValue.iText->Copy(value); } break; case EConfigText8: if (aConfig.iValue.iText8->MaxLength() > value.Length()) { aConfig.iValue.iText8->Copy(value.Left(aConfig.iValue.iText8->MaxLength())); } else { aConfig.iValue.iText8->Copy(value); } break; } } CleanupStack::PopAndDestroy(colSet); CleanupStack::PopAndDestroy(&table); }
void CAppConfig::SetConfigL(const TDesC &aKey, const TConfig &aConfig) { TBuf<KConfigValueMaxLength> value; switch (aConfig.iType) { case EConfigBool: if (*aConfig.iValue.iBool) { value.Copy(KBoolTrue); } else { value.Copy(KBoolFalse); } break; case EConfigInt: value.Num(*aConfig.iValue.iInt); break; case EConfigText: value.Copy(*aConfig.iValue.iText); break; case EConfigText8: value.Copy(*aConfig.iValue.iText8); break; } RDbTable table; TDbSeekKey seekKey(aKey); User::LeaveIfError(table.Open(iDb, KConfigTable, table.EUpdatable)); CleanupClosePushL(table); User::LeaveIfError(table.SetIndex(KConfigIndex)); CDbColSet* colSet = table.ColSetL(); CleanupStack::PushL(colSet); TInt keyColNo = colSet->ColNo(KConfigKeyCol); TInt valueColNo = colSet->ColNo(KConfigValueCol); if (table.SeekL(seekKey)) { table.GetL(); table.UpdateL(); table.SetColL(valueColNo, value); } else { table.InsertL(); table.SetColL(keyColNo, aKey); table.SetColL(valueColNo, value); } table.PutL(); CleanupStack::PopAndDestroy(colSet); CleanupStack::PopAndDestroy(&table); }
void CAppConfig::SaveGameL(midend *aME, const game *aGame) { TPtrC8 name((const TUint8*)aGame->name); RDbTable table; TDbSeekKey seekKey(name); User::LeaveIfError(table.Open(iDb, KAutosaveTable, table.EUpdatable)); CleanupClosePushL(table); User::LeaveIfError(table.SetIndex(KAutosaveIndex)); CDbColSet* colSet = table.ColSetL(); CleanupStack::PushL(colSet); TInt nameColNo = colSet->ColNo(KAutosaveNameCol); TInt saveColNo = colSet->ColNo(KAutosaveSaveCol); TInt dateColNo = colSet->ColNo(KAutosaveDateCol); if (table.SeekL(seekKey)) { table.GetL(); table.UpdateL(); } else { table.InsertL(); table.SetColL(nameColNo, name); } TTime now; now.HomeTime(); table.SetColL(dateColNo, now); RDbColWriteStream stream; stream.OpenL(table, saveColNo); CleanupClosePushL(stream); midend_serialise(aME, save_game, &stream); CleanupStack::PopAndDestroy(&stream); table.PutL(); CleanupStack::PopAndDestroy(colSet); CleanupStack::PopAndDestroy(&table); iDb.Compact(); }