* Style cleanup.
* Removed AutoDeleter class and use the shared one instead. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34244 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,31 +1,37 @@
|
||||
//----------------------------------------------------------------------
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//---------------------------------------------------------------------
|
||||
/*
|
||||
* Copyright 2002-2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _RESOURCE_FILE_H
|
||||
#define _RESOURCE_FILE_H
|
||||
|
||||
|
||||
/*!
|
||||
\file ResourceFile.h
|
||||
ResourceFile interface declaration.
|
||||
*/
|
||||
|
||||
#ifndef _RESOURCE_FILE_H
|
||||
#define _RESOURCE_FILE_H
|
||||
|
||||
#include <ByteOrder.h>
|
||||
|
||||
#include "OffsetFile.h"
|
||||
|
||||
|
||||
struct resource_info;
|
||||
struct PEFContainerHeader;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
namespace Storage {
|
||||
|
||||
|
||||
class Exception;
|
||||
struct MemArea;
|
||||
class ResourceItem;
|
||||
struct resource_parse_info;
|
||||
class ResourcesContainer;
|
||||
|
||||
|
||||
/*!
|
||||
\class ResourceFile
|
||||
\brief Represents a file capable of containing resources.
|
||||
@@ -58,21 +64,27 @@ public:
|
||||
status_t InitCheck() const;
|
||||
|
||||
status_t InitContainer(ResourcesContainer& container);
|
||||
status_t ReadResource(ResourceItem &resource, bool force = false);
|
||||
status_t ReadResources(ResourcesContainer &container, bool force = false);
|
||||
status_t ReadResource(ResourceItem& resource,
|
||||
bool force = false);
|
||||
status_t ReadResources(ResourcesContainer& container,
|
||||
bool force = false);
|
||||
status_t WriteResources(ResourcesContainer& container);
|
||||
|
||||
private:
|
||||
void _InitFile(BFile& file, bool clobber);
|
||||
void _InitELFFile(BFile& file);
|
||||
void _InitPEFFile(BFile &file, const PEFContainerHeader &pefHeader);
|
||||
void _InitPEFFile(BFile& file,
|
||||
const PEFContainerHeader& pefHeader);
|
||||
void _ReadHeader(resource_parse_info& parseInfo);
|
||||
void _ReadIndex(resource_parse_info& parseInfo);
|
||||
bool _ReadIndexEntry(resource_parse_info &parseInfo, int32 index,
|
||||
uint32 tableOffset, bool peekAhead);
|
||||
bool _ReadIndexEntry(resource_parse_info& parseInfo,
|
||||
int32 index, uint32 tableOffset,
|
||||
bool peekAhead);
|
||||
void _ReadInfoTable(resource_parse_info& parseInfo);
|
||||
bool _ReadInfoTableEnd(const void *data, int32 dataSize);
|
||||
const void *_ReadResourceInfo(resource_parse_info &parseInfo,
|
||||
bool _ReadInfoTableEnd(const void* data,
|
||||
int32 dataSize);
|
||||
const void* _ReadResourceInfo(
|
||||
resource_parse_info& parseInfo,
|
||||
const MemArea& area,
|
||||
const resource_info* info, type_code type,
|
||||
bool* readIndices);
|
||||
@@ -92,41 +104,37 @@ private:
|
||||
bool fEmptyResources;
|
||||
};
|
||||
|
||||
// _GetInt16
|
||||
inline
|
||||
int16
|
||||
|
||||
inline int16
|
||||
ResourceFile::_GetInt16(int16 value)
|
||||
{
|
||||
return (fHostEndianess ? value : B_SWAP_INT16(value));
|
||||
return fHostEndianess ? value : B_SWAP_INT16(value);
|
||||
}
|
||||
|
||||
// _GetUInt16
|
||||
inline
|
||||
uint16
|
||||
|
||||
inline uint16
|
||||
ResourceFile::_GetUInt16(uint16 value)
|
||||
{
|
||||
return (fHostEndianess ? value : B_SWAP_INT16(value));
|
||||
return fHostEndianess ? value : B_SWAP_INT16(value);
|
||||
}
|
||||
|
||||
// _GetInt32
|
||||
inline
|
||||
int32
|
||||
|
||||
inline int32
|
||||
ResourceFile::_GetInt32(int32 value)
|
||||
{
|
||||
return (fHostEndianess ? value : B_SWAP_INT32(value));
|
||||
return fHostEndianess ? value : B_SWAP_INT32(value);
|
||||
}
|
||||
|
||||
// _GetUInt32
|
||||
inline
|
||||
uint32
|
||||
|
||||
inline uint32
|
||||
ResourceFile::_GetUInt32(uint32 value)
|
||||
{
|
||||
return (fHostEndianess ? value : B_SWAP_INT32(value));
|
||||
return fHostEndianess ? value : B_SWAP_INT32(value);
|
||||
}
|
||||
|
||||
|
||||
}; // namespace Storage
|
||||
}; // namespace BPrivate
|
||||
|
||||
|
||||
#endif // _RESOURCE_FILE_H
|
||||
|
||||
|
||||
|
||||
@@ -1,33 +1,36 @@
|
||||
//----------------------------------------------------------------------
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//---------------------------------------------------------------------
|
||||
/*
|
||||
* Copyright 2002-2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
\file ResourceFile.cpp
|
||||
ResourceFile implementation.
|
||||
*/
|
||||
|
||||
|
||||
#include <ResourceFile.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <new>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Elf.h"
|
||||
#include "Exception.h"
|
||||
#include "Pef.h"
|
||||
#include "ResourceItem.h"
|
||||
#include "ResourcesContainer.h"
|
||||
#include "ResourcesDefs.h"
|
||||
//#include "Warnings.h"
|
||||
#include <AutoDeleter.h>
|
||||
|
||||
#include <Elf.h>
|
||||
#include <Exception.h>
|
||||
#include <Pef.h>
|
||||
#include <ResourceItem.h>
|
||||
#include <ResourcesContainer.h>
|
||||
#include <ResourcesDefs.h>
|
||||
//#include <Warnings.h>
|
||||
|
||||
using std::max;
|
||||
using std::min;
|
||||
using std::nothrow;
|
||||
|
||||
namespace BPrivate {
|
||||
namespace Storage {
|
||||
|
||||
|
||||
// ELF defs
|
||||
static const uint32 kMaxELFHeaderSize = sizeof(Elf32_Ehdr) + 32;
|
||||
static const char kELFFileMagic[4] = { 0x7f, 'E', 'L', 'F' };
|
||||
@@ -36,6 +39,7 @@ static const char kELFFileMagic[4] = { 0x7f, 'E', 'L', 'F' };
|
||||
static const uint32 kMaxResourceCount = 10000;
|
||||
static const uint32 kELFMaxResourceAlignment = 1024 * 1024 * 10; // 10 MB
|
||||
|
||||
|
||||
// recognized file types (indices into kFileTypeNames)
|
||||
enum {
|
||||
FILE_TYPE_UNKNOWN = 0,
|
||||
@@ -46,6 +50,7 @@ enum {
|
||||
FILE_TYPE_EMPTY = 5,
|
||||
};
|
||||
|
||||
|
||||
const char* kFileTypeNames[] = {
|
||||
"unknown",
|
||||
"x86 resource file",
|
||||
@@ -55,17 +60,17 @@ const char *kFileTypeNames[] = {
|
||||
"empty file",
|
||||
};
|
||||
|
||||
|
||||
// debugging
|
||||
//#define DBG(x) x
|
||||
#define DBG(x)
|
||||
#define OUT printf
|
||||
|
||||
|
||||
// helper functions/classes
|
||||
// #pragma mark - helper functions/classes
|
||||
|
||||
// read_exactly
|
||||
static
|
||||
void
|
||||
|
||||
static void
|
||||
read_exactly(BPositionIO& file, off_t position, void* buffer, size_t size,
|
||||
const char* errorMessage = NULL)
|
||||
{
|
||||
@@ -81,9 +86,8 @@ read_exactly(BPositionIO &file, off_t position, void *buffer, size_t size,
|
||||
}
|
||||
}
|
||||
|
||||
// write_exactly
|
||||
static
|
||||
void
|
||||
|
||||
static void
|
||||
write_exactly(BPositionIO& file, off_t position, const void* buffer,
|
||||
size_t size, const char* errorMessage = NULL)
|
||||
{
|
||||
@@ -99,18 +103,16 @@ write_exactly(BPositionIO &file, off_t position, const void *buffer,
|
||||
}
|
||||
}
|
||||
|
||||
// align_value
|
||||
|
||||
template<typename TV, typename TA>
|
||||
static inline
|
||||
TV
|
||||
static inline TV
|
||||
align_value(const TV& value, const TA& alignment)
|
||||
{
|
||||
return ((value + alignment - 1) / alignment) * alignment;
|
||||
}
|
||||
|
||||
// calculate_checksum
|
||||
static
|
||||
uint32
|
||||
|
||||
static uint32
|
||||
calculate_checksum(const void* data, uint32 size)
|
||||
{
|
||||
uint32 checkSum = 0;
|
||||
@@ -119,7 +121,7 @@ calculate_checksum(const void *data, uint32 size)
|
||||
const uint8* current = csData;
|
||||
for (; current < dataEnd; current += 4) {
|
||||
uint32 word = 0;
|
||||
int32 bytes = min(4L, (int32)(dataEnd - current));
|
||||
int32 bytes = std::min((int32)4, (int32)(dataEnd - current));
|
||||
for (int32 i = 0; i < bytes; i++)
|
||||
word = (word << 8) + current[i];
|
||||
checkSum += word;
|
||||
@@ -127,25 +129,22 @@ calculate_checksum(const void *data, uint32 size)
|
||||
return checkSum;
|
||||
}
|
||||
|
||||
// skip_bytes
|
||||
static inline
|
||||
const void*
|
||||
|
||||
static inline const void*
|
||||
skip_bytes(const void* buffer, int32 offset)
|
||||
{
|
||||
return (const char*)buffer + offset;
|
||||
}
|
||||
|
||||
// skip_bytes
|
||||
static inline
|
||||
void*
|
||||
|
||||
static inline void*
|
||||
skip_bytes(void* buffer, int32 offset)
|
||||
{
|
||||
return (char*)buffer + offset;
|
||||
}
|
||||
|
||||
// fill_pattern
|
||||
static
|
||||
void
|
||||
|
||||
static void
|
||||
fill_pattern(uint32 byteOffset, void* _buffer, uint32 count)
|
||||
{
|
||||
uint32* buffer = (uint32*)_buffer;
|
||||
@@ -153,26 +152,23 @@ fill_pattern(uint32 byteOffset, void *_buffer, uint32 count)
|
||||
buffer[i] = kUnusedResourceDataPattern[(byteOffset / 4 + i) % 3];
|
||||
}
|
||||
|
||||
// fill_pattern
|
||||
static
|
||||
void
|
||||
|
||||
static void
|
||||
fill_pattern(const void* dataBegin, void* buffer, uint32 count)
|
||||
{
|
||||
fill_pattern((char*)buffer - (const char*)dataBegin, buffer, count);
|
||||
}
|
||||
|
||||
// fill_pattern
|
||||
static
|
||||
void
|
||||
|
||||
static void
|
||||
fill_pattern(const void* dataBegin, void* buffer, const void* bufferEnd)
|
||||
{
|
||||
fill_pattern(dataBegin, buffer,
|
||||
((const char*)bufferEnd - (char*)buffer) / 4);
|
||||
}
|
||||
|
||||
// check_pattern
|
||||
static
|
||||
bool
|
||||
|
||||
static bool
|
||||
check_pattern(uint32 byteOffset, void* _buffer, uint32 count,
|
||||
bool hostEndianess)
|
||||
{
|
||||
@@ -188,7 +184,10 @@ check_pattern(uint32 byteOffset, void *_buffer, uint32 count,
|
||||
return result;
|
||||
}
|
||||
|
||||
// MemArea
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
struct MemArea {
|
||||
MemArea(const void* data, uint32 size) : data(data), size(size) {}
|
||||
|
||||
@@ -203,26 +202,7 @@ struct MemArea {
|
||||
uint32 size;
|
||||
};
|
||||
|
||||
// AutoDeleter
|
||||
template<typename C>
|
||||
struct AutoDeleter {
|
||||
AutoDeleter(C *object, bool array = false) : object(object), array(array)
|
||||
{
|
||||
}
|
||||
|
||||
~AutoDeleter()
|
||||
{
|
||||
if (array)
|
||||
delete[] object;
|
||||
else
|
||||
delete object;
|
||||
}
|
||||
|
||||
C* object;
|
||||
bool array;
|
||||
};
|
||||
|
||||
// resource_parse_info
|
||||
struct resource_parse_info {
|
||||
off_t file_size;
|
||||
int32 resource_count;
|
||||
@@ -233,22 +213,25 @@ struct resource_parse_info {
|
||||
};
|
||||
|
||||
|
||||
// constructor
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
ResourceFile::ResourceFile()
|
||||
: fFile(),
|
||||
:
|
||||
fFile(),
|
||||
fFileType(FILE_TYPE_UNKNOWN),
|
||||
fHostEndianess(true),
|
||||
fEmptyResources(true)
|
||||
{
|
||||
}
|
||||
|
||||
// destructor
|
||||
|
||||
ResourceFile::~ResourceFile()
|
||||
{
|
||||
Unset();
|
||||
}
|
||||
|
||||
// SetTo
|
||||
|
||||
status_t
|
||||
ResourceFile::SetTo(BFile* file, bool clobber)
|
||||
{
|
||||
@@ -268,25 +251,24 @@ ResourceFile::SetTo(BFile *file, bool clobber)
|
||||
return error;
|
||||
}
|
||||
|
||||
// Unset
|
||||
|
||||
void
|
||||
ResourceFile::Unset()
|
||||
{
|
||||
// file
|
||||
fFile.Unset();
|
||||
fFileType = FILE_TYPE_UNKNOWN;
|
||||
fHostEndianess = true;
|
||||
fEmptyResources = true;
|
||||
}
|
||||
|
||||
// InitCheck
|
||||
|
||||
status_t
|
||||
ResourceFile::InitCheck() const
|
||||
{
|
||||
return fFile.InitCheck();
|
||||
}
|
||||
|
||||
// InitContainer
|
||||
|
||||
status_t
|
||||
ResourceFile::InitContainer(ResourcesContainer& container)
|
||||
{
|
||||
@@ -320,7 +302,7 @@ ResourceFile::InitContainer(ResourcesContainer &container)
|
||||
return error;
|
||||
}
|
||||
|
||||
// ReadResource
|
||||
|
||||
status_t
|
||||
ResourceFile::ReadResource(ResourceItem& resource, bool force)
|
||||
{
|
||||
@@ -349,7 +331,7 @@ ResourceFile::ReadResource(ResourceItem &resource, bool force)
|
||||
return error;
|
||||
}
|
||||
|
||||
// ReadResources
|
||||
|
||||
status_t
|
||||
ResourceFile::ReadResources(ResourcesContainer& container, bool force)
|
||||
{
|
||||
@@ -364,7 +346,7 @@ ResourceFile::ReadResources(ResourcesContainer &container, bool force)
|
||||
return error;
|
||||
}
|
||||
|
||||
// WriteResources
|
||||
|
||||
status_t
|
||||
ResourceFile::WriteResources(ResourcesContainer& container)
|
||||
{
|
||||
@@ -381,7 +363,6 @@ ResourceFile::WriteResources(ResourcesContainer &container)
|
||||
}
|
||||
|
||||
|
||||
// _InitFile
|
||||
void
|
||||
ResourceFile::_InitFile(BFile& file, bool clobber)
|
||||
{
|
||||
@@ -460,7 +441,7 @@ ResourceFile::_InitFile(BFile &file, bool clobber)
|
||||
}
|
||||
}
|
||||
|
||||
// _InitELFFile
|
||||
|
||||
void
|
||||
ResourceFile::_InitELFFile(BFile& file)
|
||||
{
|
||||
@@ -501,8 +482,7 @@ ResourceFile::_InitELFFile(BFile &file)
|
||||
// ELF header size
|
||||
if (headerSize < sizeof(Elf32_Ehdr) || headerSize > kMaxELFHeaderSize) {
|
||||
throw Exception(B_IO_ERROR,
|
||||
"Invalid ELF header: invalid ELF header size: %lu.",
|
||||
headerSize);
|
||||
"Invalid ELF header: invalid ELF header size: %lu.", headerSize);
|
||||
}
|
||||
uint32 resourceOffset = headerSize;
|
||||
uint32 resourceAlignment = 0;
|
||||
@@ -512,8 +492,7 @@ ResourceFile::_InitELFFile(BFile &file)
|
||||
if (programHeaderTableOffset < headerSize
|
||||
|| programHeaderTableOffset > fileSize) {
|
||||
throw Exception(B_IO_ERROR, "Invalid ELF header: invalid program "
|
||||
"header table offset: %lu.",
|
||||
programHeaderTableOffset);
|
||||
"header table offset: %lu.", programHeaderTableOffset);
|
||||
}
|
||||
programHeaderTableSize = programHeaderSize * programHeaderCount;
|
||||
if (programHeaderSize < sizeof(Elf32_Phdr)
|
||||
@@ -522,8 +501,8 @@ ResourceFile::_InitELFFile(BFile &file)
|
||||
"table exceeds file: %lu.",
|
||||
programHeaderTableOffset + programHeaderTableSize);
|
||||
}
|
||||
resourceOffset = max(resourceOffset, programHeaderTableOffset
|
||||
+ programHeaderTableSize);
|
||||
resourceOffset = std::max(resourceOffset,
|
||||
programHeaderTableOffset + programHeaderTableSize);
|
||||
// iterate through the program headers
|
||||
for (int32 i = 0; i < (int32)programHeaderCount; i++) {
|
||||
uint32 shOffset = programHeaderTableOffset + i * programHeaderSize;
|
||||
@@ -547,8 +526,8 @@ ResourceFile::_InitELFFile(BFile &file)
|
||||
throw Exception(B_IO_ERROR, "Invalid ELF section header: "
|
||||
"segment exceeds file: %lu.", segmentEnd);
|
||||
}
|
||||
resourceOffset = max(resourceOffset, segmentEnd);
|
||||
resourceAlignment = max(resourceAlignment, alignment);
|
||||
resourceOffset = std::max(resourceOffset, segmentEnd);
|
||||
resourceAlignment = std::max(resourceAlignment, alignment);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -558,8 +537,7 @@ ResourceFile::_InitELFFile(BFile &file)
|
||||
if (sectionHeaderTableOffset < headerSize
|
||||
|| sectionHeaderTableOffset > fileSize) {
|
||||
throw Exception(B_IO_ERROR, "Invalid ELF header: invalid section "
|
||||
"header table offset: %lu.",
|
||||
sectionHeaderTableOffset);
|
||||
"header table offset: %lu.", sectionHeaderTableOffset);
|
||||
}
|
||||
sectionHeaderTableSize = sectionHeaderSize * sectionHeaderCount;
|
||||
if (sectionHeaderSize < sizeof(Elf32_Shdr)
|
||||
@@ -568,8 +546,8 @@ ResourceFile::_InitELFFile(BFile &file)
|
||||
"table exceeds file: %lu.",
|
||||
sectionHeaderTableOffset + sectionHeaderTableSize);
|
||||
}
|
||||
resourceOffset = max(resourceOffset, sectionHeaderTableOffset
|
||||
+ sectionHeaderTableSize);
|
||||
resourceOffset = std::max(resourceOffset,
|
||||
sectionHeaderTableOffset + sectionHeaderTableSize);
|
||||
// iterate through the section headers
|
||||
for (int32 i = 0; i < (int32)sectionHeaderCount; i++) {
|
||||
uint32 shOffset = sectionHeaderTableOffset + i * sectionHeaderSize;
|
||||
@@ -593,7 +571,7 @@ ResourceFile::_InitELFFile(BFile &file)
|
||||
throw Exception(B_IO_ERROR, "Invalid ELF section header: "
|
||||
"section exceeds file: %lu.", sectionEnd);
|
||||
}
|
||||
resourceOffset = max(resourceOffset, sectionEnd);
|
||||
resourceOffset = std::max(resourceOffset, sectionEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -614,7 +592,7 @@ ResourceFile::_InitELFFile(BFile &file)
|
||||
fFile.SetTo(&file, resourceOffset);
|
||||
}
|
||||
|
||||
// _InitPEFFile
|
||||
|
||||
void
|
||||
ResourceFile::_InitPEFFile(BFile& file, const PEFContainerHeader& pefHeader)
|
||||
{
|
||||
@@ -653,7 +631,7 @@ ResourceFile::_InitPEFFile(BFile &file, const PEFContainerHeader &pefHeader)
|
||||
throw Exception(B_IO_ERROR, "Invalid PEF section header: section "
|
||||
"exceeds file: %lu.", sectionEnd);
|
||||
}
|
||||
resourceOffset = max(resourceOffset, sectionEnd);
|
||||
resourceOffset = std::max(resourceOffset, sectionEnd);
|
||||
}
|
||||
if (resourceOffset >= fileSize) {
|
||||
// throw Exception("The PEF object file does not contain resources.");
|
||||
@@ -664,7 +642,7 @@ ResourceFile::_InitPEFFile(BFile &file, const PEFContainerHeader &pefHeader)
|
||||
fFile.SetTo(&file, resourceOffset);
|
||||
}
|
||||
|
||||
// _ReadHeader
|
||||
|
||||
void
|
||||
ResourceFile::_ReadHeader(resource_parse_info& parseInfo)
|
||||
{
|
||||
@@ -714,7 +692,7 @@ ResourceFile::_ReadHeader(resource_parse_info &parseInfo)
|
||||
parseInfo.resource_count = resourceCount;
|
||||
}
|
||||
|
||||
// _ReadIndex
|
||||
|
||||
void
|
||||
ResourceFile::_ReadIndex(resource_parse_info& parseInfo)
|
||||
{
|
||||
@@ -792,7 +770,7 @@ ResourceFile::_ReadIndex(resource_parse_info &parseInfo)
|
||||
}
|
||||
}
|
||||
|
||||
// _ReadIndexEntry
|
||||
|
||||
bool
|
||||
ResourceFile::_ReadIndexEntry(resource_parse_info& parseInfo, int32 index,
|
||||
uint32 tableOffset, bool peekAhead)
|
||||
@@ -824,14 +802,14 @@ ResourceFile::_ReadIndexEntry(resource_parse_info &parseInfo, int32 index,
|
||||
// "table.");
|
||||
} else {
|
||||
throw Exception(B_IO_ERROR, "Invalid resource index entry: index: "
|
||||
"%ld, offset: %lu (%lx), size: %lu (%lx).",
|
||||
index + 1, offset, offset, size, size);
|
||||
"%ld, offset: %lu (%lx), size: %lu (%lx).", index + 1, offset,
|
||||
offset, size, size);
|
||||
}
|
||||
result = false;
|
||||
}
|
||||
// add the entry
|
||||
if (result) {
|
||||
ResourceItem *item = new(nothrow) ResourceItem;
|
||||
ResourceItem* item = new(std::nothrow) ResourceItem;
|
||||
if (!item)
|
||||
throw Exception(B_NO_MEMORY);
|
||||
item->SetLocation(offset, size);
|
||||
@@ -843,14 +821,14 @@ ResourceFile::_ReadIndexEntry(resource_parse_info &parseInfo, int32 index,
|
||||
return result;
|
||||
}
|
||||
|
||||
// _ReadInfoTable
|
||||
|
||||
void
|
||||
ResourceFile::_ReadInfoTable(resource_parse_info& parseInfo)
|
||||
{
|
||||
int32& resourceCount = parseInfo.resource_count;
|
||||
// read the info table
|
||||
// alloc memory for the table
|
||||
char *tableData = new(nothrow) char[parseInfo.info_table_size];
|
||||
char* tableData = new(std::nothrow) char[parseInfo.info_table_size];
|
||||
if (!tableData)
|
||||
throw Exception(B_NO_MEMORY);
|
||||
int32 dataSize = parseInfo.info_table_size;
|
||||
@@ -858,11 +836,11 @@ ResourceFile::_ReadInfoTable(resource_parse_info &parseInfo)
|
||||
read_exactly(fFile, parseInfo.info_table_offset, tableData, dataSize,
|
||||
"Failed to read resource info table.");
|
||||
//
|
||||
bool *readIndices = new(nothrow) bool[resourceCount + 1];
|
||||
bool* readIndices = new(std::nothrow) bool[resourceCount + 1];
|
||||
// + 1 => always > 0
|
||||
if (!readIndices)
|
||||
throw Exception(B_NO_MEMORY);
|
||||
AutoDeleter<bool> readIndicesDeleter(readIndices, true);
|
||||
ArrayDeleter<bool> readIndicesDeleter(readIndices);
|
||||
for (int32 i = 0; i < resourceCount; i++)
|
||||
readIndices[i] = false;
|
||||
MemArea area(tableData, dataSize);
|
||||
@@ -940,7 +918,7 @@ ResourceFile::_ReadInfoTable(resource_parse_info &parseInfo)
|
||||
}
|
||||
}
|
||||
|
||||
// _ReadInfoTableEnd
|
||||
|
||||
bool
|
||||
ResourceFile::_ReadInfoTableEnd(const void* data, int32 dataSize)
|
||||
{
|
||||
@@ -962,8 +940,8 @@ ResourceFile::_ReadInfoTableEnd(const void *data, int32 dataSize)
|
||||
uint32 fileCheckSum = _GetUInt32(tableEnd->rite_check_sum);
|
||||
if (checkSum != fileCheckSum) {
|
||||
throw Exception(B_IO_ERROR, "Invalid resource info table check"
|
||||
" sum: In file: %lx, calculated: %lx.",
|
||||
fileCheckSum, checkSum);
|
||||
" sum: In file: %lx, calculated: %lx.", fileCheckSum,
|
||||
checkSum);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -972,14 +950,13 @@ ResourceFile::_ReadInfoTableEnd(const void *data, int32 dataSize)
|
||||
return hasTableEnd;
|
||||
}
|
||||
|
||||
// _ReadResourceInfo
|
||||
|
||||
const void*
|
||||
ResourceFile::_ReadResourceInfo(resource_parse_info& parseInfo,
|
||||
const MemArea &area, const resource_info *info,
|
||||
type_code type, bool *readIndices)
|
||||
const MemArea& area, const resource_info* info, type_code type,
|
||||
bool* readIndices)
|
||||
{
|
||||
int32& resourceCount = parseInfo.resource_count;
|
||||
//
|
||||
int32 id = _GetInt32(info->ri_id);
|
||||
int32 index = _GetInt32(info->ri_index);
|
||||
uint16 nameSize = _GetUInt16(info->ri_name_size);
|
||||
@@ -1023,7 +1000,7 @@ ResourceFile::_ReadResourceInfo(resource_parse_info &parseInfo,
|
||||
return skip_bytes(name, nameSize);
|
||||
}
|
||||
|
||||
// _WriteResources
|
||||
|
||||
status_t
|
||||
ResourceFile::_WriteResources(ResourcesContainer& container)
|
||||
{
|
||||
@@ -1042,12 +1019,12 @@ ResourceFile::_WriteResources(ResourcesContainer &container)
|
||||
indexSectionSize = align_value(indexSectionSize,
|
||||
kResourceIndexSectionAlignment);
|
||||
size += indexSectionSize;
|
||||
bufferSize = max((uint32)bufferSize, indexSectionSize);
|
||||
bufferSize = std::max((uint32)bufferSize, indexSectionSize);
|
||||
// unknown section
|
||||
uint32 unknownSectionOffset = size;
|
||||
uint32 unknownSectionSize = kUnknownResourceSectionSize;
|
||||
size += unknownSectionSize;
|
||||
bufferSize = max((uint32)bufferSize, unknownSectionSize);
|
||||
bufferSize = std::max((uint32)bufferSize, unknownSectionSize);
|
||||
// data
|
||||
uint32 dataOffset = size;
|
||||
uint32 dataSize = 0;
|
||||
@@ -1056,7 +1033,7 @@ ResourceFile::_WriteResources(ResourcesContainer &container)
|
||||
if (!item->IsLoaded())
|
||||
throw Exception(B_IO_ERROR, "Resource is not loaded.");
|
||||
dataSize += item->DataSize();
|
||||
bufferSize = max(bufferSize, item->DataSize());
|
||||
bufferSize = std::max(bufferSize, item->DataSize());
|
||||
}
|
||||
size += dataSize;
|
||||
// info table
|
||||
@@ -1080,12 +1057,12 @@ ResourceFile::_WriteResources(ResourcesContainer &container)
|
||||
infoTableSize += kResourceInfoSeparatorSize
|
||||
+ kResourceInfoTableEndSize;
|
||||
size += infoTableSize;
|
||||
bufferSize = max((uint32)bufferSize, infoTableSize);
|
||||
bufferSize = std::max((uint32)bufferSize, infoTableSize);
|
||||
|
||||
// write...
|
||||
// set the file size
|
||||
fFile.SetSize(size);
|
||||
buffer = new(nothrow) char[bufferSize];
|
||||
buffer = new(std::nothrow) char[bufferSize];
|
||||
if (!buffer)
|
||||
throw Exception(B_NO_MEMORY);
|
||||
void* data = buffer;
|
||||
@@ -1215,7 +1192,7 @@ ResourceFile::_WriteResources(ResourcesContainer &container)
|
||||
return error;
|
||||
}
|
||||
|
||||
// _MakeEmptyResourceFile
|
||||
|
||||
status_t
|
||||
ResourceFile::_MakeEmptyResourceFile()
|
||||
{
|
||||
@@ -1248,7 +1225,3 @@ ResourceFile::_MakeEmptyResourceFile()
|
||||
|
||||
}; // namespace Storage
|
||||
}; // namespace BPrivate
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user