#pragma once
#include "BKDEDefines.h"

struct PARSE_RESULT
{
	ULONG nImageSize;
	ULONG nBaseOffset;
	IMAGE_TYPES imageOSType;
	bool bImageBootable;
	CString strName;

	PARSE_RESULT()
	{
		clear();
	}

	~PARSE_RESULT()
	{
		this->strName.Empty();
	}

	void clear(void)
	{
		this->nBaseOffset = this->nImageSize = 0;
		this->imageOSType = IMAGE_TYPE_UNKNOWN;
		this->bImageBootable = false;
		this->strName = _T("");
	}

	PARSE_RESULT(const PARSE_RESULT *src)
	{
		this->nImageSize = src->nImageSize;
		this->nBaseOffset = src->nBaseOffset;
		this->imageOSType = src->imageOSType;
		this->bImageBootable = src->bImageBootable;
		this->strName = src->strName;
	}

	PARSE_RESULT &operator = (const PARSE_RESULT &src)
	{
		this->nImageSize = src.nImageSize;
		this->nBaseOffset = src.nBaseOffset;
		this->imageOSType = src.imageOSType;
		this->bImageBootable = src.bImageBootable;
		this->strName = src.strName;
		return *this;
	}
};

class CBKParseImage
{
		static const char *strID_Andos;
		static const char *strID_DXDOS;
		static const char *strID_FAT12;
		static const char *strID_Aodos;
		static const char *strID_Nord;
		static const char *strID_Nord_Voland;
		static const char *strID_RT11;
		static const char *strID_RT11Q;
	public:
		CBKParseImage(void);
		~CBKParseImage(void);
		PARSE_RESULT    ParseImage(const CString &fname, ULONG nBaseOffset);

	protected:
		bool            charcompare(uint8_t a, uint8_t b);
		bool            substrfind(uint8_t *bufs, size_t len_bufs, uint8_t *buff, size_t len_buff);
		int             IsCSIDOS3(CFile *f, ULONG nBaseOffset, uint8_t *buf);
		int             IsRT11_old(CFile *f, ULONG nBaseOffset, uint8_t *buf);
		int             IsRT11(CFile *f, ULONG nBaseOffset, uint8_t *buf);
};

