#include "stdafx.h"
#include "2HeaderInf.h"	// This header.

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/*************************************************************************
 * <_xZkqqHx_iDhHiDgCiDfPiDhEiDeAiDeDiDiLiMgAiOkO_xHqqkZx_>
 *
 *	CLSID/CLSID
 *	"MolipDraw.exe"/String
 *	_xZkqqHx_iDeBiDhGiDiKiDgPiBfLiDfHiDiHiDjD_xHqqkZx_/WORD  Major 5bit, Minor 5bit, LevelA 4bit, LevelB 2bit
 *	_xZkqqHx_iDhGiDiJiDgCiDgHiDhKiBfLiDiA_xHqqkZx_/BYTE  FDPL_WINDOWS
 *	_xZkqqHx_iDhEiDeAiDeDiDiLiDfOiDeDiDhG_xHqqkZx_/BYTE  FD_DTP_STANDARD_FORMAT/FD_DTP_PORTABLE_FORMAT/FD_DTP_TEMPLATE_FORMAT
 *	_xZkqqHx_iDhEiDeAiDeDiDiLiDgPiBfLiDfHiDiHiDjD_xHqqkZx_/WORD  Major 8bit, Minor 8bit
 *	_xZkqqHx_iNoMjAkMjDpK_xHqqkZx_/time_t
 *	_xZkqqHx_iNfIjAfGjDpK_xHqqkZx_/time_t
 *************************************************************************/

static const char*		s_cpAppName = "MolipDraw.exe";

// _xZkqqHx_iClBiCmM_xHqqkZx_ ID _xZkqqHx_iCmNiBeBiPiJjBoDiCmM_xHqqkZx_MolipDraw(FastDraw)_xZkqqHx_iNoMjAkMiOjOiCmJjAlGjAkMiClDiCoKiCnMiClFiClNiBeC_xHqqkZx_
// _xZkqqHx_iDgPiBfLiDfHiDiHiDjDiCkKiPoDiCkKiCmBiCmEiCoAjFmPiNfIiClFiCmEiCmNiCkCiCkPiCnMiClJiCpBiBeC_xHqqkZx_

// {DC96FFA0-119F-11D0-B80C-444553540000}
static const CLSID s_clsid =
{ 0xdc96ffa0, 0x119f, 0x11d0, { 0xb8, 0xc, 0x44, 0x45, 0x53, 0x54, 0x0, 0x0 } };


MC2HeaderInf::MC2HeaderInf ()
{
} // MC2HeaderInf::MC2HeaderInf.

MC2HeaderInf::~MC2HeaderInf ()
{
} // MC2HeaderInf::~MC2HeaderInf.

void MC2HeaderInf::InStream (MCARCHIVE& ar)
{
	CLSID 	clsid;			// CLSID_xZkqqHx_iBeC_xHqqkZx_
	char	szAppName[FD_MAX_APP_NAME + 1];	// _xZkqqHx_iDeBiDhGiDiKjGlMiBeC_xHqqkZx_
	WORD	wAppVersion;	// _xZkqqHx_iDeBiDhGiDiKiDgPiBfLiDfHiDiHiDjDiBeC_xHqqkZx_

	//----- CLSID_xZkqqHx_iCpAjDmHiCnNiNjOiCnO_xHqqkZx_ -----
	ar >> clsid;
	if (::memcmp(&s_clsid, &clsid, sizeof(s_clsid)))
	{
// 06.02.27 Fukushiro M. 1_xZkqqHx_iNhDjFmPiNfI_xHqqkZx_ ()
//		AfxThrowArchiveException(CArchiveException::badIndex, NULL);
		FFUtilErrI->ThrowMiscExceptionCode(FD_IDS_ERR_FILE_DESTROIED);
	}
	//----- _xZkqqHx_iDeBiDhGiDiKjGlMiCpAjDmHiCnNiNjOiCnO_xHqqkZx_ -----
	WORD wStrLen;
	ar >> wStrLen;
	if (FD_MAX_APP_NAME < wStrLen)
	{
// 06.02.27 Fukushiro M. 1_xZkqqHx_iNhDjFmPiNfI_xHqqkZx_ ()
//		AfxThrowArchiveException(CArchiveException::badIndex, NULL);
		FFUtilErrI->ThrowMiscExceptionCode(FD_IDS_ERR_FILE_DESTROIED);
	}

	ar.Read(szAppName, wStrLen);
	szAppName[wStrLen] = '\0';

	// _xZkqqHx_iDeBiDhGiDiKiDgPiBfLiDfHiDiHiDjDiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	ar >> wAppVersion;
	// _xZkqqHx_iDhGiDiJiDgCiDgHiDhKiBfLiDiAiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	ar >> m_byPlatform;
	// _xZkqqHx_iDhEiDeAiDeDiDiLiDfOiDeDiDhGiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	ar >> m_byFileType;
	// _xZkqqHx_iDhEiDeAiDeDiDiLiDgPiBfLiDfHiDiHiDjDiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	ar >> m_wFileVersion;
	// _xZkqqHx_iNoMjAkMjDpKiOjOiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	ar.Read(&m_tmCreate, sizeof(m_tmCreate));
	// _xZkqqHx_iNfIjAfGjDpKiOjOiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	ar.Read(&m_tmUpdate, sizeof(m_tmUpdate));
} // MC2HeaderInf::InStream.

void MC2HeaderInf::OutStream (MCARCHIVE& ar)
{
	// CLSID_xZkqqHx_iCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	ar << s_clsid;
	//----- _xZkqqHx_iDeBiDhGiDiKjGlMiCpAiPjBiCkLiPgPiClH_xHqqkZx_ -----
	WORD wStrLen = WORD(strlen(s_cpAppName));
	ar << wStrLen;
	ar.Write(s_cpAppName, wStrLen * sizeof(s_cpAppName[0]));
	// _xZkqqHx_iDeBiDhGiDiKiDgPiBfLiDfHiDiHiDjDiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	ar << GetStcAppVersion(3);
	// _xZkqqHx_iDhGiDiJiDgCiDgHiDhKiBfLiDiAiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	ar << m_byPlatform;
	// _xZkqqHx_iDhEiDeAiDeDiDiLiDfOiDeDiDhGiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	ar << m_byFileType;
	// _xZkqqHx_iDhEiDeAiDeDiDiLiDgPiBfLiDfHiDiHiDjDiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	ar << MajorMinorToVersion(3, 0);
	// _xZkqqHx_iNoMjAkMjDpKiOjOiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	ar.Write(&m_tmCreate, sizeof(m_tmCreate));
	// _xZkqqHx_iNfIjAfGjDpKiOjOiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	ar.Write(&m_tmUpdate, sizeof(m_tmUpdate));
} // MC2HeaderInf::OutStream.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	MC2HeaderInf::SetFileType
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iPgPjHmNiClHiCoJiDhEiDeAiDeDiDiLiMfOiCpAjAnNjCoIiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	df	:_xZkqqHx_iDhEiDeAiDeDiDiLiMfOiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.06.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void MC2HeaderInf::SetFileType (FTDocumentFormat df)
{
	m_byFileType = BYTE(df);
} // MC2HeaderInf::SetFileType.

WORD MC2HeaderInf::GetStcAppVersion (short nMajorVersion)
{
	static const char s_acAppLevelA = L'A';			// [A - P]
	static const char s_acAppLevelB = L'1';			// [1 - 4]
	union
	{
		WORD	wVersion;	// _xZkqqHx_iDeBiDhGiDiKiDgPiBfLiDfHiDiHiDjDiBeC_xHqqkZx_
		struct {
			WORD	wLevelB	: 2;	// _xZkqqHx_iDiMiDhIiDiLiCgBiBeC_xHqqkZx_
			WORD	wLevelA	: 4;	// _xZkqqHx_iDiMiDhIiDiLiCgAiBeC_xHqqkZx_
			WORD	wMinor	: 5;	// _xZkqqHx_iDhNiDeDiDgJiBfLiDgPiBfLiDfHiDiHiDjDiBeC_xHqqkZx_
			WORD	wMajor	: 5;	// _xZkqqHx_iDiBiDfHiDiDiBfLiDgPiBfLiDfHiDiHiDjDiBeC_xHqqkZx_
		};
	} ver;
	ver.wMajor  = nMajorVersion;
	ver.wMinor  = 0;
	ver.wLevelA = s_acAppLevelA - 'A';
	ver.wLevelB = s_acAppLevelB - '1';
	return ver.wVersion;
} // MC2HeaderInf::GetStcAppVersion.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	MC2HeaderInf::MajorMinorToVersion
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iJnPiLiOiCmMiDeBiDhGiDiKiCkKiNoMjAkMiClFiClNiDhEiDeAiDeDiDiLiCmMjDmBjCoIiCmMiDgPiBfLiDfHiDiHiDjDiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	wMajorVer	:_xZkqqHx_iDiBiDfHiDiDiBfLiDgPiBfLiDfHiDiHiDjDiCpAiOhHjCoIiBeC_xHqqkZx_
 *			wMinorVer	:_xZkqqHx_iDhNiDeDiDgJiBfLiDgPiBfLiDfHiDiHiDjDiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iDhEiDeAiDeDiDiLiDgPiBfLiDfHiDiHiDjDiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iJpAjAoA_xHqqkZx_>	1.0_xZkqqHx_iBeB_xHqqkZx_2.x_xZkqqHx_iCmFiCmNiBeBiDiBiDfHiDiDiBfLiCmGiDhNiDeDiDgJiBfLiCkKiLhEjDfNiClFiCmEiCkCiCoJiBeC_xHqqkZx_
 *			_xZkqqHx_iClBiCoKiCmNiBeB_xHqqkZx_3.0_xZkqqHx_iCkJiCoHiDgPiBfLiDfHiDiHiDjDiCmMjBoFiPkMiCmFjEoEiKhCiCmFiCkLiCoJiCoGiCkEiCmJ_xHqqkZx_
 *			_xZkqqHx_iClHiCoJiClNiCnPiCmJiBeBiDiBiDfHiDiDiBfLiCmGiDhNiDeDiDgJiBfLiCmMiDhCiDgCiDgHjEhKjHpBiCpAiLhEiCmJ_xHqqkZx_
 *			_xZkqqHx_iClFiClNiClNiCnPiBeC_xHqqkZx_
 *
 *			_xZkqqHx_iJnPiLiOiCmM_xHqqkZx_Molip Draw_xZkqqHx_iCmMiDgPiBfLiDfHiDiHiDjDiCmMjBmOiJjOiCmNiImIiJlKiBeC_xHqqkZx_
 *								_xZkqqHx_iPoDiImK_xHqqkZx_8bit _xZkqqHx_iJlKiImK_xHqqkZx_8bit
 *			Molip Draw 1.0:			0		0
 *			Molip Draw 2.0:			0		2
 *			Molip Draw 3.0:			3		0
 *			Molip Draw 4.0:			4		0
 *			_xZkqqHx_iClBiCmMiClNiCnPiBeBiOmAiNnLiCmMiDiBiDfHiDiDiBfL_xHqqkZx_/_xZkqqHx_iDhNiDeDiDgJiBfLiDgPiBfLiDfHiDiHiDjDiCmG_xHqqkZx_
 *			_xZkqqHx_iIoBiCkEiDgPiBfLiDfHiDiHiDjDiBgJiImIiJlKiCmMiCoGiCkEiBgKiCmJjFmPiKlHiClHiCoJjFeLjHhGiCkKiCkAiCoJiBeC_xHqqkZx_
 *
 *			Molip Draw 1.0		Major	0
 *								Minor	0
 *			Molip Draw 2.x		Major	0
 *								Minor	2
 *			Dynamic Draw 3.x	Major	3
 *								Minor	0
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	01.06.17 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
WORD MC2HeaderInf::MajorMinorToVersion (WORD wMajorVer, WORD wMinorVer)
{
	union {
		WORD	wVersion;	// _xZkqqHx_iDhEiDeAiDeDiDiLiDgPiBfLiDfHiDiHiDjDiBeC_xHqqkZx_
		struct {
			WORD	wMinor	: 8;	// _xZkqqHx_iDhNiDeDiDgJiBfLiDgPiBfLiDfHiDiHiDjDiBeC_xHqqkZx_
			WORD	wMajor	: 8;	// _xZkqqHx_iDiBiDfHiDiDiBfLiDgPiBfLiDfHiDiHiDjDiBeC_xHqqkZx_
		};
	} ver;
	if (wMajorVer == 1)
	{
		ver.wMajor = 0;
		ver.wMinor = 0;
	} else
	if (wMajorVer == 2)
	{
		ver.wMajor = 0;
		ver.wMinor = 2;
	} else
	{
		ver.wMajor = wMajorVer;
		ver.wMinor = wMinorVer;
	}
	return ver.wVersion;
} // MC2HeaderInf::MajorMinorToVersion.

