sl@0
|
1 |
// Copyright (c) 2005-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 <e32const.h>
|
sl@0
|
17 |
#include <e32debug.h>
|
sl@0
|
18 |
#include <bautils.h>
|
sl@0
|
19 |
#include <s32file.h>
|
sl@0
|
20 |
#include "CentRepConvTool.h"
|
sl@0
|
21 |
#include "shrepos.h"
|
sl@0
|
22 |
#include "inifile.h"
|
sl@0
|
23 |
#include "srvres.h"
|
sl@0
|
24 |
#include "srvparams.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
|
sl@0
|
27 |
_LIT(KCentRepConvTool, "CentRep Conversion Tool:");
|
sl@0
|
28 |
|
sl@0
|
29 |
const TInt KNumDigitsInUID = 8;
|
sl@0
|
30 |
|
sl@0
|
31 |
//
|
sl@0
|
32 |
// factory method
|
sl@0
|
33 |
CCentRepConvTool* CCentRepConvTool::NewL(const TDesC& aCmd, RFs& aFs, TBool aWaitForAck)
|
sl@0
|
34 |
{
|
sl@0
|
35 |
CCentRepConvTool* self = new(ELeave) CCentRepConvTool(aCmd, aFs);
|
sl@0
|
36 |
CleanupStack::PushL(self);
|
sl@0
|
37 |
self->ConstructL(aWaitForAck);
|
sl@0
|
38 |
CleanupStack::Pop(self);
|
sl@0
|
39 |
return self;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
//
|
sl@0
|
43 |
// Constructor
|
sl@0
|
44 |
CCentRepConvTool::CCentRepConvTool(const TDesC& aCmd, RFs& aFs)
|
sl@0
|
45 |
: iCmd(aCmd), iFs(aFs), iTextToBin(ETrue), iRepUid(KNullUid),
|
sl@0
|
46 |
iMyDataCage(KNullDesC), iDefaultPath(KNullDesC)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
//
|
sl@0
|
51 |
// two phase construct
|
sl@0
|
52 |
void CCentRepConvTool::ConstructL(TBool aWaitForAck)
|
sl@0
|
53 |
{
|
sl@0
|
54 |
iScrnOutput = CConsolePrint::NewL(aWaitForAck);
|
sl@0
|
55 |
iFs.PrivatePath(iMyDataCage);
|
sl@0
|
56 |
|
sl@0
|
57 |
// set default I/O path
|
sl@0
|
58 |
_LIT(KDefaultPathMask, "_:\\");
|
sl@0
|
59 |
iDefaultPath.Copy(KDefaultPathMask);
|
sl@0
|
60 |
iDefaultPath[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
//
|
sl@0
|
64 |
// destructor
|
sl@0
|
65 |
CCentRepConvTool::~CCentRepConvTool()
|
sl@0
|
66 |
{
|
sl@0
|
67 |
delete iScrnOutput;
|
sl@0
|
68 |
delete iCentRepShrepos;
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
//
|
sl@0
|
72 |
// setter
|
sl@0
|
73 |
void CCentRepConvTool::SetOutputMode(TBool aWaitForAck)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
iScrnOutput->SetWaitMode(aWaitForAck);
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
//
|
sl@0
|
79 |
// Extract input and output path from cmd line, determine text to
|
sl@0
|
80 |
// binary or binary to text, and invoke code in CentRep server classes
|
sl@0
|
81 |
// to do conversion.
|
sl@0
|
82 |
void CCentRepConvTool::ProcessCmdL()
|
sl@0
|
83 |
{
|
sl@0
|
84 |
_LIT(KSuccessMsg,"Output saved as: %S\r\n");
|
sl@0
|
85 |
|
sl@0
|
86 |
TPtrC inputPath(KNullDesC);
|
sl@0
|
87 |
TPtrC outputPath(KNullDesC);
|
sl@0
|
88 |
ParseCmdLineL(inputPath, outputPath);
|
sl@0
|
89 |
|
sl@0
|
90 |
// default input & output path is system drive root folder
|
sl@0
|
91 |
|
sl@0
|
92 |
iInputPath.Set(inputPath, NULL, NULL);
|
sl@0
|
93 |
if (!iInputPath.DrivePresent() && !iInputPath.PathPresent())
|
sl@0
|
94 |
{
|
sl@0
|
95 |
iInputPath.Set(inputPath, NULL, &iDefaultPath);
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
iOutputPath.Set(outputPath, NULL, NULL);
|
sl@0
|
99 |
if (!iOutputPath.DrivePresent() && !iOutputPath.PathPresent())
|
sl@0
|
100 |
{
|
sl@0
|
101 |
iOutputPath.Set(outputPath, NULL, &iDefaultPath);
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
// VerifyInputPathL must be call before VerifyOutputPathL!
|
sl@0
|
105 |
VerifyInputPathL();
|
sl@0
|
106 |
VerifyOutputPathL();
|
sl@0
|
107 |
|
sl@0
|
108 |
// Get UID from input filename
|
sl@0
|
109 |
TLex lex(iInputPath.Name());
|
sl@0
|
110 |
TUint32 intvalue;
|
sl@0
|
111 |
lex.Val(intvalue, EHex);
|
sl@0
|
112 |
iRepUid.iUid = intvalue;
|
sl@0
|
113 |
|
sl@0
|
114 |
TRAPD(err, DoConversionL());
|
sl@0
|
115 |
if (err != KErrNone)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
if (err == KErrCorrupt)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
_LIT(KCorruptError, "Input file contains corrupted entries.\r\n");
|
sl@0
|
120 |
RDebug::Print(KCentRepConvTool);
|
sl@0
|
121 |
RDebug::Print(KCorruptError);
|
sl@0
|
122 |
iScrnOutput->Printf(KCorruptError);
|
sl@0
|
123 |
}
|
sl@0
|
124 |
User::Leave(err);
|
sl@0
|
125 |
}
|
sl@0
|
126 |
|
sl@0
|
127 |
// Success
|
sl@0
|
128 |
iScrnOutput->Printf(KSuccessMsg, &(iOutputPath.FullName()));
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
//
|
sl@0
|
132 |
void CCentRepConvTool::DoConversionL()
|
sl@0
|
133 |
{
|
sl@0
|
134 |
iCentRepShrepos = CSharedRepository::NewL(iRepUid);
|
sl@0
|
135 |
|
sl@0
|
136 |
if (iTextToBin)
|
sl@0
|
137 |
{
|
sl@0
|
138 |
HBufC* tempIniFileName = iInputPath.FullName().AllocLC();
|
sl@0
|
139 |
CIniFileIn* iniFile = NULL;
|
sl@0
|
140 |
TInt ret=CIniFileIn::NewLC(iFs,iniFile,*tempIniFileName);
|
sl@0
|
141 |
if (ret==KErrCorrupt)
|
sl@0
|
142 |
User::LeaveIfError(iFs.Delete(*tempIniFileName));
|
sl@0
|
143 |
User::LeaveIfError(ret);
|
sl@0
|
144 |
User::LeaveIfError(iCentRepShrepos->ReloadContentL(*iniFile));
|
sl@0
|
145 |
CleanupStack::PopAndDestroy(2); // tempIniFileName, iniFile
|
sl@0
|
146 |
ExternalizeToCreL();
|
sl@0
|
147 |
}
|
sl@0
|
148 |
else
|
sl@0
|
149 |
{
|
sl@0
|
150 |
CDirectFileStore* store = CDirectFileStore::OpenLC(iFs,
|
sl@0
|
151 |
iInputPath.FullName(), EFileRead|EFileShareReadersOnly);
|
sl@0
|
152 |
if (store->Type()[0] != KDirectFileStoreLayoutUid)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
CleanupStack::PopAndDestroy(store);
|
sl@0
|
155 |
User::Leave(KErrCorrupt);
|
sl@0
|
156 |
}
|
sl@0
|
157 |
|
sl@0
|
158 |
// Get the root stream and attempt to read the index from it
|
sl@0
|
159 |
TStreamId rootStreamId = store->Root() ;
|
sl@0
|
160 |
RStoreReadStream rootStream ;
|
sl@0
|
161 |
rootStream.OpenLC(*store, rootStreamId);
|
sl@0
|
162 |
// Internalize the repository
|
sl@0
|
163 |
#ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
|
sl@0
|
164 |
TUint8 creVersion;
|
sl@0
|
165 |
#endif
|
sl@0
|
166 |
iCentRepShrepos->InternalizeCreL(rootStream
|
sl@0
|
167 |
#ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
|
sl@0
|
168 |
,creVersion
|
sl@0
|
169 |
#endif
|
sl@0
|
170 |
);
|
sl@0
|
171 |
CleanupStack::PopAndDestroy(&rootStream);
|
sl@0
|
172 |
CleanupStack::PopAndDestroy(store);
|
sl@0
|
173 |
|
sl@0
|
174 |
iCentRepShrepos->DoCommitChangesToIniFileL(iOutputPath.FullName()
|
sl@0
|
175 |
#ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
|
sl@0
|
176 |
,creVersion
|
sl@0
|
177 |
#endif
|
sl@0
|
178 |
);
|
sl@0
|
179 |
}
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
//
|
sl@0
|
183 |
// Extract input path and output path from cmd line
|
sl@0
|
184 |
void CCentRepConvTool::ParseCmdLineL(TPtrC& aInputPath, TPtrC& aOutputPath)
|
sl@0
|
185 |
{
|
sl@0
|
186 |
_LIT(KNoWaitSwitch, "-nowait");
|
sl@0
|
187 |
_LIT(KOutpathSwitch, "-o");
|
sl@0
|
188 |
_LIT(KHelpSwitch, "-h");
|
sl@0
|
189 |
_LIT(KBadArg, "Bad input arguments: %S\r\nUsage: CentRepConv [-o output_path] [input_path\\]<repositoryUID>.txt\r\n");
|
sl@0
|
190 |
_LIT(KHelpMsg, "Usage: CentRepConv [-o output_path] [input_path\\]<repositoryUID>.txt\r\nDefault output_path=%S\r\nDefault input_path=%S\r\n");
|
sl@0
|
191 |
|
sl@0
|
192 |
const TInt KMaxNumTokens = 8; // Arbitrary. only expect 4.
|
sl@0
|
193 |
TPtrC tokens[KMaxNumTokens];
|
sl@0
|
194 |
TLex lex(iCmd);
|
sl@0
|
195 |
TInt i;
|
sl@0
|
196 |
for (i = 0; !lex.Eos() && i < KMaxNumTokens; i++)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
tokens[i].Set(lex.NextToken());
|
sl@0
|
199 |
}
|
sl@0
|
200 |
|
sl@0
|
201 |
TInt numTokens = i;
|
sl@0
|
202 |
|
sl@0
|
203 |
// Expect: [-nowait] [-o output_path] [input_path\]<rep_UID>.txt
|
sl@0
|
204 |
for (i = 0; i < numTokens; i++)
|
sl@0
|
205 |
{
|
sl@0
|
206 |
if (tokens[i].CompareF(KOutpathSwitch) == 0)
|
sl@0
|
207 |
{
|
sl@0
|
208 |
// Got the -o switch.
|
sl@0
|
209 |
if ((i+2) < numTokens)
|
sl@0
|
210 |
{
|
sl@0
|
211 |
aOutputPath.Set(tokens[i+1]);
|
sl@0
|
212 |
aInputPath.Set(tokens[i+2]);
|
sl@0
|
213 |
}
|
sl@0
|
214 |
break;
|
sl@0
|
215 |
} // tokens[i] == "-o"
|
sl@0
|
216 |
else if (tokens[i].CompareF(KNoWaitSwitch) == 0)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
SetOutputMode(EFalse);
|
sl@0
|
219 |
continue;
|
sl@0
|
220 |
}
|
sl@0
|
221 |
else if (tokens[i].FindF(KHelpSwitch) == 0)
|
sl@0
|
222 |
{
|
sl@0
|
223 |
numTokens = 0; // indicator for help message
|
sl@0
|
224 |
break;
|
sl@0
|
225 |
}
|
sl@0
|
226 |
else if ('-' == tokens[i][0])
|
sl@0
|
227 |
{
|
sl@0
|
228 |
continue; // unknown switch, assume intended for system
|
sl@0
|
229 |
}
|
sl@0
|
230 |
|
sl@0
|
231 |
// No options. Token must be input file name.
|
sl@0
|
232 |
aInputPath.Set(tokens[i]);
|
sl@0
|
233 |
break;
|
sl@0
|
234 |
} // for
|
sl@0
|
235 |
|
sl@0
|
236 |
if (0 == numTokens)
|
sl@0
|
237 |
{
|
sl@0
|
238 |
RDebug::Print(KCentRepConvTool);
|
sl@0
|
239 |
RDebug::Print(KHelpMsg, &iDefaultPath, &iDefaultPath);
|
sl@0
|
240 |
|
sl@0
|
241 |
iScrnOutput->Printf(KHelpMsg, &iDefaultPath, &iDefaultPath);
|
sl@0
|
242 |
User::Leave(KErrArgument);
|
sl@0
|
243 |
}
|
sl@0
|
244 |
|
sl@0
|
245 |
// aOutputPath can be blank but aInputPath is mandatory.
|
sl@0
|
246 |
if (aInputPath.Length() == 0)
|
sl@0
|
247 |
{
|
sl@0
|
248 |
RDebug::Print(KCentRepConvTool);
|
sl@0
|
249 |
RDebug::Print(KBadArg, &iCmd);
|
sl@0
|
250 |
|
sl@0
|
251 |
iScrnOutput->Printf(KBadArg, &iCmd);
|
sl@0
|
252 |
User::Leave(KErrArgument);
|
sl@0
|
253 |
}
|
sl@0
|
254 |
}
|
sl@0
|
255 |
|
sl@0
|
256 |
//
|
sl@0
|
257 |
// Validate the input filenames.
|
sl@0
|
258 |
void CCentRepConvTool::VerifyInputPathL()
|
sl@0
|
259 |
{
|
sl@0
|
260 |
// Check input file is .txt or .cre
|
sl@0
|
261 |
iTextToBin = (iInputPath.Ext().CompareF(*TServerResources::iIniExt) == 0);
|
sl@0
|
262 |
TBool binInput = !iTextToBin && (iInputPath.Ext().CompareF(*TServerResources::iCreExt) == 0);
|
sl@0
|
263 |
|
sl@0
|
264 |
if (!iTextToBin && !binInput)
|
sl@0
|
265 |
{
|
sl@0
|
266 |
_LIT(KBadExt, "Bad input filename: %S\r\nInput file extension must be %S or %S\r\n");
|
sl@0
|
267 |
RDebug::Print(KCentRepConvTool);
|
sl@0
|
268 |
RDebug::Print(KBadExt, &iCmd, TServerResources::iIniExt,
|
sl@0
|
269 |
TServerResources::iCreExt);
|
sl@0
|
270 |
|
sl@0
|
271 |
iScrnOutput->Printf(KBadExt, &iCmd, TServerResources::iIniExt,
|
sl@0
|
272 |
TServerResources::iCreExt);
|
sl@0
|
273 |
User::Leave(KErrArgument);
|
sl@0
|
274 |
}
|
sl@0
|
275 |
|
sl@0
|
276 |
// check input filename is 8 hex digits.
|
sl@0
|
277 |
TPtrC p(iInputPath.Name());
|
sl@0
|
278 |
TBool validName = (KNumDigitsInUID == p.Length());
|
sl@0
|
279 |
|
sl@0
|
280 |
if (validName)
|
sl@0
|
281 |
{
|
sl@0
|
282 |
TLex lex(p);
|
sl@0
|
283 |
for (TInt i = 0; validName && i<KNumDigitsInUID; i++)
|
sl@0
|
284 |
{
|
sl@0
|
285 |
if (lex.Peek().IsHexDigit())
|
sl@0
|
286 |
{
|
sl@0
|
287 |
lex.Inc();
|
sl@0
|
288 |
}
|
sl@0
|
289 |
else
|
sl@0
|
290 |
{
|
sl@0
|
291 |
validName = EFalse;
|
sl@0
|
292 |
}
|
sl@0
|
293 |
} // for
|
sl@0
|
294 |
} // if validName
|
sl@0
|
295 |
|
sl@0
|
296 |
if (!validName)
|
sl@0
|
297 |
{
|
sl@0
|
298 |
_LIT(KBadRepUid, "Input filename in %S is not a valid UID.\r\nExpect 8 hex digits.\r\n");
|
sl@0
|
299 |
RDebug::Print(KCentRepConvTool);
|
sl@0
|
300 |
RDebug::Print(KBadRepUid, &iCmd);
|
sl@0
|
301 |
|
sl@0
|
302 |
iScrnOutput->Printf(KBadRepUid, &iCmd);
|
sl@0
|
303 |
User::Leave(KErrArgument);
|
sl@0
|
304 |
}
|
sl@0
|
305 |
|
sl@0
|
306 |
p.Set(iInputPath.FullName());
|
sl@0
|
307 |
|
sl@0
|
308 |
if ( InOthersPrivatePath(p) )
|
sl@0
|
309 |
{
|
sl@0
|
310 |
_LIT(KInfileCaged, "Cannot access input file %S because it is in private data cage.\r\n");
|
sl@0
|
311 |
RDebug::Print(KCentRepConvTool);
|
sl@0
|
312 |
RDebug::Print(KInfileCaged, &p);
|
sl@0
|
313 |
|
sl@0
|
314 |
iScrnOutput->Printf(KInfileCaged, &p);
|
sl@0
|
315 |
User::Leave(KErrAccessDenied);
|
sl@0
|
316 |
}
|
sl@0
|
317 |
|
sl@0
|
318 |
if (!BaflUtils::FileExists(iFs, p))
|
sl@0
|
319 |
{
|
sl@0
|
320 |
_LIT(KInFileNotExists, "Input file %S does not exist.\r\n");
|
sl@0
|
321 |
RDebug::Print(KCentRepConvTool);
|
sl@0
|
322 |
RDebug::Print(KInFileNotExists, &p);
|
sl@0
|
323 |
|
sl@0
|
324 |
iScrnOutput->Printf(KInFileNotExists, &p);
|
sl@0
|
325 |
User::Leave(KErrNotFound);
|
sl@0
|
326 |
}
|
sl@0
|
327 |
}
|
sl@0
|
328 |
|
sl@0
|
329 |
//
|
sl@0
|
330 |
// Validate the output filenames.
|
sl@0
|
331 |
void CCentRepConvTool::VerifyOutputPathL()
|
sl@0
|
332 |
{
|
sl@0
|
333 |
// If output filename is not specified, fill in the missing parts.
|
sl@0
|
334 |
TBool EmptyOutFileName = EFalse;
|
sl@0
|
335 |
|
sl@0
|
336 |
TPtrC outFileName(iOutputPath.Name());
|
sl@0
|
337 |
if (outFileName.Length())
|
sl@0
|
338 |
{
|
sl@0
|
339 |
if (0 != outFileName.CompareF(iInputPath.Name()))
|
sl@0
|
340 |
{
|
sl@0
|
341 |
_LIT(KUnmatchFilenames, "Bad input: %S\r\nInput filename does not match output filename.\r\n");
|
sl@0
|
342 |
RDebug::Print(KCentRepConvTool);
|
sl@0
|
343 |
RDebug::Print(KUnmatchFilenames, &iCmd);
|
sl@0
|
344 |
|
sl@0
|
345 |
iScrnOutput->Printf(KUnmatchFilenames, &iCmd);
|
sl@0
|
346 |
User::Leave(KErrArgument);
|
sl@0
|
347 |
}
|
sl@0
|
348 |
}
|
sl@0
|
349 |
else
|
sl@0
|
350 |
{
|
sl@0
|
351 |
EmptyOutFileName = ETrue;
|
sl@0
|
352 |
outFileName.Set(iInputPath.Name());
|
sl@0
|
353 |
}
|
sl@0
|
354 |
|
sl@0
|
355 |
|
sl@0
|
356 |
TPtrC correctExt(*TServerResources::iCreExt);
|
sl@0
|
357 |
TPtrC outFileExt(iOutputPath.Ext());
|
sl@0
|
358 |
if (!iTextToBin)
|
sl@0
|
359 |
{
|
sl@0
|
360 |
correctExt.Set(*TServerResources::iIniExt);
|
sl@0
|
361 |
}
|
sl@0
|
362 |
|
sl@0
|
363 |
if (outFileExt.Length())
|
sl@0
|
364 |
{
|
sl@0
|
365 |
// If output filename is specified, extension should match conversion.
|
sl@0
|
366 |
if (0 != outFileExt.CompareF(correctExt))
|
sl@0
|
367 |
{
|
sl@0
|
368 |
_LIT(KUnmatchExt, "Bad input: %S\r\nExtension of output filename not valid.\r\n");
|
sl@0
|
369 |
RDebug::Print(KCentRepConvTool);
|
sl@0
|
370 |
RDebug::Print(KUnmatchExt, &iCmd);
|
sl@0
|
371 |
|
sl@0
|
372 |
iScrnOutput->Printf(KUnmatchExt, &iCmd);
|
sl@0
|
373 |
User::Leave(KErrArgument);
|
sl@0
|
374 |
}
|
sl@0
|
375 |
}
|
sl@0
|
376 |
else
|
sl@0
|
377 |
{
|
sl@0
|
378 |
EmptyOutFileName = ETrue;
|
sl@0
|
379 |
outFileExt.Set(correctExt);
|
sl@0
|
380 |
}
|
sl@0
|
381 |
|
sl@0
|
382 |
TPtrC p;
|
sl@0
|
383 |
|
sl@0
|
384 |
if (EmptyOutFileName)
|
sl@0
|
385 |
{
|
sl@0
|
386 |
const TInt KFilePlusExtLen = KNumDigitsInUID + 4; // e.g. 01234567.cre
|
sl@0
|
387 |
TBuf<KFilePlusExtLen> newName(outFileName);
|
sl@0
|
388 |
newName.Append(correctExt);
|
sl@0
|
389 |
|
sl@0
|
390 |
p.Set(iOutputPath.DriveAndPath());
|
sl@0
|
391 |
TParse newpath;
|
sl@0
|
392 |
newpath.Set(newName, NULL, &p);
|
sl@0
|
393 |
|
sl@0
|
394 |
p.Set(newpath.FullName());
|
sl@0
|
395 |
iOutputPath.Set(p, NULL, NULL);
|
sl@0
|
396 |
}
|
sl@0
|
397 |
|
sl@0
|
398 |
// Check output file is in other's private data cage
|
sl@0
|
399 |
p.Set(iOutputPath.FullName());
|
sl@0
|
400 |
if ( InOthersPrivatePath(p) )
|
sl@0
|
401 |
{
|
sl@0
|
402 |
_LIT(KOutfileInDataCage, "Cannot write output file %S because it is in private data cage.\r\n");
|
sl@0
|
403 |
RDebug::Print(KCentRepConvTool);
|
sl@0
|
404 |
RDebug::Print(KOutfileInDataCage, &p);
|
sl@0
|
405 |
|
sl@0
|
406 |
iScrnOutput->Printf(KOutfileInDataCage, &p);
|
sl@0
|
407 |
User::Leave(KErrAccessDenied);
|
sl@0
|
408 |
}
|
sl@0
|
409 |
|
sl@0
|
410 |
// Check saving output to read only drive.
|
sl@0
|
411 |
p.Set(iOutputPath.DriveAndPath());
|
sl@0
|
412 |
TBool isReadOnly;
|
sl@0
|
413 |
TInt ret;
|
sl@0
|
414 |
ret = BaflUtils::DiskIsReadOnly(iFs, p, isReadOnly);
|
sl@0
|
415 |
if (ret == KErrNone)
|
sl@0
|
416 |
{
|
sl@0
|
417 |
if (isReadOnly)
|
sl@0
|
418 |
{
|
sl@0
|
419 |
_LIT(KWriteToReadOnly, "Bad argument: output dir %S is in read only drive.\r\n");
|
sl@0
|
420 |
RDebug::Print(KCentRepConvTool);
|
sl@0
|
421 |
RDebug::Print(KWriteToReadOnly, &p);
|
sl@0
|
422 |
|
sl@0
|
423 |
iScrnOutput->Printf(KWriteToReadOnly, &p);
|
sl@0
|
424 |
User::Leave(KErrArgument);
|
sl@0
|
425 |
}
|
sl@0
|
426 |
}
|
sl@0
|
427 |
|
sl@0
|
428 |
ret = iFs.MkDirAll(p);
|
sl@0
|
429 |
if (ret != KErrNone && ret != KErrAlreadyExists)
|
sl@0
|
430 |
{
|
sl@0
|
431 |
_LIT(KCreateOutpathFail, "Create output path %S failed, err %d.\r\n");
|
sl@0
|
432 |
RDebug::Print(KCentRepConvTool);
|
sl@0
|
433 |
RDebug::Print(KCreateOutpathFail, &p, ret);
|
sl@0
|
434 |
|
sl@0
|
435 |
iScrnOutput->Printf(KCreateOutpathFail, &p, ret);
|
sl@0
|
436 |
User::Leave(ret);
|
sl@0
|
437 |
}
|
sl@0
|
438 |
}
|
sl@0
|
439 |
|
sl@0
|
440 |
//
|
sl@0
|
441 |
// Open a RWriteStream on top of a CDirectFileStore. Call
|
sl@0
|
442 |
// CSharedRepository's ExternalizeCre method to write the
|
sl@0
|
443 |
// settings to file.
|
sl@0
|
444 |
void CCentRepConvTool::ExternalizeToCreL()
|
sl@0
|
445 |
{
|
sl@0
|
446 |
// Create file store
|
sl@0
|
447 |
CDirectFileStore* store = CDirectFileStore::ReplaceLC(iFs,
|
sl@0
|
448 |
iOutputPath.FullName(), (EFileWrite | EFileShareExclusive));
|
sl@0
|
449 |
const TUid uid2 = KNullUid;
|
sl@0
|
450 |
store->SetTypeL(TUidType(KDirectFileStoreLayoutUid, uid2, KServerUid3)) ;
|
sl@0
|
451 |
|
sl@0
|
452 |
// Write the stream index/dictionary as root stream within the store
|
sl@0
|
453 |
// so we can access it when we do a restore later on
|
sl@0
|
454 |
RStoreWriteStream rootStream ;
|
sl@0
|
455 |
TStreamId rootStreamId = rootStream.CreateLC(*store) ;
|
sl@0
|
456 |
iCentRepShrepos->ExternalizeCre(rootStream);
|
sl@0
|
457 |
rootStream.CommitL();
|
sl@0
|
458 |
|
sl@0
|
459 |
CleanupStack::PopAndDestroy(&rootStream) ;
|
sl@0
|
460 |
store->SetRootL(rootStreamId);
|
sl@0
|
461 |
store->CommitL();
|
sl@0
|
462 |
CleanupStack::PopAndDestroy(store);
|
sl@0
|
463 |
}
|
sl@0
|
464 |
|
sl@0
|
465 |
//
|
sl@0
|
466 |
// Check if given path is located in some other process's
|
sl@0
|
467 |
// private data cage
|
sl@0
|
468 |
TBool CCentRepConvTool::InOthersPrivatePath(const TDesC& aFullPathName)
|
sl@0
|
469 |
{
|
sl@0
|
470 |
_LIT(KPrivate, "\\private\\");
|
sl@0
|
471 |
const TInt KPosAfterDrive = 2;
|
sl@0
|
472 |
return aFullPathName.FindF(KPrivate) == KPosAfterDrive &&
|
sl@0
|
473 |
aFullPathName.FindF(iMyDataCage) == KErrNotFound;
|
sl@0
|
474 |
}
|