/***************************************************************************
 *                          Zanoza Modeler v2.x                            *
 *      This is unpublished propietary source code of Zanoza Software.     *
 *      The copyright notice does not evidence any actual or intended      *
 *                    publication of such source code.                     *
 *                                                                         *
 *                Copyright (c) 2002-2003 Zanoza Software.                 *
 *                                                                         *
 *                        All rights reserved.                             *
 ***************************************************************************
 *--------------------------------------------------------------------------
 * @author:   Oleg M.
 * @author:   Copyright (c) 2003, Henri Hein
 *--------------------------------------------------------------------------
 * @purpose:  ZModeler 2.x Version info helper
 *--------------------------------------------------------------------------
 * @histroy: 18.06.2004. Created
 */
#ifndef versioninfohelper_h_included
#define versioninfohelper_h_included

#include <zmodeler.h>

//
// this class implements routines for working with resource-based version info
//
class DLL_LINKAGE CVersionInfo  
{
public:
  CVersionInfo(const CVersionInfo& ver);
  CVersionInfo(VS_FIXEDFILEINFO*);
  CVersionInfo(LPCTSTR strFileName);
  CVersionInfo(HMODULE);        //Read from module
  CVersionInfo();
  virtual ~CVersionInfo();

  //Set methods
  void setFromString(LPCTSTR);
  void setFromFFI(VS_FIXEDFILEINFO*);
  void setFromVerInfo(const CVersionInfo&);
  void setMajor(WORD verMajor);
  void setMinor(WORD verMinor);
  void setAux(WORD verAux);
  void setBuildNum(WORD buildNum);
  void setFromInstance(HMODULE);
  void setFromFilename(LPCTSTR);

  //Out methods
  void asResource(ZString& str) const;      //Use ',' as sep
  void asString(ZString& str) const; //maj.min (build)
  // The "Short" methods only returns major and minor nums.
  void asStringShort(ZString& str) const;
  //Use internal buffer to format string
  LPCTSTR asString();

  inline WORD major() const       { return m_verMajor; }
  inline WORD minor() const       { return m_verMinor; }
  inline WORD aux() const         { return m_verAux; }
  inline WORD buildNum() const    { return m_BuildNum; }
			
  //For extended info
  ZRESULT getExtProductName(ZString& str) const;
  LPCTSTR getProductName() const;
  LPCTSTR getCompanyName() const;
  LPCTSTR getLegalInfo() const;

  //Compare method(s)
  int compare(const CVersionInfo& ver) const;

  // operators methods
  CVersionInfo& operator=(const CVersionInfo& ver);
  // compares product version only
  bool operator==(const CVersionInfo& ver) const;
  bool operator<(const CVersionInfo& ver) const;
  bool operator>(const CVersionInfo& ver) const;

  //Static helpers
  static ZRESULT getVersionInfo(LPCTSTR szFile, ZOpaque*& info);

protected:
  ZRESULT getVersionOfFile(LPCTSTR szFile);
  void reset();

private:
  ZString m_strOut;

  WORD    m_BuildNum; //file version
  WORD    m_verAux;   //file version
  WORD    m_verMinor; //product version
  WORD    m_verMajor; //product version

  ZString m_strProductName;
  ZString m_strCompany;
  ZString m_strLegal;
};

#endif //versioninfohelper_h_included
