examples/SysLibs/ResourceFiles/MultiRead1/MultiRead.h

00001 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 // define the multiple resource file reader class
00015 // for use in MultiRead1 and MultiRead2 examples
00016 //
00017 
00018 #ifndef __MultiRead_H
00019 #define __MultiRead_H
00020 
00021 class CMultipleResourceFileReader : public CBase
00022         {
00023 public:
00024         // construct/destruct
00025         ~CMultipleResourceFileReader();
00026         static CMultipleResourceFileReader* NewLC();
00027         // add resource file
00028         void AddResourceFileL(const TDesC& aName, TInt aVersion);
00029         HBufC8* AllocReadLC(TInt aResourceId);
00030 private:
00031         // construct/destruct
00032         void ConstructL();
00033 private:
00034         CArrayFixFlat<RResourceFile>* iResourceFiles;
00035         };
00036 
00037 // construct/destruct
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                 // new array of resource files
00051                 // typically two in an application, so use granularity 2
00052         }
00053 
00054 CMultipleResourceFileReader::~CMultipleResourceFileReader()
00055         {
00056         if (iResourceFiles)
00057                 {
00058                 for (TInt i=0; i < iResourceFiles->Count(); i++)
00059                         (*iResourceFiles)[i].Close(); // close each resource file
00060                 delete iResourceFiles; // and destroy container
00061                 }
00062         }
00063 
00064 // manipulate resource files and resources
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); // open resource file
00074         TRAPD(error,file.ConfirmSignatureL(aVersion)); // confirm its signature
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                 { // scan all resource files to find owner
00097                 RResourceFile& file=(*iResourceFiles)[i]; // get resource file
00098                 if (!file.OwnsResourceId(aResourceId))
00099                         continue; // continue if not owner
00100                 console->Printf(KOwnedByFile,i);
00101                 return file.AllocReadLC(aResourceId);
00102                                 // return resource from owning file (if present)
00103                 }
00104         User::Leave(KErrNotFound);
00105         return 0; // can never be executed, but keeps compiler happy
00106         }
00107 
00108 #endif

Generated by  doxygen 1.6.2