|
1 /* |
|
2 * Copyright (c) 2005 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 functions for finding resource files. |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <bautils.h> |
|
22 #include "EPos_PosLmFileFinder.h" |
|
23 |
|
24 // ================= MEMBER FUNCTIONS ======================= |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // PosLmFileFinder::ResourceFileL |
|
28 // |
|
29 // (other items were commented in a header). |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 EXPORT_C TInt PosLmFileFinder::ResourceFileL( |
|
33 TFileName* aFilename, |
|
34 RFs& aFileSession, |
|
35 const TDesC& aResourceFileName) |
|
36 { |
|
37 TInt ret = KErrNone; |
|
38 TBool fileFound = EFalse; |
|
39 |
|
40 |
|
41 // Check system drive first |
|
42 TInt sysDrive = KErrNotFound; |
|
43 if ( BaflUtils::GetSystemDrive( (TDriveNumber&) sysDrive ) == KErrNone ) |
|
44 { |
|
45 fileFound = IsResourceOnDriveL( sysDrive, aFilename, aFileSession, aResourceFileName ); |
|
46 } |
|
47 |
|
48 if (!fileFound) |
|
49 { |
|
50 TDriveList driveList; |
|
51 User::LeaveIfError(aFileSession.DriveList(driveList)); |
|
52 |
|
53 for ( TInt driveNumber = EDriveA; driveNumber <= EDriveZ && !fileFound; driveNumber++ ) |
|
54 { |
|
55 // Skip system drive because it has already been checked. |
|
56 if ( driveNumber == sysDrive ) |
|
57 { |
|
58 driveNumber++; |
|
59 } |
|
60 |
|
61 if ( driveList[driveNumber] && !( driveList[driveNumber] & KDriveAttRemote ) ) // avoid remote drives |
|
62 { |
|
63 TDriveInfo drvInfo; |
|
64 TInt err = aFileSession.Drive( drvInfo, driveNumber ); |
|
65 |
|
66 if ( !err && drvInfo.iType != EMediaNotPresent ) |
|
67 { |
|
68 fileFound = IsResourceOnDriveL(driveNumber, aFilename, aFileSession, aResourceFileName); |
|
69 } |
|
70 } |
|
71 } |
|
72 } |
|
73 |
|
74 // If no *.R0* file is found, look for the .rsc file |
|
75 if (!fileFound) |
|
76 { |
|
77 TParse parse; |
|
78 parse.Set( aResourceFileName, NULL, NULL ); |
|
79 |
|
80 TFindFile finder( aFileSession ); |
|
81 if ( finder.FindByDir( parse.NameAndExt(), parse.Path() ) == KErrNone ) |
|
82 { |
|
83 fileFound = ETrue; |
|
84 aFilename->Zero(); |
|
85 aFilename->Append( finder.File() ); |
|
86 } |
|
87 } |
|
88 |
|
89 if (!fileFound) |
|
90 { |
|
91 // Cannot find file on any drive |
|
92 ret = KErrNotFound; |
|
93 } |
|
94 |
|
95 return ret; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // PosLmFileFinder::IsResourceOnDriveL |
|
100 // |
|
101 // (other items were commented in a header). |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 TBool PosLmFileFinder::IsResourceOnDriveL( |
|
105 TInt aDrive, |
|
106 TFileName* aFilename, |
|
107 RFs& aFileSession, |
|
108 const TDesC& aResourceFileName) |
|
109 { |
|
110 TFileName* oldFilename = new (ELeave) TFileName(); |
|
111 CleanupStack::PushL(oldFilename); |
|
112 |
|
113 TDriveUnit unit(aDrive); |
|
114 aFilename->Copy(unit.Name()); |
|
115 aFilename->Append(aResourceFileName); |
|
116 oldFilename->Copy(*aFilename); |
|
117 BaflUtils::NearestLanguageFile(aFileSession, *aFilename); |
|
118 |
|
119 TBool fileFound = (aFilename->Compare(*oldFilename) != 0); |
|
120 |
|
121 CleanupStack::PopAndDestroy(oldFilename); |
|
122 |
|
123 return fileFound; |
|
124 } |
|
125 |
|
126 // End of File |