|
1 /* |
|
2 * Copyright (c) 2003-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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "fstokenutil.h" |
|
20 #include <f32file.h> |
|
21 #include <s32file.h> |
|
22 #include <sectcbutil.h> |
|
23 |
|
24 // RMessage::Panic() also completes the message. This is: |
|
25 // (a) important for efficient cleanup within the kernel |
|
26 // (b) a problem if the message is completed a second time |
|
27 void PanicClient(const RMessage2& aMessage, ETokenTypeServerPanic aPanic) |
|
28 { |
|
29 _LIT(KPanicClient,"TTSERVERCLIENT"); |
|
30 aMessage.Panic(KPanicClient,aPanic); |
|
31 } |
|
32 |
|
33 void PanicServer(ETokenTypeServerPanic aPanicCode) |
|
34 { |
|
35 _LIT(KPanicServer,"TOKENTYPESERVER"); |
|
36 User::Panic(KPanicServer, aPanicCode); |
|
37 } |
|
38 |
|
39 /// Rom drive where the initial store data is |
|
40 _LIT(KFileStoreROMDrive, "Z:"); |
|
41 |
|
42 TBool FileUtils::ExistsL(RFs& aFs, const TDesC& aFile) |
|
43 { |
|
44 TBool result = EFalse; |
|
45 TBool open; |
|
46 TInt err = aFs.IsFileOpen(aFile, open); |
|
47 |
|
48 if (err == KErrNone) |
|
49 { |
|
50 result = ETrue; |
|
51 } |
|
52 else if (err != KErrNotFound && err != KErrPathNotFound) |
|
53 { |
|
54 User::Leave(err); |
|
55 } |
|
56 |
|
57 return result; |
|
58 } |
|
59 |
|
60 void FileUtils::EnsurePathL(RFs& aFs, const TDesC& aFile) |
|
61 { |
|
62 TInt err = aFs.MkDirAll(aFile); |
|
63 if (err != KErrNone && err != KErrAlreadyExists) |
|
64 { |
|
65 User::Leave(err); |
|
66 } |
|
67 } |
|
68 |
|
69 void FileUtils::CopyL(RFs& aFs, const TDesC& aSouce, const TDesC& aDest) |
|
70 { |
|
71 RFileReadStream in; |
|
72 User::LeaveIfError(in.Open(aFs, aSouce, EFileRead | EFileShareReadersOnly)); |
|
73 CleanupClosePushL(in); |
|
74 |
|
75 RFileWriteStream out; |
|
76 User::LeaveIfError(out.Replace(aFs, aDest, EFileWrite | EFileShareExclusive)); |
|
77 CleanupClosePushL(out); |
|
78 |
|
79 in.ReadL(out); |
|
80 CleanupStack::PopAndDestroy(2, &in); |
|
81 } |
|
82 |
|
83 void FileUtils::MakePrivateFilenameL(RFs& aFs, const TDesC& aLeafName, TDes& aNameOut) |
|
84 { |
|
85 aNameOut.SetLength(0); |
|
86 aNameOut.Append(SecTcbUtil::GetSystemDriveChar(SecTcbUtil::GetSystemDrive())); |
|
87 aNameOut.Append(':'); |
|
88 |
|
89 // Get private path |
|
90 TBuf<20> privatePath; |
|
91 aFs.PrivatePath(privatePath); |
|
92 aNameOut.Append(privatePath); |
|
93 |
|
94 aNameOut.Append(aLeafName); |
|
95 } |
|
96 |
|
97 void FileUtils::MakePrivateROMFilenameL(RFs& aFs, const TDesC& aLeafName, TDes& aNameOut) |
|
98 { |
|
99 aNameOut.Copy(KFileStoreROMDrive); |
|
100 |
|
101 // Get private path |
|
102 TBuf<20> privatePath; |
|
103 aFs.PrivatePath(privatePath); |
|
104 aNameOut.Append(privatePath); |
|
105 |
|
106 aNameOut.Append(aLeafName); |
|
107 } |