sl@0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "pccenrepimpl.h"
|
sl@0
|
17 |
|
sl@0
|
18 |
_LIT(KCreExt,".cre");
|
sl@0
|
19 |
_LIT(KTxtExt,".txt");
|
sl@0
|
20 |
_LIT(KOgnExt,".ogn");
|
sl@0
|
21 |
const TInt KExtLength=4;
|
sl@0
|
22 |
const TInt KMinReposFileLength=12;
|
sl@0
|
23 |
|
sl@0
|
24 |
//dummy fail transaction cleanup operation
|
sl@0
|
25 |
void CPcRepImpl::FailTransactionCleanupOperation(TAny* /**aRepository*/)
|
sl@0
|
26 |
{
|
sl@0
|
27 |
//do nothing
|
sl@0
|
28 |
}
|
sl@0
|
29 |
|
sl@0
|
30 |
CPcRepImpl* CPcRepImpl::NewL(TUid aRepositoryUid,const TDesC& aInFileName,const TDesC& aOutFileName,TBool aAutoLoading)
|
sl@0
|
31 |
{
|
sl@0
|
32 |
CPcRepImpl* self=new (ELeave)CPcRepImpl();
|
sl@0
|
33 |
CleanupStack::PushL(self);
|
sl@0
|
34 |
self->ConstructL(aRepositoryUid,aInFileName,aOutFileName,aAutoLoading);
|
sl@0
|
35 |
CleanupStack::Pop();
|
sl@0
|
36 |
return self;
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
void CPcRepImpl::ConstructL(TUid aRepositoryUid,const TDesC& aInFileName,const TDesC& aOutFileName,TBool aAutoLoading)
|
sl@0
|
40 |
{
|
sl@0
|
41 |
User::LeaveIfError(iFs.Connect());
|
sl@0
|
42 |
iRepository=CHeapRepository::NewL(aRepositoryUid);
|
sl@0
|
43 |
|
sl@0
|
44 |
TFileName ognFile; // XXXXXXXX.ogn
|
sl@0
|
45 |
TBool isOriginal;
|
sl@0
|
46 |
|
sl@0
|
47 |
IsOriginalL(aRepositoryUid, aOutFileName, aAutoLoading, ognFile, isOriginal);
|
sl@0
|
48 |
iRepository->SettingsArray().SetIsDefault(isOriginal);
|
sl@0
|
49 |
if (!aAutoLoading)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
//verify file name must be in format of XXXXXXXX.<cre/txt> that is minimum length is 8+1+3=12
|
sl@0
|
52 |
if (aInFileName.Length()<KMinReposFileLength || aOutFileName.Length()<KMinReposFileLength)
|
sl@0
|
53 |
User::Leave(KErrArgument);
|
sl@0
|
54 |
//verify it is in the format of <path>XXXXXXXX.<cre/txt>
|
sl@0
|
55 |
TPtrC inFileName(aInFileName.Right(KMinReposFileLength));
|
sl@0
|
56 |
TPtrC outFileName(aOutFileName.Right(KMinReposFileLength));
|
sl@0
|
57 |
TUint inRepUid;
|
sl@0
|
58 |
TLex parser(inFileName.Left(8));
|
sl@0
|
59 |
TInt ret=parser.Val(inRepUid,EHex);
|
sl@0
|
60 |
if (ret!=KErrNone)
|
sl@0
|
61 |
(ret==KErrNoMemory)?User::Leave(ret):User::Leave(KErrArgument);
|
sl@0
|
62 |
parser.Assign(outFileName.Left(8));
|
sl@0
|
63 |
TUint outRepUid;
|
sl@0
|
64 |
ret=parser.Val(outRepUid,EHex);
|
sl@0
|
65 |
if (ret!=KErrNone)
|
sl@0
|
66 |
(ret==KErrNoMemory)?User::Leave(ret):User::Leave(KErrArgument);
|
sl@0
|
67 |
|
sl@0
|
68 |
//now finally verify the extension of the output file
|
sl@0
|
69 |
if (aOutFileName.Right(KExtLength).CompareF(KCreExt())!=0)
|
sl@0
|
70 |
User::Leave(KErrArgument);
|
sl@0
|
71 |
if (aInFileName.Right(KExtLength).CompareF(KTxtExt())==0)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
iRepository->SetUid(TUid::Uid(inRepUid));
|
sl@0
|
74 |
CIniFileIn* iniFile=NULL;
|
sl@0
|
75 |
ret=CIniFileIn::NewLC(iFs,iniFile,aInFileName);
|
sl@0
|
76 |
User::LeaveIfError(ret);
|
sl@0
|
77 |
iRepository->ReloadContentL(*iniFile);
|
sl@0
|
78 |
CleanupStack::PopAndDestroy();
|
sl@0
|
79 |
}
|
sl@0
|
80 |
else if (aInFileName.Right(KExtLength).CompareF(KCreExt())==0)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
iRepository->SetUid(TUid::Uid(inRepUid));
|
sl@0
|
83 |
iRepository->CreateRepositoryFromCreFileL(iFs,aInFileName);
|
sl@0
|
84 |
}
|
sl@0
|
85 |
else
|
sl@0
|
86 |
User::Leave(KErrArgument);
|
sl@0
|
87 |
iOutFileName=aOutFileName.AllocL();
|
sl@0
|
88 |
}
|
sl@0
|
89 |
else
|
sl@0
|
90 |
{
|
sl@0
|
91 |
//auto mode look for CRE first then TXT
|
sl@0
|
92 |
TFileName crefile;
|
sl@0
|
93 |
crefile.AppendNumFixedWidth(aRepositoryUid.iUid,EHex,8);
|
sl@0
|
94 |
crefile.Append(KCreExt());
|
sl@0
|
95 |
TInt ret=KErrNone;
|
sl@0
|
96 |
TRAP(ret,iRepository->CreateRepositoryFromCreFileL(iFs,crefile));
|
sl@0
|
97 |
if (ret!=KErrNone)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
if (ret!=KErrNotFound)
|
sl@0
|
100 |
User::Leave(ret);
|
sl@0
|
101 |
//look for TXT now
|
sl@0
|
102 |
TFileName file;
|
sl@0
|
103 |
file.AppendNumFixedWidth(aRepositoryUid.iUid,EHex,8);
|
sl@0
|
104 |
file.Append(KTxtExt());
|
sl@0
|
105 |
CIniFileIn* iniFile=NULL;
|
sl@0
|
106 |
ret=CIniFileIn::NewLC(iFs,iniFile,file);
|
sl@0
|
107 |
User::LeaveIfError(ret);
|
sl@0
|
108 |
iRepository->ReloadContentL(*iniFile);
|
sl@0
|
109 |
CleanupStack::PopAndDestroy();
|
sl@0
|
110 |
}
|
sl@0
|
111 |
//output is always cre
|
sl@0
|
112 |
iOutFileName=crefile.AllocL();
|
sl@0
|
113 |
}
|
sl@0
|
114 |
GetSingleMetaArrayL(iSingleMetaArray);
|
sl@0
|
115 |
if (isOriginal)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
// An empty file is generated in the name of <Repository Uid>.ogn when
|
sl@0
|
118 |
// the repository is loaded for the first time. see IsOriginalL().
|
sl@0
|
119 |
RFile file;
|
sl@0
|
120 |
User::LeaveIfError(file.Create(iFs, ognFile, EFileWrite));
|
sl@0
|
121 |
file.Close();
|
sl@0
|
122 |
}
|
sl@0
|
123 |
iInitialised=ETrue;
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|
sl@0
|
126 |
CPcRepImpl::~CPcRepImpl()
|
sl@0
|
127 |
{
|
sl@0
|
128 |
/** persist to cre on destructor */
|
sl@0
|
129 |
if (iRepository && iInitialised)
|
sl@0
|
130 |
Flush();
|
sl@0
|
131 |
|
sl@0
|
132 |
iFs.Close();
|
sl@0
|
133 |
iSingleMetaArray.Close();
|
sl@0
|
134 |
delete iRepository;
|
sl@0
|
135 |
delete iOutFileName;
|
sl@0
|
136 |
}
|
sl@0
|
137 |
|
sl@0
|
138 |
TInt CPcRepImpl::Flush()
|
sl@0
|
139 |
{
|
sl@0
|
140 |
#ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
|
sl@0
|
141 |
return iRepository->CommitChanges(iFs,KPersistFormatSupportsIndMetaIndicator,*iOutFileName);
|
sl@0
|
142 |
#else
|
sl@0
|
143 |
return iRepository->CommitChanges(iFs,KPersistFormatVersion,*iOutFileName);
|
sl@0
|
144 |
#endif
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|
sl@0
|
147 |
void CPcRepImpl::MoveL(TUint32 aSourcePartialKey, TUint32 aTargetPartialKey,TUint32 aMask, TUint32& aErrorKey)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
RSettingPointerArray sourceSettings;
|
sl@0
|
150 |
CleanupClosePushL(sourceSettings);
|
sl@0
|
151 |
TInt error=iRepository->SettingsArray().Find(aSourcePartialKey & aMask, aMask, sourceSettings);
|
sl@0
|
152 |
|
sl@0
|
153 |
//dont fail transaction if source settings is empty
|
sl@0
|
154 |
if (error!=KErrNone)
|
sl@0
|
155 |
{
|
sl@0
|
156 |
aErrorKey = aSourcePartialKey;
|
sl@0
|
157 |
User::Leave(error);
|
sl@0
|
158 |
}
|
sl@0
|
159 |
else if (sourceSettings.Count() == 0)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
aErrorKey = aSourcePartialKey;
|
sl@0
|
162 |
User::Leave(KErrNotFound);
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
for (TInt i=0;i<sourceSettings.Count();i++)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
TServerSetting* ts=sourceSettings[i];
|
sl@0
|
168 |
TUint32 sourceKey = ts->Key();
|
sl@0
|
169 |
TUint32 targetKey = sourceKey ^ ((aSourcePartialKey & aMask) ^ (aTargetPartialKey & aMask));
|
sl@0
|
170 |
TServerSetting* targetSetting = GetSetting(targetKey);
|
sl@0
|
171 |
if (targetSetting && !targetSetting->IsDeleted())
|
sl@0
|
172 |
{
|
sl@0
|
173 |
aErrorKey=targetKey;
|
sl@0
|
174 |
User::Leave(KErrAlreadyExists);
|
sl@0
|
175 |
}
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
TRAPD(err,error = MOperationLogic::MoveL(aSourcePartialKey,aTargetPartialKey,aMask,aErrorKey, sourceSettings));
|
sl@0
|
179 |
|
sl@0
|
180 |
//the Move operation logic only mark it as deleted, now remove it from the settings list
|
sl@0
|
181 |
RemoveAnyMarkDeleted();
|
sl@0
|
182 |
|
sl@0
|
183 |
User::LeaveIfError(err);
|
sl@0
|
184 |
User::LeaveIfError(error);
|
sl@0
|
185 |
|
sl@0
|
186 |
CleanupStack::PopAndDestroy(&sourceSettings);
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
void CPcRepImpl::DeleteRangeL(TUint32 aPartialKey, TUint32 aMask,TUint32& aErrorKey)
|
sl@0
|
190 |
{
|
sl@0
|
191 |
RSettingPointerArray sourceSettings;
|
sl@0
|
192 |
CleanupClosePushL(sourceSettings);
|
sl@0
|
193 |
TInt error=FindSettings(aPartialKey & aMask, aMask, sourceSettings);
|
sl@0
|
194 |
if (error==KErrNotFound)
|
sl@0
|
195 |
{
|
sl@0
|
196 |
aErrorKey=aPartialKey;
|
sl@0
|
197 |
}
|
sl@0
|
198 |
User::LeaveIfError(error);
|
sl@0
|
199 |
DeleteSettingsRangeL(sourceSettings,aPartialKey,aErrorKey);
|
sl@0
|
200 |
RemoveAnyMarkDeleted();
|
sl@0
|
201 |
CleanupStack::PopAndDestroy(&sourceSettings);
|
sl@0
|
202 |
}
|
sl@0
|
203 |
|
sl@0
|
204 |
void CPcRepImpl::GetSingleMetaArrayL(RSingleMetaArray& aMetaArray)
|
sl@0
|
205 |
{
|
sl@0
|
206 |
TInt numSettings = iRepository->SettingsArray().Count();
|
sl@0
|
207 |
aMetaArray.Reset();
|
sl@0
|
208 |
aMetaArray.ReserveL(numSettings);
|
sl@0
|
209 |
for (TInt i = 0; i < numSettings; i++)
|
sl@0
|
210 |
{
|
sl@0
|
211 |
TUint32 key = iRepository->SettingsArray()[i].Key();
|
sl@0
|
212 |
TUint32 meta = iRepository->SettingsArray()[i].Meta();
|
sl@0
|
213 |
TSettingSingleMeta metaItem(key, meta);
|
sl@0
|
214 |
aMetaArray.AppendL(metaItem);
|
sl@0
|
215 |
}
|
sl@0
|
216 |
}
|
sl@0
|
217 |
|
sl@0
|
218 |
// This function is used to identify wether the repository is loaded for the first
|
sl@0
|
219 |
// time or not. The purpose of this function is to determine whether entries of a
|
sl@0
|
220 |
// repository should be set clean during initializing process. At symbian side, this
|
sl@0
|
221 |
// flag is only set when load from ROM, but at PC side, there is no ROM, so the clean
|
sl@0
|
222 |
// flag is set when load for the first time to keep consistency with Symbian side Library.
|
sl@0
|
223 |
void CPcRepImpl::IsOriginalL(TUid aUid, const TDesC& aOutFile, TBool aAutoLoading, TFileName& aOgnFileName, TBool& aIsOriginal)
|
sl@0
|
224 |
{
|
sl@0
|
225 |
if (!aAutoLoading)
|
sl@0
|
226 |
{
|
sl@0
|
227 |
TInt len = aOutFile.Length();
|
sl@0
|
228 |
aOgnFileName = aOutFile.Left(len - KExtLength);
|
sl@0
|
229 |
}
|
sl@0
|
230 |
else
|
sl@0
|
231 |
{
|
sl@0
|
232 |
aOgnFileName.AppendNumFixedWidth(aUid.iUid,EHex,8);
|
sl@0
|
233 |
}
|
sl@0
|
234 |
aOgnFileName.Append(KOgnExt());
|
sl@0
|
235 |
|
sl@0
|
236 |
RFile file;
|
sl@0
|
237 |
TInt err = file.Open(iFs,aOgnFileName,EFileRead|EFileShareReadersOnly);
|
sl@0
|
238 |
file.Close();
|
sl@0
|
239 |
if (err != KErrNone)
|
sl@0
|
240 |
{
|
sl@0
|
241 |
if (err == KErrNotFound || err == KErrPathNotFound)
|
sl@0
|
242 |
{
|
sl@0
|
243 |
aIsOriginal = ETrue;
|
sl@0
|
244 |
return;
|
sl@0
|
245 |
}
|
sl@0
|
246 |
else
|
sl@0
|
247 |
User::Leave(err);
|
sl@0
|
248 |
}
|
sl@0
|
249 |
aIsOriginal = EFalse;
|
sl@0
|
250 |
}
|