2
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: This file contains the header file of the CAtsLogger
|
|
15 |
* class.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
#include "stffiletestlibplugin.h"
|
|
20 |
#include <f32file.h>
|
|
21 |
|
|
22 |
_LIT(KSTFRunUtilsMakeReadWrite,"MakeReadWrite");
|
|
23 |
_LIT(KSTFRunUtilsCopyFile,"CopyFile");
|
|
24 |
_LIT(KSTFRunUtilsMkDir,"MkDir");
|
|
25 |
_LIT(KSTFRunUtilsDeleteFile,"DeleteFile");
|
|
26 |
_LIT(KSTFRunUtilsDelete,"Delete");
|
|
27 |
_LIT(KSTFRunUtilsDeleteDirectory,"DeleteDirectory");
|
|
28 |
EXPORT_C CStfFileTestLibPlugin* LibEntryL()
|
|
29 |
{
|
|
30 |
CStfFileTestLibPlugin* self=CStfFileTestLibPlugin::NewL();
|
|
31 |
return self;
|
|
32 |
}
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
// Member Functions
|
|
37 |
|
|
38 |
CStfFileTestLibPlugin* CStfFileTestLibPlugin::NewL()
|
|
39 |
{
|
|
40 |
CStfFileTestLibPlugin* self = new (ELeave) CStfFileTestLibPlugin;
|
|
41 |
CleanupStack::PushL(self);
|
|
42 |
self->ConstructL();
|
|
43 |
CleanupStack::Pop(self);
|
|
44 |
return self;
|
|
45 |
}
|
|
46 |
CStfFileTestLibPlugin::~CStfFileTestLibPlugin()
|
|
47 |
{
|
|
48 |
|
|
49 |
}
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
EXPORT_C TBool CStfFileTestLibPlugin::IsCommandSupported(const TDesC& aCommand)
|
|
55 |
{
|
|
56 |
TBool result=EFalse;
|
|
57 |
if(aCommand==KSTFRunUtilsMakeReadWrite)
|
|
58 |
{
|
|
59 |
result=ETrue;
|
|
60 |
}
|
|
61 |
else if(aCommand==KSTFRunUtilsCopyFile)
|
|
62 |
{
|
|
63 |
result=ETrue;
|
|
64 |
}
|
|
65 |
else if(aCommand==KSTFRunUtilsMkDir)
|
|
66 |
{
|
|
67 |
result=ETrue;
|
|
68 |
}
|
|
69 |
else if(aCommand==KSTFRunUtilsDeleteFile)
|
|
70 |
{
|
|
71 |
result=ETrue;
|
|
72 |
}
|
|
73 |
else if(aCommand==KSTFRunUtilsDelete)
|
|
74 |
{
|
|
75 |
result=ETrue;
|
|
76 |
}
|
|
77 |
else if(aCommand==KSTFRunUtilsDeleteDirectory)
|
|
78 |
{
|
|
79 |
result=ETrue;
|
|
80 |
}
|
|
81 |
|
|
82 |
return result;
|
|
83 |
}
|
|
84 |
|
|
85 |
EXPORT_C TInt CStfFileTestLibPlugin::ExecuteCommandL(const TDesC& aCommandLine)
|
|
86 |
{
|
|
87 |
TInt err = 0;
|
|
88 |
_LIT(KDefault, "?:\\default");
|
|
89 |
_LIT(KCDrive, "?:\\");
|
|
90 |
_LIT(KSTFBackslash, "\\" );
|
|
91 |
TBuf<10> defaultPath(KDefault);
|
|
92 |
defaultPath.Replace(0, 2, _L("c:"));
|
|
93 |
|
|
94 |
TBuf<3> cDrive(KCDrive);
|
|
95 |
cDrive.Replace(0, 2, _L("c:"));
|
|
96 |
|
|
97 |
RFs fS;
|
|
98 |
User::LeaveIfError(fS.Connect() );
|
|
99 |
CleanupClosePushL(fS);
|
|
100 |
|
|
101 |
TLex lex(aCommandLine);
|
|
102 |
// lex.NextToken();
|
|
103 |
TPtrC token(lex.NextToken());
|
|
104 |
if(token.CompareF(KSTFRunUtilsCopyFile) == 0)
|
|
105 |
{
|
|
106 |
TPtrC file1=lex.NextToken();
|
|
107 |
TPtrC file2=lex.NextToken();
|
|
108 |
TParse source, dest;
|
|
109 |
CFileMan* fMan = CFileMan::NewL(fS);
|
|
110 |
CleanupStack::PushL(fMan);
|
|
111 |
User::LeaveIfError(source.Set(file1, &defaultPath, NULL) );
|
|
112 |
User::LeaveIfError(dest.Set(file2, &defaultPath, NULL) );
|
|
113 |
TPtrC sourcefile=source.FullName();
|
|
114 |
TPtrC destfile=dest.FullName();
|
|
115 |
err=fMan->Copy(file1, file2, CFileMan::EOverWrite);
|
|
116 |
User::LeaveIfError(err);
|
|
117 |
CleanupStack::PopAndDestroy(fMan);
|
|
118 |
}
|
|
119 |
else if(token.CompareF(KSTFRunUtilsMkDir) == 0)
|
|
120 |
{
|
|
121 |
token.Set(lex.NextToken());
|
|
122 |
TParse fileName;
|
|
123 |
|
|
124 |
if (!token.Length())
|
|
125 |
User::Leave(KErrPathNotFound);
|
|
126 |
|
|
127 |
TPtrC lastChar(token.Mid(token.Length() - 1));
|
|
128 |
if ( lastChar.CompareF(KSTFBackslash) != 0 )
|
|
129 |
{
|
|
130 |
TBuf<64> tempToken(token);
|
|
131 |
tempToken.Append(KSTFBackslash);
|
|
132 |
token.Set(tempToken);
|
|
133 |
}
|
|
134 |
|
|
135 |
User::LeaveIfError( fileName.Set(token, &cDrive, NULL) );
|
|
136 |
err=fS.MkDir( fileName.DriveAndPath() );
|
|
137 |
User::LeaveIfError( err );
|
|
138 |
}
|
|
139 |
else if(token.CompareF(KSTFRunUtilsDeleteFile) == 0 ||
|
|
140 |
token.CompareF(KSTFRunUtilsDelete) == 0)
|
|
141 |
{
|
|
142 |
token.Set(lex.NextToken());
|
|
143 |
|
|
144 |
CFileMan* fMan = CFileMan::NewL(fS);
|
|
145 |
CleanupStack::PushL(fMan);
|
|
146 |
err=fMan->Delete(token);
|
|
147 |
User::LeaveIfError(err );
|
|
148 |
CleanupStack::PopAndDestroy(fMan);
|
|
149 |
}
|
|
150 |
else if(token.CompareF(KSTFRunUtilsMakeReadWrite) == 0)
|
|
151 |
{
|
|
152 |
token.Set(lex.NextToken());
|
|
153 |
TParse fileName;
|
|
154 |
User::LeaveIfError(fileName.Set(token, &defaultPath, NULL) );
|
|
155 |
err = fS.SetAtt(fileName.FullName(),0, KEntryAttReadOnly);
|
|
156 |
if (err != KErrNone && err != KErrNotFound)
|
|
157 |
User::Leave(err);
|
|
158 |
}
|
|
159 |
//It deletes the specified directory
|
|
160 |
else if(token.CompareF(KSTFRunUtilsDeleteDirectory) == 0)
|
|
161 |
{
|
|
162 |
token.Set(lex.NextToken());
|
|
163 |
TParse fileName;
|
|
164 |
|
|
165 |
if (!token.Length())
|
|
166 |
User::Leave(KErrPathNotFound);
|
|
167 |
|
|
168 |
TPtrC lastChar(token.Mid(token.Length() - 1));
|
|
169 |
if ( lastChar.CompareF(KSTFBackslash) != 0 )
|
|
170 |
{
|
|
171 |
TBuf<64> tempToken(token);
|
|
172 |
tempToken.Append(KSTFBackslash);
|
|
173 |
token.Set(tempToken);
|
|
174 |
}
|
|
175 |
|
|
176 |
CFileMan* fMan = CFileMan::NewL(fS);
|
|
177 |
CleanupStack::PushL(fMan);
|
|
178 |
|
|
179 |
User::LeaveIfError(fileName.Set(token, &cDrive, NULL) );
|
|
180 |
err=fMan->RmDir( fileName.DriveAndPath() );
|
|
181 |
User::LeaveIfError(err );
|
|
182 |
|
|
183 |
CleanupStack::PopAndDestroy(fMan);
|
|
184 |
}
|
|
185 |
|
|
186 |
fS.Close();
|
|
187 |
CleanupStack::Pop(&fS);
|
|
188 |
return err;
|
|
189 |
}
|
|
190 |
|
|
191 |
CStfFileTestLibPlugin::CStfFileTestLibPlugin()
|
|
192 |
// note, CBase initialises all member variables to zero
|
|
193 |
{
|
|
194 |
}
|
|
195 |
|
|
196 |
void CStfFileTestLibPlugin::ConstructL()
|
|
197 |
{
|
|
198 |
// second phase constructor, anything that may leave must be constructed here
|
|
199 |
|
|
200 |
}
|
|
201 |
|
|
202 |
|
|
203 |
|