sl@0
|
1 |
// Copyright (c) 2004-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 |
// Helper process with high capability to perform copying of files for
|
sl@0
|
15 |
// test harnesses.
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <f32file.h>
|
sl@0
|
20 |
#include <e32debug.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
|
sl@0
|
23 |
_LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames
|
sl@0
|
24 |
|
sl@0
|
25 |
|
sl@0
|
26 |
// Copy the files specified.
|
sl@0
|
27 |
void CopyFileL(const TDesC& anOld, const TDesC& aNew)
|
sl@0
|
28 |
{
|
sl@0
|
29 |
TInt r = KErrNone;
|
sl@0
|
30 |
RFs fs;
|
sl@0
|
31 |
r = fs.Connect();
|
sl@0
|
32 |
if (r != KErrNone)
|
sl@0
|
33 |
{
|
sl@0
|
34 |
User::Leave(r);
|
sl@0
|
35 |
}
|
sl@0
|
36 |
CleanupClosePushL(fs);
|
sl@0
|
37 |
|
sl@0
|
38 |
CFileMan* fileMan = CFileMan::NewL(fs);
|
sl@0
|
39 |
CleanupStack::PushL(fileMan);
|
sl@0
|
40 |
|
sl@0
|
41 |
// Ensure the path exists
|
sl@0
|
42 |
TInt err = fs.MkDirAll(aNew);
|
sl@0
|
43 |
if ((err != KErrNone) && (err != KErrAlreadyExists))
|
sl@0
|
44 |
User::Leave(err);
|
sl@0
|
45 |
|
sl@0
|
46 |
// Make the destination file writeable
|
sl@0
|
47 |
err = fileMan->Attribs(aNew, 0, KEntryAttReadOnly, TTime(0), 0);
|
sl@0
|
48 |
if ((err != KErrNone) && (err != KErrNotFound))
|
sl@0
|
49 |
User::Leave(err);
|
sl@0
|
50 |
|
sl@0
|
51 |
// Do the file copy
|
sl@0
|
52 |
User::LeaveIfError(fileMan->Copy(anOld, aNew));
|
sl@0
|
53 |
|
sl@0
|
54 |
CleanupStack::PopAndDestroy(2);
|
sl@0
|
55 |
}
|
sl@0
|
56 |
|
sl@0
|
57 |
|
sl@0
|
58 |
// Format of aFileNames is [srcFile]|[dstFile]
|
sl@0
|
59 |
GLDEF_C TInt E32Main()
|
sl@0
|
60 |
{
|
sl@0
|
61 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
sl@0
|
62 |
|
sl@0
|
63 |
TBuf<KMaxFileName*2> names;
|
sl@0
|
64 |
User::CommandLine(names);
|
sl@0
|
65 |
TInt pos = names.Find(KSeparator);
|
sl@0
|
66 |
TFileName srcFile(names.Mid(0,pos));
|
sl@0
|
67 |
TFileName dstFile(names.Mid(pos+1, names.Length()-(pos+1)));
|
sl@0
|
68 |
|
sl@0
|
69 |
TInt err = KErrNone;
|
sl@0
|
70 |
TRAP(err,CopyFileL(srcFile, dstFile));
|
sl@0
|
71 |
if (err == KErrNone)
|
sl@0
|
72 |
RDebug::Print(_L("CFileMan Copy file '%S' to '%S' succeeded.\n"), &srcFile, &dstFile);
|
sl@0
|
73 |
else
|
sl@0
|
74 |
RDebug::Print(_L("CFileMan Copy file '%S' to '%S' failed with error = %d.\n"), &srcFile, &dstFile, err);
|
sl@0
|
75 |
|
sl@0
|
76 |
delete cleanup;
|
sl@0
|
77 |
return err;
|
sl@0
|
78 |
}
|