Example #1
0
BViewState::BViewState(BMallocIO* stream, bool endianSwap)
{
	_Init();
	stream->Read(&fViewMode, sizeof(uint32));
	stream->Read(&fLastIconMode, sizeof(uint32));
	stream->Read(&fListOrigin, sizeof(BPoint));
	stream->Read(&fIconOrigin, sizeof(BPoint));
	stream->Read(&fPrimarySortAttr, sizeof(uint32));
	stream->Read(&fPrimarySortType, sizeof(uint32));
	stream->Read(&fSecondarySortAttr, sizeof(uint32));
	stream->Read(&fSecondarySortType, sizeof(uint32));
	stream->Read(&fReverseSort, sizeof(bool));
	stream->Read(&fIconSize, sizeof(uint32));
	stream->Read(&fLastIconSize, sizeof(uint32));

	if (endianSwap) {
		PRINT(("endian swapping view state\n"));
		fViewMode = B_SWAP_INT32(fViewMode);
		fLastIconMode = B_SWAP_INT32(fLastIconMode);
		fIconSize = B_SWAP_INT32(fIconSize);
		fLastIconSize = B_SWAP_INT32(fLastIconSize);
		swap_data(B_POINT_TYPE, &fListOrigin,
			sizeof(fListOrigin), B_SWAP_ALWAYS);
		swap_data(B_POINT_TYPE, &fIconOrigin,
			sizeof(fIconOrigin), B_SWAP_ALWAYS);
		fPrimarySortAttr = B_SWAP_INT32(fPrimarySortAttr);
		fSecondarySortAttr = B_SWAP_INT32(fSecondarySortAttr);
		fPrimarySortType = B_SWAP_INT32(fPrimarySortType);
		fSecondarySortType = B_SWAP_INT32(fSecondarySortType);
	}

	_StorePreviousState();
	_Sanitize(this, true);
}
Example #2
0
BViewState::BViewState(BMallocIO *stream, bool endianSwap)
{
	stream->Read(&fViewMode, sizeof(uint32));
	stream->Read(&fLastIconMode, sizeof(uint32));
	stream->Read(&fListOrigin, sizeof(BPoint));
	stream->Read(&fIconOrigin, sizeof(BPoint));
	stream->Read(&fPrimarySortAttr, sizeof(uint32));
	stream->Read(&fPrimarySortType, sizeof(uint32));
	stream->Read(&fSecondarySortAttr, sizeof(uint32));
	stream->Read(&fSecondarySortType, sizeof(uint32));
	stream->Read(&fReverseSort, sizeof(bool));
	
	if (endianSwap) {
		PRINT(("endian swapping view state\n"));
		fViewMode = B_SWAP_INT32(fViewMode);
		fLastIconMode = B_SWAP_INT32(fLastIconMode);
		swap_data(B_POINT_TYPE, &fListOrigin, sizeof(fListOrigin), B_SWAP_ALWAYS);
		swap_data(B_POINT_TYPE, &fIconOrigin, sizeof(fIconOrigin), B_SWAP_ALWAYS);
		fPrimarySortAttr = B_SWAP_INT32(fPrimarySortAttr);
		fSecondarySortAttr = B_SWAP_INT32(fSecondarySortAttr);
		fPrimarySortType = B_SWAP_INT32(fPrimarySortType);
		fSecondarySortType = B_SWAP_INT32(fSecondarySortType);
	}
	fStateNeedsSaving = false;
}
Example #3
0
BColumn::BColumn(BMallocIO *stream, bool endianSwap)
{
	StringFromStream(&fTitle, stream, endianSwap);
	stream->Read(&fOffset, sizeof(float));
	stream->Read(&fWidth, sizeof(float));
	stream->Read(&fAlignment, sizeof(alignment));
	StringFromStream(&fAttrName, stream, endianSwap);
	stream->Read(&fAttrHash, sizeof(uint32));
	stream->Read(&fAttrType, sizeof(uint32));
	stream->Read(&fStatField, sizeof(bool));
	stream->Read(&fEditable, sizeof(bool));
	
	if (endianSwap) {
		PRINT(("endian swapping column\n"));
		fOffset = B_SWAP_FLOAT(fOffset);
		fWidth = B_SWAP_FLOAT(fWidth);
		STATIC_ASSERT(sizeof(BColumn::fAlignment) == sizeof(int32));
		fAlignment = (alignment)B_SWAP_INT32(fAlignment);
		fAttrHash = B_SWAP_INT32(fAttrHash);
		fAttrType = B_SWAP_INT32(fAttrType);
	}
}
Example #4
0
// _ReadHeader
void
ResourceFile::_ReadHeader()
{
	// read the header
	resources_header header;
	read_exactly(fFile, 0, &header, kResourcesHeaderSize,
				 "Failed to read the header.");
	// check the header
	// magic
	uint32 magic = _GetUInt32(header.rh_resources_magic);
	if (magic == kResourcesHeaderMagic) {
		// everything is fine
	} else if (B_SWAP_INT32(magic) == kResourcesHeaderMagic) {
		const char* endianessStr[2] = { "little", "big" };
		int32 endianess
			= (fHostEndianess == ((bool)B_HOST_IS_LENDIAN ? 0 : 1));
		Warnings::AddCurrentWarning("Endianess seems to be %s, although %s "
									"was expected.",
									endianessStr[1 - endianess],
									endianessStr[endianess]);
		fHostEndianess = !fHostEndianess;
	} else
		throw Exception("Invalid resources header magic.");
	// resource count
	uint32 resourceCount = _GetUInt32(header.rh_resource_count);
	if (resourceCount > kMaxResourceCount)
		throw Exception("Bad number of resources.");
	// index section offset
	uint32 indexSectionOffset = _GetUInt32(header.rh_index_section_offset);
	if (indexSectionOffset != kResourceIndexSectionOffset) {
		throw Exception("Unexpected resource index section offset. Is: %lu, "
						"should be: %lu.", indexSectionOffset,
						kResourceIndexSectionOffset);
	}
	// admin section size
	uint32 indexSectionSize = kResourceIndexSectionHeaderSize
							  + kResourceIndexEntrySize * resourceCount;
	indexSectionSize = align_value(indexSectionSize,
								   kResourceIndexSectionAlignment);
	uint32 adminSectionSize = _GetUInt32(header.rh_admin_section_size);
	if (adminSectionSize != indexSectionOffset + indexSectionSize) {
		throw Exception("Unexpected resource admin section size. Is: %lu, "
						"should be: %lu.", adminSectionSize,
						indexSectionOffset + indexSectionSize);
	}
	// set the resource count
	fResourceCount = resourceCount;
}
Example #5
0
// check_pattern
static
bool
check_pattern(uint32 byteOffset, void* _buffer, uint32 count,
			  bool hostEndianess)
{
	bool result = true;
	uint32* buffer = (uint32*)_buffer;
	for (uint32 i = 0; result && i < count; i++) {
		uint32 value = buffer[i];
		if (!hostEndianess)
			value = B_SWAP_INT32(value);
		result
			= (value == kUnusedResourceDataPattern[(byteOffset / 4 + i) % 3]);
	}
	return result;
}
Example #6
0
//------------------------------------------------------------------------------
uint32 _checksum_(const uchar* buf, int32 size)
{
	uint32 sum = 0;
	uint32 temp = 0;

	while (size > 3) {
#if defined(__INTEL__)
		sum += B_SWAP_INT32(*(int*)buf);
#else
		sum += *(int*)buf;
#endif

		buf += 4;
		size -= 4;
	}

	while (size > 0) {
		temp = (temp << 8) + *buf++;
		size -= 1;
		sum += temp;
	}

	return sum;
}
Example #7
0
static void
openpic_write(openpic_info *info, int reg, uint32 val)
{
	info->pci->write_io_32(info->device, info->virtual_registers + reg,
		B_SWAP_INT32(val));
}
Example #8
0
static uint32
openpic_read(openpic_info *info, int reg)
{
	return B_SWAP_INT32(info->pci->read_io_32(info->device,
		info->virtual_registers + reg));
}