
#include "common/stdafx.h"
#include "common/array.h"
#include "common/file.h"
#include "common/config-manager.h"
#include "common/util.h"

#include "tinsel/index.h"
#include "tinsel/features.h"

namespace Tinsel {

Index::Index(void) {
	IndexEntry ientry;
	Common::File file;
	int features = ConfMan.getInt("features");
	uint8 buf[8];
	uint8 buflen = 4;
	uint8 shift = 23;
	uint32 n = 0;
	uint32 size_flags;

	if(!file.open("index")) {
		error("failed to open INDEX");
		return;
	}

	if(features & GF_DW2) {
		buflen = 8;
		shift = 25;
	}

	while(file.read(ientry.filename, 12)) {
		size_flags = file.readUint32LE();

		// ignore size for now
		ientry.flags = (size_flags & 0xFF000000) >> 24;

		// read buffer and ignore
		file.read(buf, buflen);

		ientry.i_shifted = n << shift;

		debug(2, "INDEX: %-12s: %6dB 0x%02x 0x%08x", ientry.filename,
			size_flags & 0x00FFFFFF, ientry.flags, ientry.i_shifted);

		_index.push_back(ientry);

		n ++;
	}
}

Index::~Index() {
}

} // namespace Tinsel
