1 /* |
|
2 * Copyright (c) 2008-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 "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: Utility for thumbnail tasks handling files |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 * @internal reviewed 31/07/2007 by Simon Brooks |
|
22 */ |
|
23 |
|
24 #include "glxtnfileutility.h" |
|
25 #include "glxscreenresolutions.h" |
|
26 #include <glxtracer.h> |
|
27 #include <glxpanic.h> |
|
28 #include <glxthumbnailinfo.h> |
|
29 #include <pathinfo.h> |
|
30 #include <s32file.h> |
|
31 |
|
32 _LIT(KGlxBadFileList, "glxbadfilelist.dat"); |
|
33 _LIT(KGlxBadFileMarker, "glxbadfilemarker.dat"); |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // Constructor |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CGlxtnFileUtility::CGlxtnFileUtility() |
|
40 { |
|
41 TRACER("CGlxtnFileUtility::CGlxtnFileUtility()"); |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // ConstructL |
|
46 // Symbian 2nd phase constructor can leave. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 void CGlxtnFileUtility::ConstructL() |
|
50 { |
|
51 TRACER("CGlxtnFileUtility::ConstructL()"); |
|
52 User::LeaveIfError(iFs.Connect()); |
|
53 |
|
54 iFs.PrivatePath(iBadFileDir); |
|
55 iBadFileDir.Insert( |
|
56 0, PathInfo::PhoneMemoryRootPath().Left( KMaxDriveName ) ); |
|
57 |
|
58 TRAP_IGNORE(ReadBadFileListL()); |
|
59 |
|
60 iPersistentSizeClasses.AppendL( |
|
61 TSize(KGlxThumbnailSmallWidth, KGlxThumbnailSmallHeight)); |
|
62 iPersistentSizeClasses.AppendL( |
|
63 TSize(KGlxThumbnailLargeWidth, KGlxThumbnailLargeHeight)); |
|
64 iPersistentSizeClasses.AppendL( |
|
65 TSize(KGlxThumbnailPortraitWidth, KGlxThumbnailPortraitHeight)); |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // NewL |
|
70 // Two-phased constructor. |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CGlxtnFileUtility* CGlxtnFileUtility::NewL() |
|
74 { |
|
75 TRACER("CGlxtnFileUtility::NewL()"); |
|
76 CGlxtnFileUtility* self = new (ELeave) CGlxtnFileUtility; |
|
77 |
|
78 CleanupStack::PushL(self); |
|
79 self->ConstructL(); |
|
80 CleanupStack::Pop(); |
|
81 |
|
82 return self; |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // Destructor |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 CGlxtnFileUtility::~CGlxtnFileUtility() |
|
90 { |
|
91 TRACER("CGlxtnFileUtility::~CGlxtnFileUtility()"); |
|
92 iFs.Close(); |
|
93 iBadFileArray.ResetAndDestroy(); |
|
94 iPersistentSizeClasses.Close(); |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // FsSession |
|
99 // Provide file server session for opening images from files. |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 RFs& CGlxtnFileUtility::FsSession() |
|
103 { |
|
104 TRACER("RFs& CGlxtnFileUtility::FsSession()"); |
|
105 return iFs; |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CheckBadFileListL |
|
110 // Test whether a file is on the bad file list. If not the bad file marker |
|
111 // is set to the filename, so that if a panic occurs it will be added to the |
|
112 // bad file list. |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 void CGlxtnFileUtility::CheckBadFileListL(const TDesC& aFilename) |
|
116 { |
|
117 TRACER("0CGlxtnFileUtility::CheckBadFileListL(const TDesC& aFilename)"); |
|
118 for ( TInt i = 0; i < iBadFileArray.Count(); i++ ) |
|
119 { |
|
120 if ( 0 == iBadFileArray[i]->CompareF(aFilename) ) |
|
121 { |
|
122 // File is bad |
|
123 User::Leave( KErrCorrupt ); |
|
124 } |
|
125 } |
|
126 |
|
127 // Set bad file marker |
|
128 TPath path(iBadFileDir); |
|
129 path.Append(KGlxBadFileMarker); |
|
130 |
|
131 // Ensure directory exists |
|
132 TInt err = iFs.MkDirAll(path); |
|
133 if ( err != KErrAlreadyExists ) |
|
134 { |
|
135 User::LeaveIfError(err); |
|
136 } |
|
137 |
|
138 RFileWriteStream stream; |
|
139 CleanupClosePushL(stream); |
|
140 User::LeaveIfError(stream.Replace( |
|
141 iFs, path, EFileWrite | EFileShareExclusive)); |
|
142 stream << aFilename; |
|
143 stream.CommitL(); |
|
144 CleanupStack::PopAndDestroy(&stream); |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // ClearBadFileMarker |
|
149 // Clear the bad file marker. Called when processing a file is complete (no |
|
150 // panic occurred). |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 void CGlxtnFileUtility::ClearBadFileMarker() |
|
154 { |
|
155 TRACER("void CGlxtnFileUtility::ClearBadFileMarker()"); |
|
156 TPath path(iBadFileDir); |
|
157 path.Append(KGlxBadFileMarker); |
|
158 |
|
159 ( void )iFs.Delete( path ); // Ignore error |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // IsPersistentSize |
|
164 // Test whether a generated thumbnail should be stored in persistent storage. |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 TBool CGlxtnFileUtility::IsPersistentSize(const TSize& aSize) |
|
168 { |
|
169 TRACER("CGlxtnFileUtility::IsPersistentSize()"); |
|
170 for ( TInt i = 0; i < iPersistentSizeClasses.Count(); i++ ) |
|
171 { |
|
172 if ( iPersistentSizeClasses[i] == aSize ) |
|
173 { |
|
174 return ETrue; |
|
175 } |
|
176 } |
|
177 |
|
178 return EFalse; |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // ReadBadFileListL |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 void CGlxtnFileUtility::ReadBadFileListL() |
|
186 { |
|
187 TRACER("void CGlxtnFileUtility::ReadBadFileListL()"); |
|
188 TPath pathList(iBadFileDir); |
|
189 pathList.Append(KGlxBadFileList); |
|
190 TPath pathMarker(iBadFileDir); |
|
191 pathMarker.Append(KGlxBadFileMarker); |
|
192 |
|
193 RFileReadStream stream; |
|
194 CleanupClosePushL(stream); |
|
195 |
|
196 // Check bad file list |
|
197 if ( KErrNone == stream.Open( |
|
198 iFs, pathList, EFileRead | EFileShareReadersOnly) ) |
|
199 { |
|
200 TInt err; |
|
201 // Loop until end of file |
|
202 do |
|
203 { |
|
204 TRAP(err, |
|
205 HBufC* file = HBufC::NewLC(stream, KMaxTInt); |
|
206 iBadFileArray.AppendL(file); |
|
207 CleanupStack::Pop(file); |
|
208 ) |
|
209 } while ( KErrNone == err ); |
|
210 |
|
211 stream.Close(); |
|
212 // NOTE: We always get KErrEof even if the file is corrupted |
|
213 } |
|
214 |
|
215 // Check bad file marker |
|
216 if ( KErrNone == stream.Open( |
|
217 iFs, pathMarker, EFileRead | EFileShareReadersOnly) ) |
|
218 { |
|
219 // File exists, file in marker must be bad |
|
220 HBufC* file = HBufC::NewLC(stream, KMaxTInt); |
|
221 iBadFileArray.AppendL(file); |
|
222 CleanupStack::Pop(file); |
|
223 |
|
224 // Save the list for next gallery session |
|
225 // Recreate whole file in case existing file is corrupted |
|
226 WriteBadFileListL(); |
|
227 |
|
228 stream.Close(); |
|
229 ClearBadFileMarker(); |
|
230 } |
|
231 |
|
232 CleanupStack::Pop(&stream); // Stream already closed |
|
233 } |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // WriteBadFileListL |
|
237 // ----------------------------------------------------------------------------- |
|
238 // |
|
239 void CGlxtnFileUtility::WriteBadFileListL() |
|
240 { |
|
241 TRACER("void CGlxtnFileUtility::WriteBadFileListL()"); |
|
242 TPath path(iBadFileDir); |
|
243 path.Append(KGlxBadFileList); |
|
244 |
|
245 RFileWriteStream stream; |
|
246 CleanupClosePushL(stream); |
|
247 User::LeaveIfError(stream.Replace( |
|
248 iFs, path, EFileWrite | EFileShareExclusive)); |
|
249 |
|
250 for ( TInt i = 0; i < iBadFileArray.Count() ; i++ ) |
|
251 { |
|
252 stream << *iBadFileArray[i]; |
|
253 } |
|
254 stream.CommitL(); |
|
255 |
|
256 CleanupStack::PopAndDestroy(&stream); |
|
257 } |
|