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