00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef __MultiRead_H
00035 #define __MultiRead_H
00036
00037 class CMultipleResourceFileReader : public CBase
00038 {
00039 public:
00040
00041 ~CMultipleResourceFileReader();
00042 static CMultipleResourceFileReader* NewLC();
00043
00044 void AddResourceFileL(const TDesC& aName, TInt aVersion);
00045 HBufC8* AllocReadLC(TInt aResourceId);
00046 private:
00047
00048 void ConstructL();
00049 private:
00050 CArrayFixFlat<RResourceFile>* iResourceFiles;
00051 };
00052
00053
00054
00055 CMultipleResourceFileReader* CMultipleResourceFileReader::NewLC()
00056 {
00057 CMultipleResourceFileReader* self=new (ELeave) CMultipleResourceFileReader;
00058 CleanupStack::PushL(self);
00059 self->ConstructL();
00060 return self;
00061 }
00062
00063 void CMultipleResourceFileReader::ConstructL()
00064 {
00065 iResourceFiles=new (ELeave) CArrayFixFlat<RResourceFile> (2);
00066
00067
00068 }
00069
00070 CMultipleResourceFileReader::~CMultipleResourceFileReader()
00071 {
00072 if (iResourceFiles)
00073 {
00074 for (TInt i=0; i < iResourceFiles->Count(); i++)
00075 (*iResourceFiles)[i].Close();
00076 delete iResourceFiles;
00077 }
00078 }
00079
00080
00081
00082 void CMultipleResourceFileReader::AddResourceFileL(const TDesC& aName, TInt aVersion)
00083 {
00084 _LIT(KAddingResourceFile,"Adding resource file %S, version %d: will be file %d\n");
00085 console->Printf(KAddingResourceFile,
00086 &aName, aVersion, iResourceFiles->Count()
00087 );
00088 RResourceFile file;
00089 file.OpenL(fsSession,aName);
00090 TRAPD(error,file.ConfirmSignatureL(aVersion));
00091 if (error!=KErrNone)
00092 {
00093 file.Close();
00094 User::Leave(error);
00095 }
00096 TRAP(error,iResourceFiles->AppendL(file))
00097 if (error!=KErrNone)
00098 {
00099 file.Close();
00100 User::Leave(error);
00101 }
00102 return;
00103 }
00104
00105 HBufC8* CMultipleResourceFileReader::AllocReadLC(TInt aResourceId)
00106 {
00107 _LIT(KReadingResource,"Reading resource %08X\n");
00108 _LIT(KOwnedByFile," Owned by file %d\n");
00109
00110 console->Printf(KReadingResource,aResourceId);
00111 for (TInt i=0; i < iResourceFiles->Count(); i++)
00112 {
00113 RResourceFile& file=(*iResourceFiles)[i];
00114 if (!file.OwnsResourceId(aResourceId))
00115 continue;
00116 console->Printf(KOwnedByFile,i);
00117 return file.AllocReadLC(aResourceId);
00118
00119 }
00120 User::Leave(KErrNotFound);
00121 return 0;
00122 }
00123
00124 #endif