#ifndef _xbVERSION_
#define _xbVERSION_
/*<<<***************************************************************************
The MIT License (MIT)

Copyright(C) 2013 - 2015 Marc Mirti Mancinelli, Christophe Lardau and Philippe Pamart (xdcube.org)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
////////////////////////////////////////////////////////////////////////////////
#Title: xbVersion
#Project: xdcBase
////////////////////////////////////////////////////////////////////////////////
#Author: Marc MIRTI MANCINELLI
#History:
<15/09/2013: creation.
12/02/2014: this notice inserted.
***************************************************************************>>>*/

#ifndef _xbSTRING_
#	include "xbString.h"
#endif

#ifndef _xbDATA_
#	include "xbData.h"
#endif

enum xbVersionType
{
	xbVersion_File,
	xbVersion_Product
};

class xbEXPORT xbVersion
{
public:
	xbVersion()
	{
		m_highVer = m_lowVer = -1;
	}
	xbVersion(const VS_FIXEDFILEINFO &info,xbVersionType vtype = xbVersion_Product)
	{
		if (vtype == xbVersion_File)
		{
			m_highVer = info.dwFileVersionMS;
			m_lowVer = info.dwFileVersionLS;
		}
		else
		{
			m_highVer = info.dwProductVersionMS;
			m_lowVer = info.dwProductVersionLS;
		}
	}
	explicit xbVersion(const xbString &str,xbOpMode opm =xbOp_Required)
	{
		FromStr(str,opm);
	}
	xbVersion(ulong highVer,ulong lowVer)
	{
		m_highVer = highVer;
		m_lowVer = lowVer;
	}
	xbVersion(const xbVersion &ver)
	{
		m_highVer = ver.m_highVer;
		m_lowVer = ver.m_lowVer;
	}

	xbVersion &operator=(const xbVersion &ver)
	{
		m_highVer = ver.m_highVer;
		m_lowVer = ver.m_lowVer;
		return *this;
	}

	ulong GetHigh() const {return m_highVer;}
	ulong GetLow() const {return m_lowVer;}

	int Compare(const xbVersion &ver) const;
	bool operator==(const xbVersion &ver) const {return Compare(ver) == 0;}
	bool operator!=(const xbVersion &ver) const {return Compare(ver) != 0;}
	bool operator>=(const xbVersion &ver) const {return Compare(ver) >= 0;}
	bool operator>(const xbVersion &ver) const {return Compare(ver) > 0;}
	bool operator<=(const xbVersion &ver) const {return Compare(ver) <= 0;}
	bool operator<(const xbVersion &ver) const {return Compare(ver) < 0;}

	bool IsAny() const {return m_highVer == -1 && m_lowVer == -1;}
	bool IsEmpty() const {return m_highVer == -1 && m_lowVer == -1;}
	bool IsValid() const {return m_highVer != -1 && m_lowVer != -1;}
	void Empty()
	{
		m_highVer = m_lowVer = -1;
	}

	operator xbString() const
	{
		return ToStr();
	}
	xbString ToStr(char chSep = ',',bool bDisplayAny = true) const; 
	bool FromStr(const xbString &str,xbOpMode opm =xbOp_Required);
protected:
	ulong m_highVer,m_lowVer;
};

extern bool		xbEXPORT xbGetVersionInfo(LPCSTR pszFile,xbData *pData);
extern xbString xbEXPORT xbGetProductName(LPCSTR pszFile = NULL,bool bWithVersion = true);
extern xbVersion xbEXPORT xbGetProductVersion(LPCSTR pszFile = NULL,xbOpMode opm =xbOp_Required);
extern xbVersion xbEXPORT xbGetFileVersion(LPCSTR pszFile = NULL,xbOpMode opm =xbOp_Required);

extern xbEXPORT VS_FIXEDFILEINFO	*xbGetVersionRoot(const xbData &dta,UINT *pSz = NULL);
extern xbEXPORT xbString			xbGetVersionLangCodePage(const xbData &dta,LPCSTR pDflt = "040904E4");
extern xbEXPORT xbString			xbGetVersionString(const xbData &dta,const xbString &langcodepage,const xbString &stringName);

#endif
