Symbian下ini文件操作

 

Symbian下ini文件的操作

程序中的一些配置信息,可以利用ini文件存储。同时存储到安装程序的私有路径下面。

 

_LIT(KtxDicFileName ,"settings.ini" );

 

const TInt KRegistrar = 2;

const TInt KUsername = 3;

const TInt KPassword = 4;

 

 

//读取 void LoadSettingValuesL() { // load values into iSettings TFileName path; TFileName pathWithoutDrive; CEikonEnv::Static()->FsSession().PrivatePath(pathWithoutDrive); // Extract drive letter into appDrive: #ifdef __WINS__ path.Copy(_L("c:")); #else RProcess process; path.Copy( process.FileName().Left(2) ); #endif path.Append(pathWithoutDrive); path.Append(KtxDicFileName); // Open the dictionary store CDictionaryStore* aDictstore = CDictionaryFileStore::OpenLC( CCoeEnv::Static()->FsSession(), path, TUid::Uid(0x0001)); //TUid::Uid(0x0001) ini文件标识 RDictionaryReadStream in; in.OpenLC(*aDictstore, TUid::Uid(KUsername)); TBuf16<100> aLockedString; aLockedString.Delete(0, aLockedString.Length()); in >> aLockedString; CleanupStack::PopAndDestroy(); CleanupStack::PopAndDestroy(1);// aDictstore CAknInformationNote* note = new (ELeave) CAknInformationNote; note->ExecuteLD(aLockedString); return EFalse; }  

 

//存储 void SaveSettingValuesL() { // store values from iSettings TFileName path; TFileName pathWithoutDrive; CEikonEnv::Static()->FsSession().PrivatePath(pathWithoutDrive); // Extract drive letter into appDrive: #ifdef __WINS__ path.Copy(_L("c:")); #else RProcess process; path.Copy( process.FileName().Left(2) ); if(path.Compare(_L("c")) || path.Compare(_L("C"))) CEikonEnv::Static()->FsSession().CreatePrivatePath(EDriveC); else if(path.Compare(_L("e")) || path.Compare(_L("E"))) CEikonEnv::Static()->FsSession().CreatePrivatePath(EDriveE); #endif path.Append(pathWithoutDrive); path.Append(KtxDicFileName); CDictionaryStore* aDictStore = CDictionaryFileStore::OpenLC( CCoeEnv::Static()->FsSession(), path, TUid::Uid(0x0001)); RDictionaryWriteStream out; out.AssignLC(*aDictStore, TUid::Uid(KRegistrar)); _LIT( KLOOCKED, "maria" ); out << KLOOCKED(); out.CommitL(); CleanupStack::PopAndDestroy(); RDictionaryWriteStream out2; out2.AssignLC(*aDictStore, TUid::Uid(KUsername)); _LIT( KLOOCKED2, "zhang" ); out2 << KLOOCKED2(); out2.CommitL(); CleanupStack::PopAndDestroy(); aDictStore->CommitL(); CleanupStack::PopAndDestroy(aDictStore); } 

 

一些数据通过流方式的读取 
// String
TBuf<100> iText;
aStream >> iText;
 
// Integer
TInt iVolume;
iVolume = aStream.ReadInt32L();
 
// Boolean
TBool iBinary;
iBinary = aStream.ReadInt16L();
 
// Ip address
TInetAddr iIpAddress;
iIpAddress.SetAddress(aStream.ReadUint32L());
 
// Time
TTime iTime;
TInt64 time;
aStream >> time;
iTime = TTime(time);

 

你可能感兴趣的:(Integer,存储,ini,Path,Symbian,Dictionary)