#include "stdafx.h"
#include "2UtilVersion.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  MD2_FDPL_WINDOWS
 *	_xZkqqHx_iDhEiDeAiDeDiDiLiDfOiDeDiDhG_xHqqkZx_/BYTE  MD2_FDFL_MOLIPDRAW/MD2_FDFL_HISTSPOT/MD2_FDFL_TEMPLATE
 *	_xZkqqHx_iDhEiDeAiDeDiDiLiDgPiBfLiDfHiDiHiDjD_xHqqkZx_/WORD  Major 8bit, Minor 8bit
 *	_xZkqqHx_iNoMjAkMjDpK_xHqqkZx_/time_t
 *	_xZkqqHx_iNfIjAfGjDpK_xHqqkZx_/time_t
 *************************************************************************/

static const _TCHAR*	s_tcpAppName = _T("MolipDraw.exe");

// _xZkqqHx_iClBiCmM_xHqqkZx_ ID _xZkqqHx_iCmNiBeBiPiJjBoDiCmM_xHqqkZx_MolipDraw(FastDraw)_xZkqqHx_iNoMjAkMiOjOiCmJjAlGjAkMiClDiCoKiCnMiClFiClNiBeC_xHqqkZx_

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

/////////////////////////////////////////////////////////////////////////////
// MC2HeaderInf_xZkqqHx_iDiBiDjDiDgPiKnGjAjEiBeC_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	MC2HeaderInf::MC2HeaderInf
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDhHiDgCiDfPiPoOjFpBiCmMiNfMjChKiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	99.06.02 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
MC2HeaderInf::MC2HeaderInf ()
{
} // MC2HeaderInf::MC2HeaderInf.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	MC2HeaderInf::InStream
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDhEiDeAiDeDiDiLiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	ar	:_xZkqqHx_jDmHiCnNiNjOiCnNjHhAiDeBiBfLiDeKiDeDiDhFiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.03.07 Fukushiro M. _xZkqqHx_iDfCiDiBiDjDiDgHiNoMjAkM_xHqqkZx_
 *************************************************************************/
void MC2HeaderInf::InStream (MC2ARCHIVE& ar)
{
	//----- CLSID_xZkqqHx_iCpAjDmHiCnNiNjOiCnO_xHqqkZx_ -----
	CLSID clsid;
	ar.Read(&clsid, sizeof(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);
	}
	//----- "MolipDraw.exe"_xZkqqHx_iCpAjDmHiCnNiNjOiCnO_xHqqkZx_ -----
	WORD wStrLen;
	ar >> wStrLen;
	TCHARVector tcvBuf(wStrLen + 1, _TCHAR('\0'));
	ar.Read(&tcvBuf.front(), wStrLen);
	if (_tcscmp(s_tcpAppName, &tcvBuf.front()) != 0)
	{
// 06.02.27 Fukushiro M. 1_xZkqqHx_iNhDjFmPiNfI_xHqqkZx_ ()
//		AfxThrowArchiveException(CArchiveException::badIndex, NULL);
		FFUtilErrI->ThrowMiscExceptionCode(FD_IDS_ERR_FILE_DESTROIED);
	}
	// _xZkqqHx_iDeBiDhGiDiKiDgPiBfLiDfHiDiHiDjDiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	ar >> m_wAppVersion;
	// _xZkqqHx_iDhGiDiJiDgCiDgHiDhKiBfLiDiAiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	ar >> m_byPlatform;
	// _xZkqqHx_iDhEiDeAiDeDiDiLiDfOiDeDiDhGiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	ar >> m_byFileType;
	// _xZkqqHx_iDhEiDeAiDeDiDiLiDgPiBfLiDfHiDiHiDjDiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	ar >> m_wFileVersion;
	// _xZkqqHx_iNoMjAkMjDpKiOjOiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	ar >> m_tmCreate;
	// _xZkqqHx_iNfIjAfGjDpKiOjOiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	ar >> m_tmUpdate;
} // MC2HeaderInf::InStream.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	MC2HeaderInf::OutStream
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDhEiDeAiDeDiDiLiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	ar	:_xZkqqHx_iPjBiCkLiPgPiClFjHhAiDeBiBfLiDeKiDeDiDhFiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.03.07 Fukushiro M. _xZkqqHx_iDfCiDiBiDjDiDgHiNoMjAkM_xHqqkZx_
 *************************************************************************/
void MC2HeaderInf::OutStream (MC2ARCHIVE& ar) const
{
	// CLSID_xZkqqHx_iCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	ar.Write(&s_clsid, sizeof(s_clsid));
	//----- "MolipDraw.exe"_xZkqqHx_iCpAiPjBiCkLiPgPiClH_xHqqkZx_ -----
	WORD wStrLen = WORD(_tcslen(s_tcpAppName));
	ar << wStrLen;
	ar.Write(s_tcpAppName, wStrLen);
	// _xZkqqHx_iDeBiDhGiDiKiDgPiBfLiDfHiDiHiDjDiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	ar << m_wAppVersion;
	// _xZkqqHx_iDhGiDiJiDgCiDgHiDhKiBfLiDiAiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	ar << m_byPlatform;
	// _xZkqqHx_iDhEiDeAiDeDiDiLiDfOiDeDiDhGiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	ar << m_byFileType;
	// _xZkqqHx_iDhEiDeAiDeDiDiLiDgPiBfLiDfHiDiHiDjDiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	ar << m_wFileVersion;
	// _xZkqqHx_iNoMjAkMjDpKiOjOiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	ar << m_tmCreate;
	// _xZkqqHx_iNfIjAfGjDpKiOjOiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
	ar << m_tmUpdate;
} // MC2HeaderInf::OutStream.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	MC2HeaderInf::GetFileVersion
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_jDmHiCnNiNjOiCnMiCoKiClNiBeBiMlLiNnNiCmMiDhEiDeAiDeDiDiLiCmMiDgPiBfLiDfHiDiHiDjDiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iDhEiDeAiDeDiDiLiDgPiBfLiDfHiDiHiDjDiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.08.01 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
WORD MC2HeaderInf::GetFileVersion () const
{
	return m_wFileVersion;
} // MC2HeaderInf::GetFileVersion.

/*************************************************************************
 * <_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.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	MC2HeaderInf::FileVersionToString
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDhEiDeAiDeDiDiLiDgPiBfLiDfHiDiHiDjDiCpAiBeBjBmOiJjOiClHiCoJjFlGiOjKjHpBiCmJjFmPiKlHiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	wVersion	:_xZkqqHx_iDhEiDeAiDeDiDiLiDgPiBfLiDfHiDiHiDjDiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_jFlGiOjKjHpBiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.08.01 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
WString MC2HeaderInf::FileVersionToString (WORD wVersion)
{
	union {
		WORD	wVersion;	// _xZkqqHx_iDhEiDeAiDeDiDiLiDgPiBfLiDfHiDiHiDjDiBeC_xHqqkZx_
		struct {
			WORD	wMinor	: 8;	// _xZkqqHx_iDhNiDeDiDgJiBfLiDgPiBfLiDfHiDiHiDjDiBeC_xHqqkZx_
			WORD	wMajor	: 8;	// _xZkqqHx_iDiBiDfHiDiDiBfLiDgPiBfLiDfHiDiHiDjDiBeC_xHqqkZx_
		};
	} ver;
	ver.wVersion = wVersion;
	CString strVersion;
	if (ver.wMajor == 0 && ver.wMinor == 0)
		strVersion = _T("1.0");
	else
	if (ver.wMajor == 0 && ver.wMinor == 2)
		strVersion = _T("2.0");
	else
		strVersion.Format(_T("%d.%d"), ver.wMajor, ver.wMinor);
	return TStrToWStr(strVersion);
} // MC2HeaderInf::FileVersionToString.

