|
1 /* |
|
2 * Copyright (c) 2005-2006 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: MnUtils class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <f32file.h> |
|
21 #include <barsc2.h> |
|
22 #include <barsread2.h> |
|
23 #include <bautils.h> |
|
24 |
|
25 #include "mnutils.h" |
|
26 |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 EXPORT_C void MnUtils::FindLocalizedResourceFileL( |
|
33 RFs& aFsSession, |
|
34 const TDesC& aRscFile, |
|
35 TFileName& aFileName ) |
|
36 { |
|
37 TFileName fileName( aRscFile ); |
|
38 |
|
39 TParse parse; |
|
40 parse.Set( aRscFile, NULL, NULL ); |
|
41 |
|
42 // look on system and given drives first |
|
43 BaflUtils::NearestLanguageFile( aFsSession, fileName ); |
|
44 |
|
45 const TInt KLangPartOfExtensionLen = 2; |
|
46 TBool found = ( fileName.Right( KLangPartOfExtensionLen ) != |
|
47 aRscFile.Right( KLangPartOfExtensionLen ) ); |
|
48 |
|
49 if ( !found ) |
|
50 { |
|
51 // look on other drives |
|
52 TDriveList drives; |
|
53 aFsSession.DriveList( drives ); |
|
54 |
|
55 for ( TInt drive = EDriveA; drive <= EDriveZ; drive++ ) |
|
56 { |
|
57 if ( drives[drive] && !( drives[drive] & KDriveAttRemote ) ) // avoid remote drives |
|
58 { |
|
59 TDriveInfo drvInfo; |
|
60 TInt err = aFsSession.Drive( drvInfo, drive ); |
|
61 |
|
62 if ( !err && drvInfo.iType != EMediaNotPresent ) |
|
63 { |
|
64 TChar drv; |
|
65 aFsSession.DriveToChar( drive, drv ); |
|
66 |
|
67 fileName.Zero(); |
|
68 fileName.Append( drv ); |
|
69 fileName.Append( KDriveDelimiter ); |
|
70 fileName.Append( parse.Path() ); |
|
71 fileName.Append( parse.NameAndExt() ); |
|
72 |
|
73 // look on c: and this drive |
|
74 BaflUtils::NearestLanguageFile( aFsSession, fileName ); |
|
75 |
|
76 const TInt KLangPartOfExtensionLen = 2; |
|
77 found = ( fileName.Right( KLangPartOfExtensionLen ) != |
|
78 aRscFile.Right( KLangPartOfExtensionLen ) ); |
|
79 if ( found ) break; |
|
80 } |
|
81 } |
|
82 } |
|
83 } |
|
84 |
|
85 if ( !found ) |
|
86 { |
|
87 // localized file not found, try using SC |
|
88 FindResourceFileL( aFsSession, aRscFile, fileName ); |
|
89 } |
|
90 |
|
91 aFileName.Copy( fileName ); |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 EXPORT_C void MnUtils::FindResourceFileL( |
|
98 RFs& aFsSession, |
|
99 const TDesC& aFilePathAndName, |
|
100 TFileName& aRscFile ) |
|
101 { |
|
102 TParse parse; |
|
103 parse.Set( aFilePathAndName, NULL, NULL ); |
|
104 |
|
105 TFindFile finder( aFsSession ); |
|
106 if ( finder.FindByDir( parse.NameAndExt(), parse.Path() ) == KErrNone ) |
|
107 { |
|
108 aRscFile.Copy( finder.File() ); |
|
109 } |
|
110 else |
|
111 { |
|
112 User::Leave( KErrNotFound ); |
|
113 } |
|
114 } |