sl@0
|
1 |
// Copyright (c) 2007-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 |
/**
|
sl@0
|
17 |
@file
|
sl@0
|
18 |
@test
|
sl@0
|
19 |
@internalComponent - Internal Symbian test code
|
sl@0
|
20 |
*/
|
sl@0
|
21 |
#include <f32file.h>
|
sl@0
|
22 |
#include <e32cmn.h>
|
sl@0
|
23 |
#include <e32std.h>
|
sl@0
|
24 |
#include <e32const.h>
|
sl@0
|
25 |
#include <e32def_private.h>
|
sl@0
|
26 |
|
sl@0
|
27 |
void CopyFileL(const TDesC& aSourceFile, const TDesC& aDestFile)
|
sl@0
|
28 |
{
|
sl@0
|
29 |
RFs fs;
|
sl@0
|
30 |
fs.Connect();
|
sl@0
|
31 |
CleanupClosePushL(fs);
|
sl@0
|
32 |
fs.MkDirAll(aDestFile);
|
sl@0
|
33 |
CFileMan* fileMan = CFileMan::NewL( fs );
|
sl@0
|
34 |
// Copy feature file to file manager private data cage.
|
sl@0
|
35 |
//Ignore any errors as the file or path may not exist
|
sl@0
|
36 |
fileMan->Copy(aSourceFile, aDestFile);
|
sl@0
|
37 |
CleanupStack::PopAndDestroy(&fs);
|
sl@0
|
38 |
}
|
sl@0
|
39 |
|
sl@0
|
40 |
void DeleteFileL(const TDesC& aFile)
|
sl@0
|
41 |
{
|
sl@0
|
42 |
RFs fs;
|
sl@0
|
43 |
fs.Connect();
|
sl@0
|
44 |
CleanupClosePushL(fs);
|
sl@0
|
45 |
fs.SetAtt(aFile, 0, KEntryAttReadOnly);
|
sl@0
|
46 |
//Ignore any errors as the file or path may not exist
|
sl@0
|
47 |
fs.Delete( aFile );
|
sl@0
|
48 |
CleanupStack::PopAndDestroy(&fs);
|
sl@0
|
49 |
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
TInt CheckFile(const TDesC& aFile)
|
sl@0
|
53 |
{
|
sl@0
|
54 |
RFs fs;
|
sl@0
|
55 |
fs.Connect();
|
sl@0
|
56 |
RFile file;
|
sl@0
|
57 |
TInt err = file.Open(fs,aFile,EFileRead);
|
sl@0
|
58 |
if (err!=KErrNotFound)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
file.Close();
|
sl@0
|
61 |
fs.Close();
|
sl@0
|
62 |
return KErrNone;
|
sl@0
|
63 |
}
|
sl@0
|
64 |
else
|
sl@0
|
65 |
{
|
sl@0
|
66 |
fs.Close();
|
sl@0
|
67 |
return KErrNotFound;
|
sl@0
|
68 |
}
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
TInt ParseSwitch(const TDesC& aSwitch, const TDesC& aFile)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
if (aSwitch==_L("?"))
|
sl@0
|
74 |
return CheckFile(aFile);
|
sl@0
|
75 |
else
|
sl@0
|
76 |
return KErrNotSupported;
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
static void DoMainL()
|
sl@0
|
80 |
{
|
sl@0
|
81 |
HBufC* cmdLine = HBufC::NewL(User::CommandLineLength());
|
sl@0
|
82 |
CleanupStack::PushL(cmdLine);
|
sl@0
|
83 |
|
sl@0
|
84 |
TPtr cmdLinePtr(cmdLine->Des());
|
sl@0
|
85 |
User::CommandLine(cmdLinePtr);
|
sl@0
|
86 |
|
sl@0
|
87 |
const TInt KMaxNumTokens = 2;
|
sl@0
|
88 |
TPtrC tokens[KMaxNumTokens];
|
sl@0
|
89 |
TLex lex(cmdLinePtr);
|
sl@0
|
90 |
TInt i;
|
sl@0
|
91 |
for (i = 0; !lex.Eos() && i < KMaxNumTokens; i++)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
tokens[i].Set(lex.NextToken());
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
TInt numTokens = i;
|
sl@0
|
97 |
if (numTokens == 1)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
DeleteFileL(tokens[0]);
|
sl@0
|
100 |
}
|
sl@0
|
101 |
else
|
sl@0
|
102 |
if (numTokens == 2)
|
sl@0
|
103 |
{
|
sl@0
|
104 |
if (tokens[0][0]=='-')
|
sl@0
|
105 |
{
|
sl@0
|
106 |
User::LeaveIfError(ParseSwitch(tokens[0].Right(tokens[0].Length()-1),tokens[1]));
|
sl@0
|
107 |
}
|
sl@0
|
108 |
else
|
sl@0
|
109 |
{
|
sl@0
|
110 |
CopyFileL(tokens[0],tokens[1]);
|
sl@0
|
111 |
}
|
sl@0
|
112 |
}
|
sl@0
|
113 |
|
sl@0
|
114 |
CleanupStack::PopAndDestroy(cmdLine);
|
sl@0
|
115 |
}
|
sl@0
|
116 |
|
sl@0
|
117 |
TInt E32Main()
|
sl@0
|
118 |
{
|
sl@0
|
119 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
sl@0
|
120 |
|
sl@0
|
121 |
TRAPD(err, ::DoMainL());
|
sl@0
|
122 |
|
sl@0
|
123 |
|
sl@0
|
124 |
delete cleanup;
|
sl@0
|
125 |
|
sl@0
|
126 |
return(err);
|
sl@0
|
127 |
}
|
sl@0
|
128 |
|