|
1 // Copyright (c) 1998-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 #include "MSVUTILS.H" |
|
17 #include "MSVUIDS.H" |
|
18 #include "MSVIDS.H" |
|
19 #include "MSVPANIC.H" |
|
20 |
|
21 #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT) |
|
22 // Code change for PREQ 557. |
|
23 #include "msvpreferreddrivelist.h" |
|
24 #endif // #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT) |
|
25 |
|
26 |
|
27 // static |
|
28 EXPORT_C TBool MsvUtils::ValidEntry(const TMsvEntry& aEntry) |
|
29 // |
|
30 // Returns true if the contents of the entry confrom to policy |
|
31 // |
|
32 { |
|
33 return ValidEntry(aEntry, EFalse); |
|
34 } |
|
35 |
|
36 TBool MsvUtils::ValidEntry(const TMsvEntry& aEntry, TBool aCreate) |
|
37 // |
|
38 // Returns true if the contents of the entry confrom to policy |
|
39 // |
|
40 { |
|
41 if ((aEntry.iType!=KUidMsvNullEntry) && (aEntry.iMtm!=KUidMsvNullEntry) && (aEntry.Parent()!=KMsvNullIndexEntryId)) |
|
42 { |
|
43 // it has a type, MTM and parent defined |
|
44 if (aEntry.iType!=KUidMsvServiceEntry) |
|
45 { |
|
46 // a non-service entry cannot be owned by root and must have a service id |
|
47 if (aEntry.Parent()!=KMsvRootIndexEntryId && aEntry.iServiceId!=KMsvNullIndexEntryId) |
|
48 return ETrue; |
|
49 } |
|
50 else |
|
51 { |
|
52 // a service entry must be owned by root and has to have the service id pointed to itself |
|
53 // unless the entry is being created in which case we don't know the Id yet |
|
54 if (aEntry.Parent()==KMsvRootIndexEntryId && (aCreate || aEntry.iServiceId==aEntry.Id())) |
|
55 { |
|
56 return ETrue; |
|
57 } |
|
58 } |
|
59 } |
|
60 return EFalse; |
|
61 } |
|
62 |
|
63 // static |
|
64 EXPORT_C void MsvUtils::ConstructEntryName(TMsvId aService, TMsvId aEntry, TDes& aName, TNameMode aMode) |
|
65 // |
|
66 // Construct the name of the store, or the directory for binary files |
|
67 // The aName should already be seeded with the main message folder. |
|
68 // |
|
69 { |
|
70 #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT) |
|
71 // Code change for PREQ 557. |
|
72 // Unmask the TMsvIds supplied. |
|
73 TInt driveId = GetDriveId(aEntry); |
|
74 #ifdef SYMBIAN_MESSAGESTORE_UNIT_TESTCODE |
|
75 TInt drive = 0; |
|
76 if(0 == driveId) |
|
77 drive = TDriveUnit(aName.Left(1)); |
|
78 #endif |
|
79 aService = UnmaskTMsvId(aService); |
|
80 aEntry = UnmaskTMsvId(aEntry); |
|
81 #endif |
|
82 |
|
83 __ASSERT_DEBUG(aEntry!=KMsvRootIndexEntryId||aMode==EStore, PanicServer(EMsvAskingForRootFolderOrPath)); |
|
84 __ASSERT_DEBUG(aEntry!=aService || aMode!=EFolder || aService!=KMsvRootIndexEntryId, PanicServer(EMsvAskingForRootFolder)); |
|
85 __ASSERT_DEBUG(aMode!=EPath || (aEntry==aService && aService!=KMsvRootIndexEntryId), PanicServer(EMsvPathAsForNonService)); |
|
86 |
|
87 TBuf<KFileNameFixedWidth> dir; |
|
88 |
|
89 dir.NumFixedWidth(aService, EHex, KFileNameFixedWidth); |
|
90 |
|
91 // Change required for Preq557 |
|
92 #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT) |
|
93 // Delete the drive letter from the path as the drive can now be any |
|
94 // other drive unlike C: earlier. |
|
95 // We can get the correct drive information from aEntry. |
|
96 TInt colonPos = aName.Locate(':'); |
|
97 aName.Delete(0, colonPos + 1); |
|
98 |
|
99 // Add the appropriate drive letter. |
|
100 TDriveNumber driveNum; |
|
101 #ifdef SYMBIAN_MESSAGESTORE_UNIT_TESTCODE |
|
102 if(0 == driveId) |
|
103 { |
|
104 driveNum = TDriveNumber(drive); |
|
105 } |
|
106 else |
|
107 { |
|
108 CMsvPreferredDriveList::GetDriveList()->GetDriveNumber(driveId, driveNum); |
|
109 } |
|
110 #else |
|
111 CMsvPreferredDriveList::GetDriveList()->GetDriveNumber(driveId, driveNum); |
|
112 #endif |
|
113 |
|
114 aName.Insert(0, TDriveUnit(driveNum).Name()); |
|
115 #endif // #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT) |
|
116 |
|
117 aName.Append(dir); |
|
118 |
|
119 // root or service entry |
|
120 if (aService==aEntry) // Both are unmasked, so this comparison is safe. |
|
121 { |
|
122 if (aMode==EPath) |
|
123 // path - ...\[aService]_S\. |
|
124 aName.Append(KMsvDirectoryExt); |
|
125 else if (aMode==EFolder) |
|
126 // folder - ...\[aService]_F\. |
|
127 aName.Append(KMsvBinaryFolderExt); |
|
128 // else |
|
129 // store - ...\[aService] |
|
130 return; |
|
131 } |
|
132 |
|
133 aName.Append(KMsvDirectoryExt); |
|
134 // service path - ...\[aService]_S\. |
|
135 if (aMode==EPath) |
|
136 return; |
|
137 |
|
138 _LIT(KDirSep,"\\"); |
|
139 dir.NumFixedWidth(aEntry&0xf, EHex,1); |
|
140 aName.Append(dir); |
|
141 aName.Append(KDirSep); |
|
142 dir.NumFixedWidth(aEntry, EHex, KFileNameFixedWidth); |
|
143 aName.Append(dir); |
|
144 |
|
145 |
|
146 // entry store - ..\[aService]_S\[aEntry] |
|
147 if (aMode==EStore) |
|
148 return; |
|
149 |
|
150 aName.Append(KMsvBinaryFolderExt); |
|
151 // entry folder - ..\[aService]_S\[aEntry]_F |
|
152 |
|
153 |
|
154 } |
|
155 |
|
156 // static |
|
157 EXPORT_C TInt MsvUtils::HasDirectory(const RFs& aFs, const TDesC& aMessageFolder, TMsvId aService, TMsvId aEntry) |
|
158 { |
|
159 TFileName filename(aMessageFolder); |
|
160 ConstructEntryName(aService, aEntry, filename, EFolder); |
|
161 |
|
162 TUint attributes; |
|
163 TInt err = aFs.Att(filename, attributes); |
|
164 |
|
165 if (err == KErrNotFound || err == KErrPathNotFound) |
|
166 return 0; |
|
167 else if (err == KErrNone) |
|
168 return 1; |
|
169 |
|
170 return err; |
|
171 } |
|
172 |
|
173 // static |
|
174 EXPORT_C TInt MsvUtils::HasStore(const RFs& aFs, const TDesC& aMessageFolder, TMsvId aService, TMsvId aEntry) |
|
175 { |
|
176 TFileName filename(aMessageFolder); |
|
177 ConstructEntryName(aService, aEntry, filename, EStore); |
|
178 |
|
179 TUint attributes; |
|
180 TInt err = aFs.Att(filename, attributes); |
|
181 |
|
182 if (err == KErrNotFound || err == KErrPathNotFound) |
|
183 return 0; |
|
184 else if (err == KErrNone) |
|
185 return 1; |
|
186 |
|
187 return err; |
|
188 } |
|
189 |
|
190 // static |
|
191 EXPORT_C void MsvUtils::AddPathAndExtensionToResFileL(TFileName& aFileName) |
|
192 // Uses the following rules to make sure aFileName has a path and extension: |
|
193 // 1. If aFileName has no extension add ".rsc" |
|
194 // 2. If aFileName does have an extension then replace it with ".rsc" |
|
195 // 3. If aFileName contains a path leave it |
|
196 // 4. If aFileName contains no path prepend "z:\system\data\" |
|
197 |
|
198 // @param aFileName file name to be altered by this function |
|
199 // @leave system-wide error codes |
|
200 { |
|
201 _LIT(KFileExtension, ".rsc"); |
|
202 _LIT(KFileLocation, "z:\\resource\\messaging\\"); |
|
203 |
|
204 TParse parser; |
|
205 User::LeaveIfError(parser.Set(KFileExtension, &aFileName, &KFileLocation)); |
|
206 |
|
207 |
|
208 aFileName = parser.FullName(); |
|
209 } |
|
210 |
|
211 |
|
212 #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT) |
|
213 //Code added for Preq557 |
|
214 //static |
|
215 TMsvId MsvUtils::UnmaskTMsvId(TMsvId aMaskedId) |
|
216 { |
|
217 return (aMaskedId & KDriveMask); |
|
218 } |
|
219 |
|
220 |
|
221 //static |
|
222 TUint MsvUtils::GetDriveId(TMsvId aMaskedId) |
|
223 { |
|
224 TUint driveId = ( (aMaskedId & ~KDriveMask) >> 28); |
|
225 if(0 == driveId) |
|
226 { |
|
227 return KCurrentDriveId; |
|
228 } |
|
229 return driveId; |
|
230 } |
|
231 |
|
232 |
|
233 //static |
|
234 TBool MsvUtils::IsStandardId(TMsvId aId) |
|
235 { |
|
236 if(UnmaskTMsvId(aId) < KMsvUnkownServiceIndexEntryIdValue && |
|
237 UnmaskTMsvId(aId) > KMsvLocalServiceIndexEntryIdValue) |
|
238 { |
|
239 return ETrue; |
|
240 } |
|
241 return EFalse; |
|
242 } |
|
243 |
|
244 |
|
245 //static |
|
246 TMsvId MsvUtils::MaskTMsvId(TUint aDriveId, TMsvId aUnmaskedId) |
|
247 { |
|
248 return (UnmaskTMsvId(aUnmaskedId) | (aDriveId << 28)); |
|
249 } |
|
250 |
|
251 |
|
252 #endif |