|
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: S60FileSystemUtilities |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <f32file.h> |
|
20 #include "logger.h" |
|
21 #include "jstringutils.h" |
|
22 #include "s60filesystemutilities.h" |
|
23 #include "fileutilities.h" |
|
24 |
|
25 using namespace java::fileutils; |
|
26 |
|
27 /* |
|
28 * Implementation of S60FileSystemUtilities.h |
|
29 * |
|
30 */ |
|
31 using namespace std; |
|
32 |
|
33 void S60FileSystemUtilities::GetAvailableSizeL(TInt64& aRetSize, |
|
34 TChar& aDriveChar) |
|
35 { |
|
36 JELOG2(EJavaFile); |
|
37 //Note: Uri type check is not needed here. |
|
38 TVolumeInfo volumeInfo; |
|
39 RFs iRFs; |
|
40 User::LeaveIfError(iRFs.Connect()); |
|
41 TInt drive = EDriveC; |
|
42 RFs::CharToDrive(aDriveChar, drive); |
|
43 |
|
44 // If it is not a valid root, return immediately |
|
45 int error = 0; |
|
46 if (RFs::IsValidDrive(drive)) |
|
47 { |
|
48 error = iRFs.Volume(volumeInfo, drive); |
|
49 } |
|
50 else |
|
51 { |
|
52 iRFs.Close(); |
|
53 User::Leave(KErrArgument); |
|
54 } |
|
55 |
|
56 if (KErrNone != error) |
|
57 { |
|
58 iRFs.Close(); |
|
59 User::Leave(error); |
|
60 } |
|
61 |
|
62 aRetSize = volumeInfo.iFree; |
|
63 iRFs.Close(); |
|
64 } |
|
65 |
|
66 /** |
|
67 * |
|
68 */ |
|
69 void S60FileSystemUtilities::GetUsedSizeL(TInt64& aRetSize, TChar& aDriveChar) |
|
70 { |
|
71 JELOG2(EJavaFile); |
|
72 //Note: Uri type check is not needed here. |
|
73 TVolumeInfo volumeInfo; |
|
74 RFs iRFs; |
|
75 User::LeaveIfError(iRFs.Connect()); |
|
76 TInt drive = EDriveC; |
|
77 RFs::CharToDrive(aDriveChar, drive); |
|
78 |
|
79 // If it is not a valid root, return immediately |
|
80 int error = 0; |
|
81 if (RFs::IsValidDrive(drive)) |
|
82 { |
|
83 error = iRFs.Volume(volumeInfo, drive); |
|
84 } |
|
85 else |
|
86 { |
|
87 iRFs.Close(); |
|
88 User::Leave(KErrArgument); |
|
89 } |
|
90 |
|
91 if (KErrNone != error) |
|
92 { |
|
93 iRFs.Close(); |
|
94 User::Leave(error); |
|
95 } |
|
96 |
|
97 aRetSize = volumeInfo.iSize - volumeInfo.iFree; |
|
98 iRFs.Close(); |
|
99 } |
|
100 |
|
101 void S60FileSystemUtilities::IsHiddenL(TBool& aIsHidden, const TDesC &aFile) |
|
102 { |
|
103 JELOG2(EJavaFile); |
|
104 RFs iRFs; |
|
105 User::LeaveIfError(iRFs.Connect()); |
|
106 TEntry entry; |
|
107 |
|
108 TInt length = aFile.Length(); |
|
109 |
|
110 HBufC* fileUrl = HBufC::NewL(length); |
|
111 *fileUrl = aFile; |
|
112 |
|
113 TPtr uriBufPtr(fileUrl->Des()); |
|
114 ReplaceCharacters(uriBufPtr, '/', '\\'); |
|
115 |
|
116 User::LeaveIfError(iRFs.Entry(uriBufPtr, entry)); |
|
117 aIsHidden = entry.IsHidden(); |
|
118 iRFs.Close(); |
|
119 |
|
120 delete fileUrl; //allocated on heap, so deleting it |
|
121 } |
|
122 |
|
123 void S60FileSystemUtilities::GetTotalSizeL(TInt64& aRetSize, TChar& aDriveChar) |
|
124 { |
|
125 JELOG2(EJavaFile); |
|
126 //Note: Uri type check is not needed here. |
|
127 TVolumeInfo volumeInfo; |
|
128 RFs iRFs; |
|
129 User::LeaveIfError(iRFs.Connect()); |
|
130 TInt drive = EDriveC; |
|
131 RFs::CharToDrive(aDriveChar, drive); |
|
132 |
|
133 // If it is not a valid root, return immediately |
|
134 int error = 0; |
|
135 if (RFs::IsValidDrive(drive)) |
|
136 { |
|
137 error = iRFs.Volume(volumeInfo, drive); |
|
138 } |
|
139 else |
|
140 { |
|
141 iRFs.Close(); |
|
142 User::Leave(KErrArgument); |
|
143 } |
|
144 |
|
145 if (KErrNone != error) |
|
146 { |
|
147 iRFs.Close(); |
|
148 User::Leave(error); |
|
149 } |
|
150 aRetSize = volumeInfo.iSize; |
|
151 iRFs.Close(); |
|
152 } |
|
153 |
|
154 EXPORT_C void S60FileSystemUtilities::SetHiddenL(TDesC& aFile, TBool aHide) |
|
155 { |
|
156 JELOG2(EJavaFile); |
|
157 //Might need to close the file before attempting to change att. |
|
158 //need to verify it |
|
159 RFs iRFs; |
|
160 TInt err = KErrNone; |
|
161 User::LeaveIfError(iRFs.Connect()); |
|
162 |
|
163 HBufC* fileUrl = HBufC::NewL(aFile.Length()); |
|
164 *fileUrl = aFile; |
|
165 |
|
166 TPtr uriBufPtr(fileUrl->Des()); |
|
167 ReplaceCharacters(uriBufPtr, '/', '\\'); |
|
168 |
|
169 if (aHide) |
|
170 err = iRFs.SetAtt(uriBufPtr, KEntryAttHidden, 0); |
|
171 else |
|
172 err = iRFs.SetAtt(uriBufPtr, 0, KEntryAttHidden); |
|
173 |
|
174 iRFs.Close(); |
|
175 delete fileUrl; |
|
176 User::LeaveIfError(err); |
|
177 } |
|
178 |
|
179 void S60FileSystemUtilities::ReplaceCharacters(TPtr& aPtr, |
|
180 TUint8 aReplacedChar, TUint8 aNewChar) |
|
181 { |
|
182 ReplaceCharacters(aPtr, aReplacedChar, aNewChar, EFalse); |
|
183 } |
|
184 |
|
185 /** |
|
186 * |
|
187 */ |
|
188 void S60FileSystemUtilities::ReplaceCharacters(TPtr& aPtr, |
|
189 TUint8 aReplacedChar, TUint8 aNewChar, TBool aOnlyFirstMatch) |
|
190 { |
|
191 for (TInt i = 0; i < aPtr.Length(); ++i) |
|
192 { |
|
193 if (aReplacedChar == aPtr[i]) |
|
194 { |
|
195 aPtr[i] = aNewChar; |
|
196 if (aOnlyFirstMatch) |
|
197 return; |
|
198 } |
|
199 } |
|
200 } |
|
201 |
|
202 TDesC16& S60FileSystemUtilities::GetSupportedDrives() |
|
203 { |
|
204 JELOG2(EJavaFile); |
|
205 //TBuf16<80> driveString; |
|
206 HBufC* driveString = HBufC::NewMax(80); |
|
207 TDriveList driveList; |
|
208 TInt driveNumber = EDriveA; |
|
209 TChar driveChar; |
|
210 TChar colon = ':'; |
|
211 TChar separator = '*'; |
|
212 |
|
213 RFs session; |
|
214 int error = session.Connect(); |
|
215 if (KErrNone == error) |
|
216 { |
|
217 error = session.DriveList(driveList); |
|
218 if (KErrNone == error) |
|
219 { |
|
220 for (; driveNumber <= EDriveZ; driveNumber++) |
|
221 { |
|
222 if (driveList[driveNumber]) |
|
223 { |
|
224 session.DriveToChar(driveNumber, driveChar); |
|
225 (driveString->Des()).Append(driveChar); |
|
226 (driveString->Des()).Append(colon); |
|
227 (driveString->Des()).Append(separator); |
|
228 } |
|
229 } |
|
230 } |
|
231 } |
|
232 session.Close(); |
|
233 return *driveString; |
|
234 } |