|
1 /* |
|
2 * Copyright (c) 2008 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: Provides System properties such as Memory Card drive name. |
|
15 * Paths to specific system properties based on the device. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #include <f32file.h> |
|
22 #include <driveinfo.h> |
|
23 #include <pathinfo.h> |
|
24 |
|
25 #include "logger.h" |
|
26 |
|
27 #include "javasymbianoslayer.h" |
|
28 |
|
29 #include "systempropertyprovider.h" |
|
30 #include "com_nokia_mj_impl_file_FileConstants.h" |
|
31 |
|
32 using namespace java::file; |
|
33 |
|
34 _LIT(KSystemDir, "system"); |
|
35 _LIT(KPrivateDir, "private"); |
|
36 _LIT(KSeparator, "\\"); |
|
37 _LIT(KColon, ":"); |
|
38 |
|
39 void SystemPropertyProvider::GetMemoryCardPath(TFileName& aPath) |
|
40 { |
|
41 TChar drive; |
|
42 DriveInfo::GetDefaultDrive(DriveInfo::EDefaultRemovableMassStorage, drive); |
|
43 aPath.Append(drive); |
|
44 aPath.Append(KColon); |
|
45 aPath.Append(KSeparator); |
|
46 } |
|
47 |
|
48 void SystemPropertyProvider::GetTemporaryDrive(TFileName& aPath) |
|
49 { |
|
50 TChar drive; |
|
51 DriveInfo::GetDefaultDrive(DriveInfo::EDefaultRam, drive); |
|
52 aPath.Append(drive); |
|
53 aPath.Append(KColon); |
|
54 aPath.Append(KSeparator); |
|
55 } |
|
56 |
|
57 void SystemPropertyProvider::GetDefaultRoot(TFileName& aPath) |
|
58 { |
|
59 TChar drive; |
|
60 DriveInfo::GetDefaultDrive(DriveInfo::EDefaultPhoneMemory, drive); |
|
61 aPath.Append(drive); |
|
62 aPath.Append(KColon); |
|
63 aPath.Append(KSeparator); |
|
64 } |
|
65 |
|
66 void SystemPropertyProvider::GetRomDrive(TFileName& aPath) |
|
67 { |
|
68 TChar drive; |
|
69 DriveInfo::GetDefaultDrive(DriveInfo::EDefaultRom, drive); |
|
70 aPath.Append(drive); |
|
71 aPath.Append(KColon); |
|
72 aPath.Append(KSeparator); |
|
73 } |
|
74 |
|
75 void SystemPropertyProvider::GetPathOfProperty(TInt aProperty, |
|
76 TFileName& aPath, TBool aAddRoot) |
|
77 { |
|
78 if ((aProperty |
|
79 != com_nokia_mj_impl_file_FileConstants_MEMORY_CARD_PROPERTY) |
|
80 && aAddRoot) |
|
81 { |
|
82 aPath = PathInfo::PhoneMemoryRootPath(); |
|
83 } |
|
84 |
|
85 switch (aProperty) |
|
86 { |
|
87 case com_nokia_mj_impl_file_FileConstants_PHOTOS_PROPERTY: |
|
88 { |
|
89 aPath.Append(PathInfo::ImagesPath()); |
|
90 return; |
|
91 } |
|
92 case com_nokia_mj_impl_file_FileConstants_VIDEOS_PROPERTY: |
|
93 { |
|
94 aPath.Append(PathInfo::VideosPath()); |
|
95 return; |
|
96 } |
|
97 case com_nokia_mj_impl_file_FileConstants_GRAPHICS_PROPERTY: |
|
98 { |
|
99 aPath.Append(PathInfo::GmsPicturesPath()); |
|
100 return; |
|
101 } |
|
102 case com_nokia_mj_impl_file_FileConstants_TONES_PROPERTY: |
|
103 { |
|
104 aPath.Append(PathInfo::SoundsPath()); |
|
105 return; |
|
106 } |
|
107 case com_nokia_mj_impl_file_FileConstants_MUSIC_PROPERTY: |
|
108 { |
|
109 aPath.Append(PathInfo::SoundsPath()); |
|
110 return; |
|
111 } |
|
112 case com_nokia_mj_impl_file_FileConstants_RECORDINGS_PROPERTY: |
|
113 { |
|
114 aPath.Append(PathInfo::DigitalSoundsPath()); |
|
115 return; |
|
116 } |
|
117 case com_nokia_mj_impl_file_FileConstants_MEMORY_CARD_PROPERTY: |
|
118 { |
|
119 GetMemoryCardPath(aPath); |
|
120 return; |
|
121 } |
|
122 default: |
|
123 { |
|
124 aPath = NULL; |
|
125 } |
|
126 } |
|
127 } |
|
128 |
|
129 void SystemPropertyProvider::GetRestrictedPathsL(HBufC*& aRetBuf) |
|
130 { |
|
131 JELOG2(EJavaFile); |
|
132 |
|
133 TChar separator = '*'; |
|
134 TInt drive; |
|
135 |
|
136 aRetBuf = HBufC::New(KMaxFileName); |
|
137 TPtr16 pointer(aRetBuf->Des()); |
|
138 RBuf16 buf(aRetBuf); |
|
139 |
|
140 // Create the default path structure for default phone memory |
|
141 DriveInfo::GetDefaultDrive(DriveInfo::EDefaultPhoneMemory, drive); |
|
142 |
|
143 CDesCArray* paths = 0; |
|
144 paths = PathInfo::GetListOfPathsLC(drive); |
|
145 |
|
146 TInt count(paths->MdcaCount()); |
|
147 for (TInt i = 1; i < count; ++i) |
|
148 { |
|
149 TPtrC16 prt = paths->MdcaPoint(i); |
|
150 buf.Append(prt); |
|
151 buf.Append(separator); |
|
152 } |
|
153 buf.ZeroTerminate(); |
|
154 CleanupStack::PopAndDestroy(paths); |
|
155 } |
|
156 |
|
157 void SystemPropertyProvider::GetForbiddenPaths(HBufC*& aRetBuf) |
|
158 { |
|
159 // Note: Memory allocation can be improved. This can be done in future |
|
160 // release of S60 where we better string manipulation utils are expected. |
|
161 |
|
162 // System/private need to be added |
|
163 aRetBuf = HBufC::NewMax(KMaxFileName * 26); |
|
164 |
|
165 TDriveList driveList; |
|
166 TChar driveChar; |
|
167 TChar colon = ':'; |
|
168 TChar separator = '*'; |
|
169 TChar slash = '/'; |
|
170 |
|
171 RFs session; |
|
172 int err = session.Connect(); |
|
173 |
|
174 if (KErrNone == err) |
|
175 { |
|
176 err = session.DriveList(driveList); |
|
177 if (KErrNone == err) |
|
178 { |
|
179 (aRetBuf->Des()).Zero(); |
|
180 for (TInt driveNumber = EDriveA; driveNumber <= EDriveZ; driveNumber++) |
|
181 { |
|
182 if (driveNumber == EDriveC) |
|
183 { |
|
184 continue; |
|
185 } |
|
186 |
|
187 if (driveList[driveNumber]) |
|
188 { |
|
189 err = session.DriveToChar(driveNumber, driveChar); |
|
190 if (KErrNone == err) |
|
191 { |
|
192 // append system dir |
|
193 (aRetBuf->Des()).Append(driveChar); |
|
194 (aRetBuf->Des()).Append(colon); |
|
195 (aRetBuf->Des()).Append(slash); |
|
196 (aRetBuf->Des()).Append(KSystemDir); |
|
197 (aRetBuf->Des()).Append(separator); |
|
198 |
|
199 // append private dir |
|
200 (aRetBuf->Des()).Append(driveChar); |
|
201 (aRetBuf->Des()).Append(colon); |
|
202 (aRetBuf->Des()).Append(slash); |
|
203 (aRetBuf->Des()).Append(KPrivateDir); |
|
204 (aRetBuf->Des()).Append(separator); |
|
205 } |
|
206 } |
|
207 } |
|
208 } |
|
209 } |
|
210 session.Close(); |
|
211 } |