imgtools/romtools/rofsbuild/r_romnode.h
changeset 0 044383f39525
child 590 360bd6b35136
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 /*
       
     2 * Copyright (c) 1995-2009 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 the License "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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __R_ROMNODE_H__
       
    20 #define __R_ROMNODE_H__
       
    21 
       
    22 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
       
    23 #include <fstream>
       
    24 #else //!__MSVCDOTNET__
       
    25 #include <fstream.h>
       
    26 #endif //__MSVCDOTNET__
       
    27 
       
    28 #include <e32std.h>
       
    29 #include "rofs.h"
       
    30 #include "e32image.h"
       
    31 #include "h_utl.h"
       
    32 
       
    33 const TUint KOverrideStack = 0x01;
       
    34 const TUint KOverrideHeapMin = 0x02;
       
    35 const TUint KOverrideHeapMax = 0x04;
       
    36 const TUint KOverrideRelocationAddress = 0x08;
       
    37 const TUint KOverrideUid1 = 0x10;
       
    38 const TUint KOverrideUid2 = 0x20;
       
    39 const TUint KOverrideUid3 = 0x40;
       
    40 const TUint KOverrideCallEntryPoint = 0x80;
       
    41 const TUint KOverrideNoCallEntryPoint = 0x100;
       
    42 const TUint KOverridePriority = 0x200;
       
    43 const TUint KOverrideStackReserve = 0x400;
       
    44 const TUint KOverrideKeepIAT = 0x800;
       
    45 const TUint KOverrideCapability = 0x1000;
       
    46 const TUint KOverrideFixed = 0x2000;
       
    47 const TUint KOverrideDllData  = 0x4000;
       
    48 const TUint KOverrideCodeUnpaged = 0x8000;
       
    49 const TUint KOverrideCodePaged = 0x10000;
       
    50 const TUint KOverrideDataUnpaged = 0x20000;
       
    51 const TUint KOverrideDataPaged = 0x40000;
       
    52 
       
    53 enum ECompression{
       
    54 	ECompressionUnknown=0,
       
    55 	ECompressionCompress=1,
       
    56 	ECompressionUncompress=2
       
    57 };
       
    58 
       
    59 const TInt KFileHidden = 0xFFFFFFFF;
       
    60 
       
    61 
       
    62 
       
    63 class TRomBuilderEntry;
       
    64 class RomFileStructure;
       
    65 class TRomNode
       
    66 	{
       
    67 public:
       
    68 	TRomNode(TText* aName, TRomBuilderEntry* aEntry=0);
       
    69 	~TRomNode();
       
    70 	void Destroy();
       
    71 
       
    72 	static inline TRomNode* FirstNode() { return TheFirstNode; };
       
    73 	inline TRomNode* NextNode() { return iNextNode; };
       
    74 	inline void SetNextNode(TRomNode* aNode) { iNextNode = aNode; };
       
    75 	inline TRomNode* Currentchild() const { return iChild; };
       
    76 	inline TRomNode* Currentsibling() const { return iSibling; };
       
    77 
       
    78 	void DisplayStructure(ostream* aOut);
       
    79 	TRomNode* FindInDirectory(TText *aName);
       
    80 	void AddFile(TRomNode *aChild);
       
    81 	TRomNode* NewSubDir(TText *aName);
       
    82 	TInt SetAtt(TText *anAttWord);
       
    83 	TInt SetAttExtra(TText *anAttWord, TRomBuilderEntry* aFile, enum EKeyword aKeyword);
       
    84 	inline void SetStackSize(TInt aValue);
       
    85 	inline void SetHeapSizeMin(TInt aValue);
       
    86 	inline void SetHeapSizeMax(TInt aValue);
       
    87 	inline void SetCapability(SCapabilitySet& aCapability);
       
    88 	inline void SetUid1(TInt aValue);
       
    89 	inline void SetUid2(TInt aValue);
       
    90 	inline void SetUid3(TInt aValue);
       
    91 	inline void SetPriority(TProcessPriority aValue);
       
    92 	inline void SetFixed();
       
    93 	inline void SetDllData();
       
    94 
       
    95 
       
    96 	TBool IsDirectory() const { return 0==iEntry; };
       
    97 	TBool IsFile() const { return 0!=iEntry; };
       
    98 
       
    99 	TInt CalculateDirectoryEntrySize( TInt& aDirectoryBlockSize,
       
   100 										    TInt& aFileBlockSize );
       
   101 
       
   102 	TInt CountFileAndDir(TInt& aFileCount, TInt& aDirCount);
       
   103 
       
   104 	TInt PlaceFile( TUint8* &aDest, TUint aOffset, TUint aMaxSize, CBytePair *aBPE );
       
   105 	TInt Place( TUint8* aDestBase );
       
   106 
       
   107 	TInt NameCpy(char* aDest, TUint8& aUnicodeLength );
       
   108 	TInt NameLengthUnicode() const;
       
   109 
       
   110 	void Rename(TRomNode *aOldParent, TRomNode* aNewParent, TText* aNewName);
       
   111 
       
   112 	TRofsEntry* RofsEntry() const { return iRofsEntry; };
       
   113 	void SetRofsEntry(TRofsEntry* aEntry);
       
   114 	inline void SetImagePosition( TInt aPosition ) { iImagePosition = aPosition; };
       
   115 	inline void SetFileBlockPosition( TInt aPosition ) { iFileBlockPosition = aPosition; };
       
   116 	
       
   117 	void AddNodeForSameFile(TRomNode* aPreviousNode, TRomBuilderEntry* aFile);
       
   118 
       
   119 	void CountDirectory(TInt& aFileCount, TInt& aDirCount);
       
   120 	TInt ProcessDirectory(RomFileStructure* aRFS);
       
   121 
       
   122 	TRomNode* CopyDirectory(TRomNode*& aLastExecutable);
       
   123 	void Alias(TRomNode* aNode);
       
   124 	
       
   125 	static void deleteTheFirstNode();
       
   126 	static void displayFlatList();
       
   127 	TInt FullNameLength(TBool aIgnoreHiddenAttrib = EFalse) const;
       
   128 	TInt GetFullName(char* aBuf, TBool aIgnoreHiddenAttrib = EFalse) const;
       
   129 	static void InitializeCount();
       
   130 	// Accessor Function.
       
   131     inline TRomNode* GetParent() const { return iParent; }
       
   132 
       
   133 private:
       
   134 	void Remove(TRomNode* aChild);
       
   135 	void Add(TRomNode* aChild);
       
   136 	void Clone(TRomNode* aOriginal);
       
   137 
       
   138 	TInt CalculateEntrySize() const;
       
   139 
       
   140 private:	
       
   141 	static TInt Count;			// seed for unique identifiers
       
   142 
       
   143 	// Flat linked list of TRomNode structures
       
   144 	static TRomNode*	TheFirstNode;
       
   145 	static TRomNode*	TheLastNode;
       
   146 	TRomNode* iNextNode;
       
   147 
       
   148 	TRomNode* iParent;
       
   149 	TRomNode* iSibling;
       
   150 	TRomNode* iChild;
       
   151 	TRomNode* iNextNodeForSameFile;
       
   152 
       
   153 protected:
       
   154 	TInt iIdentifier;
       
   155 	TRofsEntry* iRofsEntry;		// in ROM image buffer
       
   156 
       
   157 	TInt	iTotalDirectoryBlockSize;	// calculated size of directory block
       
   158 	TInt	iTotalFileBlockSize;		// calculated size of file block
       
   159 
       
   160 
       
   161 	TInt iImagePosition;		// position of directory entry in image
       
   162 	TInt iFileBlockPosition;	// position of directory file block in image
       
   163 
       
   164 	friend class FileEntry;
       
   165 
       
   166 public:
       
   167 	TText* iName;
       
   168 	TUint8 iAtt;
       
   169 	TUint8 iAttExtra;
       
   170 	TBool iHidden;
       
   171 	TRomBuilderEntry* iEntry;		// represents file data
       
   172 	TUint	iFileStartOffset;		// position in image of start of file
       
   173 	TInt iSize;			        // size of associated file
       
   174 
       
   175 	// Override values
       
   176 	TInt iStackSize;
       
   177 	TInt iHeapSizeMin;
       
   178 	TInt iHeapSizeMax;
       
   179 	SCapabilitySet iCapability;
       
   180 	TInt iUid1;
       
   181 	TInt iUid2;
       
   182 	TInt iUid3;
       
   183 	TProcessPriority iPriority;
       
   184 
       
   185 	TInt iOverride;
       
   186 	TBool iFileUpdate;
       
   187   bool iAlias;
       
   188   // for a ROM image, all the files have a default read-only attribute, but in data drive, files's default attribute should be 0 
       
   189 	static TUint8 sDefaultInitialAttr ;
       
   190 	};
       
   191 
       
   192 
       
   193 
       
   194 class DllDataEntry;
       
   195 class TRomBuilderEntry
       
   196 	{
       
   197 public:
       
   198 	TRomBuilderEntry(const char *aFileName, TText *aName);
       
   199 	~TRomBuilderEntry();
       
   200 	void SetRomNode(TRomNode* aNode);
       
   201 	TRofsEntry* RofsEntry() const {return iRomNode->RofsEntry(); };
       
   202 	TInt PlaceFile( TUint8* &aDest, TUint aMaxSize, CBytePair *aBPE );
       
   203 
       
   204 	inline TInt RealFileSize() const { return iRealFileSize; };
       
   205 	inline void SetRealFileSize(TInt aFileSize) { iRealFileSize=aFileSize;};
       
   206 	void DisplaySize(TPrintType aWhere);
       
   207 	
       
   208 private:
       
   209 	TRomBuilderEntry();
       
   210 	TRomBuilderEntry(const TRomBuilderEntry&);
       
   211 	const TRomBuilderEntry& operator==(const TRomBuilderEntry &);
       
   212 	DllDataEntry* iFirstDllDataEntry;
       
   213 
       
   214 public:
       
   215 	TText *iName;
       
   216 	char *iFileName;
       
   217 
       
   218 	TRomBuilderEntry* iNext;
       
   219 	TRomBuilderEntry* iNextInArea;
       
   220 	TBool iExecutable;
       
   221 	TBool iFileOffset; // offset of the file in ROM
       
   222 	TUint iCompressEnabled;
       
   223 	TUint8 iUids[sizeof(TCheckedUid)];
       
   224 	TBool iHidden;
       
   225   	DllDataEntry* GetFirstDllDataEntry() const;
       
   226 	void SetFirstDllDataEntry(DllDataEntry *aDllDataEntry);
       
   227 
       
   228 private:
       
   229 	TRomNode *iRomNode;
       
   230 	TInt	iRealFileSize;	
       
   231 	};
       
   232 
       
   233 
       
   234 inline void TRomNode::SetStackSize(TInt aValue)
       
   235 	{
       
   236 	iStackSize = aValue;
       
   237 	iOverride |= KOverrideStack;
       
   238 	}
       
   239 
       
   240 inline void TRomNode::SetHeapSizeMin(TInt aValue)
       
   241 	{
       
   242 	iHeapSizeMin = aValue;
       
   243 	iOverride |= KOverrideHeapMin;
       
   244 	}
       
   245 
       
   246 inline void TRomNode::SetHeapSizeMax(TInt aValue)
       
   247 	{
       
   248 	iHeapSizeMax = aValue;
       
   249 	iOverride |= KOverrideHeapMax;
       
   250 	}
       
   251 
       
   252 inline void TRomNode::SetCapability(SCapabilitySet& aCapability)
       
   253 	{
       
   254 	iCapability = aCapability;
       
   255 	iOverride |= KOverrideCapability;
       
   256 	}
       
   257 
       
   258 inline void TRomNode::SetUid1(TInt aValue)
       
   259 	{
       
   260 	iUid1 = aValue;
       
   261 	iOverride |= KOverrideUid1;
       
   262 	}
       
   263 
       
   264 inline void TRomNode::SetUid2(TInt aValue)
       
   265 	{
       
   266 	iUid2 = aValue;
       
   267 	iOverride |= KOverrideUid2;
       
   268 	}
       
   269 
       
   270 inline void TRomNode::SetUid3(TInt aValue)
       
   271 	{
       
   272 	iUid3 = aValue;
       
   273 	iOverride |= KOverrideUid3;
       
   274 	}
       
   275 
       
   276 inline void TRomNode::SetPriority(TProcessPriority aValue)
       
   277 	{
       
   278 	iPriority = aValue;
       
   279 	iOverride |= KOverridePriority;
       
   280 	}
       
   281 
       
   282 inline void TRomNode::SetFixed()
       
   283 	{
       
   284 	iOverride |= KOverrideFixed;
       
   285 	}
       
   286 inline void TRomNode::SetDllData()
       
   287 {
       
   288 	iOverride |= KOverrideDllData;
       
   289 }
       
   290 
       
   291 #endif