2 * Copyright 2002-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
5 #ifndef _RESOURCE_FILE_H
6 #define _RESOURCE_FILE_H
11 ResourceFile interface declaration.
15 #include <ByteOrder.h>
17 #include "OffsetFile.h"
21 struct PEFContainerHeader
;
31 struct resource_parse_info
;
32 class ResourcesContainer
;
37 \brief Represents a file capable of containing resources.
39 This class provides access to the resources of a file.
40 Basically a ResourceFile object can be set to a file, load infos for the
41 resources without loading their data (InitContainer()), read the data of
42 one (ReadResource()) or all resources (ReadResources()) and write all
43 resources to the file (WriteResources()).
45 Note, that the object does only provide the I/O functionality, it does
46 not store any information about the resources -- this is done via a
47 ResourcesContainer. We gain flexibility using this approach, since e.g.
48 a certain resource may be represented by more than one ResourceItem and
49 we can have as many ResourcesContainers for the resources as we like.
50 In particular it is nice, that at any time we can write an arbitrary set
51 of resources to the file.
53 \author <a href='mailto:bonefish@users.sf.net'>Ingo Weinhold</a>
60 virtual ~ResourceFile();
62 status_t
SetTo(BFile
* file
, bool clobber
= false);
64 status_t
InitCheck() const;
66 status_t
InitContainer(ResourcesContainer
& container
);
67 status_t
ReadResource(ResourceItem
& resource
,
69 status_t
ReadResources(ResourcesContainer
& container
,
71 status_t
WriteResources(ResourcesContainer
& container
);
74 void _InitFile(BFile
& file
, bool clobber
);
76 void _InitELFFile(BFile
& file
);
78 template<typename ElfHeader
, typename ElfProgramHeader
,
79 typename ElfSectionHeader
>
80 void _InitELFXFile(BFile
& file
, uint64 fileSize
);
82 void _InitPEFFile(BFile
& file
,
83 const PEFContainerHeader
& pefHeader
);
84 void _ReadHeader(resource_parse_info
& parseInfo
);
85 void _ReadIndex(resource_parse_info
& parseInfo
);
86 bool _ReadIndexEntry(resource_parse_info
& parseInfo
,
87 int32 index
, uint32 tableOffset
,
89 void _ReadInfoTable(resource_parse_info
& parseInfo
);
90 bool _ReadInfoTableEnd(const void* data
,
92 const void* _ReadResourceInfo(
93 resource_parse_info
& parseInfo
,
95 const resource_info
* info
, type_code type
,
98 status_t
_WriteResources(ResourcesContainer
& container
);
99 status_t
_MakeEmptyResourceFile();
101 inline int16
_GetInt(int16 value
) const;
102 inline uint16
_GetInt(uint16 value
) const;
103 inline int32
_GetInt(int32 value
) const;
104 inline uint32
_GetInt(uint32 value
) const;
105 inline int64
_GetInt(int64 value
) const;
106 inline uint64
_GetInt(uint64 value
) const;
112 bool fEmptyResources
;
117 ResourceFile::_GetInt(int16 value
) const
119 return fHostEndianess
? value
: (int16
)B_SWAP_INT16((uint16
)value
);
124 ResourceFile::_GetInt(uint16 value
) const
126 return fHostEndianess
? value
: B_SWAP_INT16(value
);
131 ResourceFile::_GetInt(int32 value
) const
133 return fHostEndianess
? value
: (int32
)B_SWAP_INT32((uint32
)value
);
138 ResourceFile::_GetInt(uint32 value
) const
140 return fHostEndianess
? value
: B_SWAP_INT32(value
);
145 ResourceFile::_GetInt(int64 value
) const
147 return fHostEndianess
? value
: (int64
)B_SWAP_INT64((uint64
)value
);
152 ResourceFile::_GetInt(uint64 value
) const
154 return fHostEndianess
? value
: B_SWAP_INT64(value
);
158 }; // namespace Storage
159 }; // namespace BPrivate
162 #endif // _RESOURCE_FILE_H