|
1 /* |
|
2 * Copyright (c) 2002-2004 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: server implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32std.h> |
|
21 #include <e32base.h> |
|
22 #include <f32file.h> |
|
23 #include <drmcommon.h> |
|
24 |
|
25 #ifdef RD_MULTIPLE_DRIVE |
|
26 #include <DriveInfo.h> |
|
27 #endif |
|
28 |
|
29 #include "DcfRepSrv.h" |
|
30 #include "SearchLeaf.h" |
|
31 #include "FileScan.h" |
|
32 |
|
33 // EXTERNAL DATA STRUCTURES |
|
34 |
|
35 // EXTERNAL FUNCTION PROTOTYPES |
|
36 |
|
37 // CONSTANTS |
|
38 |
|
39 // MACROS |
|
40 |
|
41 // LOCAL CONSTANTS AND MACROS |
|
42 _LIT( KWma, ".wma" ); |
|
43 _LIT( KWmv, ".wmv" ); |
|
44 _LIT( KAsf, ".asf" ); |
|
45 |
|
46 #ifdef RD_MULTIPLE_DRIVE |
|
47 _LIT( KIgnoreDir1, "%c:\\sys" ); |
|
48 _LIT( KIgnoreDir2, "%c:\\private\\101F51F2" ); |
|
49 #else |
|
50 _LIT( KIgnoreDir1, "c:\\sys" ); |
|
51 _LIT( KIgnoreDir2, "c:\\private\\101F51F2" ); |
|
52 #endif |
|
53 |
|
54 // MODULE DATA STRUCTURES |
|
55 |
|
56 // LOCAL FUNCTION PROTOTYPES |
|
57 #ifndef RD_MULTIPLE_DRIVE |
|
58 LOCAL_C TBool IgnoreDir( TFileName& aDir ); |
|
59 #else // RD_MULTIPLE_DRIVE |
|
60 LOCAL_C TBool IgnoreDir( RFs& aFs, TFileName& aDir ); |
|
61 #endif |
|
62 // FORWARD DECLARATIONS |
|
63 |
|
64 // ============================ LOCAL FUNCTIONS ================================= |
|
65 |
|
66 // ------------------------------------------------------------------------------ |
|
67 // Returns whether directory should be ignored or not |
|
68 // ------------------------------------------------------------------------------ |
|
69 #ifndef RD_MULTIPLE_DRIVE |
|
70 LOCAL_C TBool IgnoreDir( TFileName& aDir ) |
|
71 { |
|
72 if ( !aDir.CompareF( KIgnoreDir1 ) || |
|
73 !aDir.CompareF( KIgnoreDir2 ) ) |
|
74 { |
|
75 return ETrue; |
|
76 } |
|
77 return EFalse; |
|
78 } |
|
79 #else // RD_MULTIPLE_DRIVE |
|
80 LOCAL_C TBool IgnoreDir( RFs& aFs, TFileName& aDir ) |
|
81 { |
|
82 TInt driveNumber( -1 ); |
|
83 TChar driveLetter; |
|
84 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
|
85 aFs.DriveToChar( driveNumber, driveLetter ); |
|
86 |
|
87 TFileName ignore1; |
|
88 TFileName ignore2; |
|
89 |
|
90 ignore1.Format( KIgnoreDir1, (TUint)driveLetter ); |
|
91 ignore2.Format( KIgnoreDir2, (TUint)driveLetter ); |
|
92 |
|
93 if ( !aDir.CompareF( ignore1 ) || |
|
94 !aDir.CompareF( ignore2 ) ) |
|
95 { |
|
96 return ETrue; |
|
97 } |
|
98 return EFalse; |
|
99 } |
|
100 #endif |
|
101 |
|
102 // ============================ MEMBER FUNCTIONS =============================== |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CFileScan::CFileScan |
|
106 // C++ default constructor can NOT contain any code, that |
|
107 // might leave. |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 CFileScan::CFileScan( RFs& aFs ) : |
|
111 CActive( CActive::EPriorityStandard ),iServer(NULL),iFs(&aFs),iCurrentLeaf(NULL) |
|
112 { |
|
113 CleanInternal(); |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CFileScan::ConstructL |
|
118 // Symbian 2nd phase constructor can leave. |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 void CFileScan::ConstructL() |
|
122 { |
|
123 TInt err = 0; |
|
124 if ( !iFs ) |
|
125 { |
|
126 err = KErrArgument; |
|
127 } |
|
128 else |
|
129 { |
|
130 err = KErrNone; |
|
131 } |
|
132 User::LeaveIfError( err ); |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CFileScan::NewL |
|
137 // Two-phased constructor. |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 CFileScan* CFileScan::NewL( RFs& aFs ) |
|
141 { |
|
142 CFileScan* self = new( ELeave ) CFileScan( aFs ); |
|
143 CleanupStack::PushL( self ); |
|
144 self->ConstructL(); |
|
145 CleanupStack::Pop(self); |
|
146 return self; |
|
147 } |
|
148 |
|
149 |
|
150 // Destructor |
|
151 CFileScan::~CFileScan() |
|
152 { |
|
153 CleanInternal(); |
|
154 iServer = NULL; |
|
155 iFs = NULL; |
|
156 } |
|
157 |
|
158 |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CFileScan::DoCancel |
|
162 // Function is called when the request is completed |
|
163 // (other items were commented in a header). |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 void CFileScan::DoCancel() |
|
167 { |
|
168 CleanInternal(); |
|
169 } |
|
170 |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CFileScan::IsProtected |
|
174 // Function returns whether the specific file is protected or not |
|
175 // (other items were commented in a header). |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 TInt CFileScan::IsProtected( const TDesC& aFileName , TBool& aIsDCF ) |
|
179 { |
|
180 TInt err = KErrNone; |
|
181 aIsDCF = EFalse; |
|
182 err = iServer->ProcessFile( aFileName , aIsDCF ); |
|
183 if ( err && err != KErrNoMemory ) |
|
184 { |
|
185 err = KErrNone; |
|
186 } |
|
187 return err; |
|
188 } |
|
189 |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CFileScan::RunL |
|
193 // Function is called when the request is completed |
|
194 // (other items were commented in a header). |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void CFileScan::RunL() |
|
198 { |
|
199 TInt err = KErrNone; |
|
200 if ( iSearching && iServer->State()!=EStateIdle ) |
|
201 { |
|
202 err = SearchNext(); |
|
203 if ( err == KErrCancel ) |
|
204 { |
|
205 err = KErrNone; |
|
206 } |
|
207 if ( !err ) |
|
208 { |
|
209 SetActive(); |
|
210 TRequestStatus* status = &iStatus; |
|
211 User::RequestComplete( status , err ); |
|
212 } |
|
213 } |
|
214 else |
|
215 { |
|
216 CleanInternal(); |
|
217 iServer->CompleteScanning(err); |
|
218 Deque(); |
|
219 } |
|
220 if ( err ) |
|
221 { |
|
222 CleanInternal(); |
|
223 iServer->CompleteScanning(err); |
|
224 Deque(); |
|
225 } |
|
226 } |
|
227 |
|
228 |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CFileScan::SearchContent |
|
232 // Function starts the active objects to search protected file through whole file system |
|
233 // (other items were commented in a header). |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 TInt CFileScan::SearchContent( CDcfRepSrv* aServer ) |
|
237 { |
|
238 TInt err = KErrNone; |
|
239 |
|
240 iServer = aServer; |
|
241 CActiveScheduler::Add( this ); |
|
242 |
|
243 iSearching = ETrue; |
|
244 err = SearchNext(); |
|
245 if ( err ) |
|
246 { |
|
247 return err; |
|
248 } |
|
249 SetActive(); |
|
250 TRequestStatus* status = &iStatus; |
|
251 User::RequestComplete( status , KErrNone ); |
|
252 return err; |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CFileScan::SearchDrive |
|
257 // This function searches for the DCF files on target device |
|
258 // (other items were commented in a header). |
|
259 // ----------------------------------------------------------------------------- |
|
260 // |
|
261 TInt CFileScan::SearchDrive() |
|
262 { |
|
263 _LIT( KDrive, "%c:"); |
|
264 TDriveList drivelist; |
|
265 TChar driveLetter; |
|
266 TInt driveNumber = EDriveA - 1; |
|
267 TInt err = KErrNone; |
|
268 |
|
269 #ifdef RD_MULTIPLE_DRIVE |
|
270 |
|
271 TInt ramDrive( -1 ); |
|
272 TInt romDrive( -1 ); |
|
273 |
|
274 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRam, ramDrive ); |
|
275 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, romDrive ); |
|
276 |
|
277 #endif |
|
278 |
|
279 err = iFs->DriveList( drivelist ); |
|
280 |
|
281 if ( iLastPosition != KNullDesC ) |
|
282 { |
|
283 driveLetter = iLastPosition[0]; |
|
284 err = iFs->CharToDrive( driveLetter, driveNumber ); |
|
285 } |
|
286 |
|
287 driveNumber++; |
|
288 |
|
289 for ( ; driveNumber < KMaxDrives ; driveNumber++ ) |
|
290 { |
|
291 |
|
292 #ifndef RD_MULTIPLE_DRIVE |
|
293 |
|
294 if ( driveNumber == EDriveD || driveNumber == EDriveZ ) |
|
295 { |
|
296 } |
|
297 |
|
298 #else // RD_MULTIPLE_DRIVE |
|
299 |
|
300 if ( driveNumber == ramDrive || driveNumber == romDrive ) |
|
301 { |
|
302 } |
|
303 |
|
304 #endif |
|
305 |
|
306 else if ( drivelist[driveNumber] ) |
|
307 { |
|
308 err = iFs->DriveToChar( driveNumber, driveLetter ); |
|
309 iLastPosition.Format( KDrive, (TUint)driveLetter ); |
|
310 iDeeper = ETrue; |
|
311 return err; |
|
312 } |
|
313 } |
|
314 CleanInternal(); |
|
315 return err; |
|
316 } |
|
317 |
|
318 |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // CFileScan::SearchFolder |
|
322 // This function create Leaves for the current leaf |
|
323 // (other items were commented in a header). |
|
324 // ----------------------------------------------------------------------------- |
|
325 // |
|
326 TInt CFileScan::SearchFolder( CDir*& aFolderList ) |
|
327 { |
|
328 TInt err = KErrNone; |
|
329 TRAP( err , iCurrentLeaf->SetLeafL( aFolderList ) ); |
|
330 return err; |
|
331 } |
|
332 |
|
333 // ----------------------------------------------------------------------------- |
|
334 // CFileScan::SearchFile |
|
335 // This function searches for the DCF files under specific folder |
|
336 // (other items were commented in a header). |
|
337 // ----------------------------------------------------------------------------- |
|
338 // |
|
339 TInt CFileScan::SearchFile( CDir*& aFileList ) |
|
340 { |
|
341 TInt err = KErrNone; |
|
342 TInt i = 0; |
|
343 TBool isDCF; |
|
344 _LIT ( KFullFileName , "%S\\%S"); |
|
345 TFileName fileName; |
|
346 |
|
347 for ( ; i < aFileList->Count() && !err ; i++ ) |
|
348 { |
|
349 if (!( *aFileList )[i].IsDir()) |
|
350 { |
|
351 TPtrC extension = (*aFileList)[i].iName.Right( 4 ); |
|
352 if( !extension.CompareF( KWma ) || |
|
353 !extension.CompareF( KWmv ) || |
|
354 !extension.CompareF( KAsf ) ) |
|
355 { |
|
356 |
|
357 } |
|
358 else |
|
359 { |
|
360 fileName.Format( KFullFileName , &iLastPosition , &( *aFileList )[i].iName ); |
|
361 err = IsProtected( fileName , isDCF ); |
|
362 } |
|
363 } |
|
364 } |
|
365 return err; |
|
366 } |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // CFileScan::SearchNext |
|
370 // This function searches for the DCF files under specific folder or drive |
|
371 // (other items were commented in a header). |
|
372 // ----------------------------------------------------------------------------- |
|
373 // |
|
374 TInt CFileScan::SearchNext() |
|
375 { |
|
376 TInt err = KErrNone; |
|
377 |
|
378 err = CheckDrive(); |
|
379 if ( !err && iSearching ) |
|
380 { |
|
381 if ( iDeeper ) |
|
382 { |
|
383 err = CheckFolder(); |
|
384 } |
|
385 if ( !err && iSearching ) |
|
386 { |
|
387 err = ToNextLeaf(); |
|
388 } |
|
389 } |
|
390 return err; |
|
391 } |
|
392 |
|
393 TInt CFileScan::CheckDrive() |
|
394 { |
|
395 // check if current drive is end of searching |
|
396 TInt err = KErrNone; |
|
397 |
|
398 if( !iCurrentLeaf ) |
|
399 { |
|
400 err = SearchDrive(); |
|
401 if ( err || !iSearching ) |
|
402 { |
|
403 return err; |
|
404 } |
|
405 CSearchLeaf* root = NULL; |
|
406 TRAP( err , iCurrentLeaf = CSearchLeaf::NewL( root , iLastPosition ) ); |
|
407 } |
|
408 return err; |
|
409 } |
|
410 |
|
411 TInt CFileScan::CheckFolder() |
|
412 { |
|
413 // check current folder |
|
414 _LIT ( KSearchDir , "%S\\*"); |
|
415 |
|
416 TInt err = KErrNone; |
|
417 CDir* fileList = NULL; |
|
418 CDir* dirList = NULL; |
|
419 TFileName temp; |
|
420 |
|
421 #ifndef RD_MULTIPLE_DRIVE |
|
422 if ( IgnoreDir( iLastPosition ) ) |
|
423 #else // RD_MULTIPLE_DRIVE |
|
424 if ( IgnoreDir( *iFs, iLastPosition ) ) |
|
425 #endif |
|
426 { |
|
427 return err; |
|
428 } |
|
429 |
|
430 if( iLastPosition.Length() + KSearchDir().Length() < iLastPosition.MaxLength() ) |
|
431 { |
|
432 temp.Format( KSearchDir , &iLastPosition ); |
|
433 err = iFs->GetDir( temp |
|
434 , KEntryAttMaskSupported |
|
435 , ESortByName |
|
436 , fileList , dirList ); |
|
437 |
|
438 if ( !err ) |
|
439 { |
|
440 err = SearchFolder( dirList ); |
|
441 if ( !err ) |
|
442 { |
|
443 err = SearchFile( fileList ); |
|
444 } |
|
445 } |
|
446 delete fileList; |
|
447 fileList = NULL; |
|
448 delete dirList; |
|
449 dirList = NULL; |
|
450 } |
|
451 return err; |
|
452 } |
|
453 |
|
454 TInt CFileScan::ToNextLeaf() |
|
455 { |
|
456 _LIT ( KChildDir , "%S\\%S"); |
|
457 TInt err = KErrNone; |
|
458 TFileName file; |
|
459 CSearchLeaf* temp = NULL; |
|
460 |
|
461 file.Format( iLastPosition ); |
|
462 |
|
463 if ( iCurrentLeaf->LeafList().Count() > 0 ) |
|
464 { |
|
465 iDeeper = ETrue; |
|
466 iCurrentLeaf = iCurrentLeaf->LeafList()[0]; |
|
467 iLastPosition.Format( KChildDir , &file , &iCurrentLeaf->FolderName() ); |
|
468 } |
|
469 else |
|
470 { |
|
471 iDeeper = EFalse; |
|
472 temp = iCurrentLeaf; |
|
473 iCurrentLeaf = iCurrentLeaf->Root(); |
|
474 if ( iCurrentLeaf ) |
|
475 { |
|
476 iCurrentLeaf->RemoveLeaf( temp ); |
|
477 } |
|
478 delete temp; |
|
479 temp = NULL; |
|
480 err = UpFolder(); |
|
481 } |
|
482 return err; |
|
483 } |
|
484 |
|
485 TInt CFileScan::UpFolder() |
|
486 { |
|
487 TInt err = KErrNone; |
|
488 TParse file; |
|
489 if ( iLastPosition.Length()<3 ) |
|
490 { |
|
491 return err; |
|
492 } |
|
493 err = file.Set( iLastPosition , NULL , NULL ); |
|
494 iLastPosition.Format( file.DriveAndPath() ); |
|
495 iLastPosition.SetLength( iLastPosition.Length() - 1 ); |
|
496 return err; |
|
497 } |
|
498 |
|
499 |
|
500 void CFileScan::CleanInternal() |
|
501 { |
|
502 CSearchLeaf* root = iCurrentLeaf; |
|
503 iLastPosition = KNullDesC; |
|
504 iSearching = EFalse; |
|
505 root = GetRootLeaf(); |
|
506 delete root; |
|
507 root = NULL; |
|
508 iCurrentLeaf = NULL; |
|
509 iDeeper = ETrue; |
|
510 } |
|
511 |
|
512 CSearchLeaf* CFileScan::GetRootLeaf() |
|
513 { |
|
514 CSearchLeaf* root = iCurrentLeaf; |
|
515 if ( iCurrentLeaf ) |
|
516 { |
|
517 while ( root->Root() ) |
|
518 { |
|
519 root = root->Root(); |
|
520 } |
|
521 } |
|
522 return root; |
|
523 } |
|
524 |
|
525 // End of File |
|
526 |