|
1 // COEUTILS.CPP |
|
2 |
|
3 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 // All rights reserved. |
|
5 // This component and the accompanying materials are made available |
|
6 // under the terms of "Eclipse Public License v1.0" |
|
7 // which accompanies this distribution, and is available |
|
8 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 // |
|
10 // Initial Contributors: |
|
11 // Nokia Corporation - initial contribution. |
|
12 // |
|
13 // Contributors: |
|
14 // |
|
15 // Description: |
|
16 // |
|
17 |
|
18 #include <coeutils.h> |
|
19 #include <bautils.h> |
|
20 #include <coemain.h> |
|
21 #include "COETLS.H" |
|
22 |
|
23 _LIT( KResLPanicString, "RCoeResourceLoader: "); |
|
24 |
|
25 |
|
26 /** Tests whether a file exists. |
|
27 |
|
28 @param aFileName The file name to check. |
|
29 @return ETrue if the file exists, EFalse if it doesn't. |
|
30 @see BaflUtils::FileExists() */ |
|
31 EXPORT_C TBool ConeUtils::FileExists(const TDesC& aFileName) |
|
32 { // static |
|
33 return(BaflUtils::FileExists(TheCoe()->FsSession(),aFileName)); |
|
34 } |
|
35 |
|
36 /** Ensures a path exists. |
|
37 |
|
38 This function tests whether the path for the file given by aFileName exists, |
|
39 and creates it if it doesn't. The function does nothing if the path name |
|
40 already exists. |
|
41 |
|
42 @param aFileName The full path name to create. Any file name is ignored and |
|
43 may be omitted. |
|
44 @see RFs::MkDirAll() |
|
45 @see BaflUtils::EnsurePathExistsL() */ |
|
46 EXPORT_C void ConeUtils::EnsurePathExistsL(const TPtrC& aFileName) |
|
47 { // static |
|
48 BaflUtils::EnsurePathExistsL(TheCoe()->FsSession(),aFileName); |
|
49 } |
|
50 |
|
51 // |
|
52 // class RCoeResourceLoader |
|
53 // |
|
54 |
|
55 /** |
|
56 Constructor. |
|
57 @param aEnv is a reference to Control environment in which resource is loaded. |
|
58 */ |
|
59 EXPORT_C RCoeResourceLoader::RCoeResourceLoader(CCoeEnv& aEnv) |
|
60 : iEnv(aEnv), iResourceFileOffset(0) |
|
61 { |
|
62 } |
|
63 |
|
64 /** |
|
65 Opens the resource file for reading. Only one resource may be open at a time. |
|
66 Panics if this instance already has a file open. |
|
67 The implementation uses BaflUtils::NearestLanguageFile to search |
|
68 for a localized resource file in proper search order. |
|
69 |
|
70 @param aFileName is the resource file name to open. This parameter |
|
71 value is changed to the best matching language file found. The drive |
|
72 letter is required in the filename. |
|
73 @return a Symbian OS error code. |
|
74 @panic KErrNotSupported The instance already has a file open. |
|
75 */ |
|
76 EXPORT_C TInt RCoeResourceLoader::Open(TFileName& aFileName) |
|
77 { |
|
78 __ASSERT_ALWAYS(!iResourceFileOffset, User::Panic(KResLPanicString, KErrNotSupported) ); |
|
79 |
|
80 TRAPD(ret, OpenL(aFileName)); |
|
81 return ret; |
|
82 } |
|
83 |
|
84 /** |
|
85 Opens the resource file for reading. Only one resource may be open |
|
86 at a time. Leaves if this instance already has a file open. |
|
87 The implementation uses BaflUtils::NearestLanguageFile to search |
|
88 for a localized resource file in proper search order. |
|
89 |
|
90 @param aFileName Reference for resource file name. Note that drive letter is required. |
|
91 @leave KErrNotSupported The instance already has a file open. |
|
92 @panic CONE 15 The resource file has no NAME statement (i.e. has no offset). |
|
93 */ |
|
94 EXPORT_C void RCoeResourceLoader::OpenL(TFileName& aFileName) |
|
95 { |
|
96 __ASSERT_ALWAYS(!iResourceFileOffset, User::Leave(KErrNotSupported) ); |
|
97 BaflUtils::NearestLanguageFile(iEnv.FsSession(), aFileName); |
|
98 |
|
99 iResourceFileOffset = iEnv.AddResourceFileL(aFileName); |
|
100 } |
|
101 |
|
102 EXPORT_C void RCoeResourceLoader::Close() |
|
103 { |
|
104 if(iResourceFileOffset) |
|
105 { |
|
106 iEnv.DeleteResourceFile(iResourceFileOffset); |
|
107 iResourceFileOffset = 0; |
|
108 } |
|
109 } |