|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 #include <f32file.h> |
|
22 #include <e32cmn.h> |
|
23 #include <e32std.h> |
|
24 #include <e32const.h> |
|
25 #include <e32def_private.h> |
|
26 |
|
27 void CopyFileL(const TDesC& aSourceFile, const TDesC& aDestFile) |
|
28 { |
|
29 RFs fs; |
|
30 fs.Connect(); |
|
31 CleanupClosePushL(fs); |
|
32 fs.MkDirAll(aDestFile); |
|
33 CFileMan* fileMan = CFileMan::NewL( fs ); |
|
34 // Copy feature file to file manager private data cage. |
|
35 //Ignore any errors as the file or path may not exist |
|
36 fileMan->Copy(aSourceFile, aDestFile); |
|
37 CleanupStack::PopAndDestroy(&fs); |
|
38 } |
|
39 |
|
40 void DeleteFileL(const TDesC& aFile) |
|
41 { |
|
42 RFs fs; |
|
43 fs.Connect(); |
|
44 CleanupClosePushL(fs); |
|
45 fs.SetAtt(aFile, 0, KEntryAttReadOnly); |
|
46 //Ignore any errors as the file or path may not exist |
|
47 fs.Delete( aFile ); |
|
48 CleanupStack::PopAndDestroy(&fs); |
|
49 |
|
50 } |
|
51 |
|
52 TInt CheckFile(const TDesC& aFile) |
|
53 { |
|
54 RFs fs; |
|
55 fs.Connect(); |
|
56 RFile file; |
|
57 TInt err = file.Open(fs,aFile,EFileRead); |
|
58 if (err!=KErrNotFound) |
|
59 { |
|
60 file.Close(); |
|
61 fs.Close(); |
|
62 return KErrNone; |
|
63 } |
|
64 else |
|
65 { |
|
66 fs.Close(); |
|
67 return KErrNotFound; |
|
68 } |
|
69 } |
|
70 |
|
71 TInt ParseSwitch(const TDesC& aSwitch, const TDesC& aFile) |
|
72 { |
|
73 if (aSwitch==_L("?")) |
|
74 return CheckFile(aFile); |
|
75 else |
|
76 return KErrNotSupported; |
|
77 } |
|
78 |
|
79 static void DoMainL() |
|
80 { |
|
81 HBufC* cmdLine = HBufC::NewL(User::CommandLineLength()); |
|
82 CleanupStack::PushL(cmdLine); |
|
83 |
|
84 TPtr cmdLinePtr(cmdLine->Des()); |
|
85 User::CommandLine(cmdLinePtr); |
|
86 |
|
87 const TInt KMaxNumTokens = 2; |
|
88 TPtrC tokens[KMaxNumTokens]; |
|
89 TLex lex(cmdLinePtr); |
|
90 TInt i; |
|
91 for (i = 0; !lex.Eos() && i < KMaxNumTokens; i++) |
|
92 { |
|
93 tokens[i].Set(lex.NextToken()); |
|
94 } |
|
95 |
|
96 TInt numTokens = i; |
|
97 if (numTokens == 1) |
|
98 { |
|
99 DeleteFileL(tokens[0]); |
|
100 } |
|
101 else |
|
102 if (numTokens == 2) |
|
103 { |
|
104 if (tokens[0][0]=='-') |
|
105 { |
|
106 User::LeaveIfError(ParseSwitch(tokens[0].Right(tokens[0].Length()-1),tokens[1])); |
|
107 } |
|
108 else |
|
109 { |
|
110 CopyFileL(tokens[0],tokens[1]); |
|
111 } |
|
112 } |
|
113 |
|
114 CleanupStack::PopAndDestroy(cmdLine); |
|
115 } |
|
116 |
|
117 TInt E32Main() |
|
118 { |
|
119 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
120 |
|
121 TRAPD(err, ::DoMainL()); |
|
122 |
|
123 |
|
124 delete cleanup; |
|
125 |
|
126 return(err); |
|
127 } |
|
128 |