Crypt Library Demo 1.00
Classes | Public Member Functions | Protected Member Functions | Protected Attributes

CVersionInfo Class Reference

#include <VersionInfo.h>

Collaboration diagram for CVersionInfo:
Collaboration graph
[legend]

List of all members.

Classes

struct  TRANSLATION

Public Member Functions

 CVersionInfo ()
 ~CVersionInfo ()
BOOL Load (LPCTSTR szFileName)
VS_FIXEDFILEINFO * GetFixedFileInfo ()
DWORD GetFileFlagsMask ()
DWORD GetFileFlags ()
DWORD GetOS ()
DWORD GetFileType ()
DWORD GetFileSubType ()
FILETIME GetCreationTime ()
unsigned __int64 GetFileVersion ()
unsigned __int64 GetProductVersion ()
CString GetValue (const CString &sKeyName)
CString GetComments ()
CString GetCompanyName ()
CString GetFileDescription ()
CString GetFileVersionAsString ()
CString GetInternalName ()
CString GetLegalCopyright ()
CString GetLegalTrademarks ()
CString GetOriginalFilename ()
CString GetPrivateBuild ()
CString GetProductName ()
CString GetProductVersionAsString ()
CString GetSpecialBuild ()
int GetNumberOfTranslations ()
TRANSLATIONGetTranslation (int nIndex)
void SetTranslation (int nIndex)

Protected Member Functions

void Unload ()

Protected Attributes

WORD m_wLangID
WORD m_wCharset
ATL::CHeapPtr< BYTE > m_VerData
TRANSLATIONm_pTranslations
int m_nTranslations
VS_FIXEDFILEINFO * m_pffi

Detailed Description

Definition at line 38 of file VersionInfo.h.


Constructor & Destructor Documentation

CVersionInfo::CVersionInfo ( )

Definition at line 52 of file VersionInfo.cpp.

                           : m_pffi(NULL),
m_wLangID(0),
m_wCharset(1252), //Use the ANSI code page as a default
m_pTranslations(NULL),
m_nTranslations(0)
{
}
CVersionInfo::~CVersionInfo ( )

Definition at line 60 of file VersionInfo.cpp.

{
    Unload();
}

Here is the call graph for this function:


Member Function Documentation

CString CVersionInfo::GetComments ( )

Definition at line 257 of file VersionInfo.cpp.

{
    return GetValue(_T("Comments"));
}

Here is the call graph for this function:

CString CVersionInfo::GetCompanyName ( )

Definition at line 212 of file VersionInfo.cpp.

{
    return GetValue(_T("CompanyName"));
}

Here is the call graph for this function:

FILETIME CVersionInfo::GetCreationTime ( )

Definition at line 156 of file VersionInfo.cpp.

{
    ASSERT(m_VerData != NULL); //Must have been loaded successfully
    FILETIME CreationTime;
    CreationTime.dwHighDateTime = m_pffi->dwFileDateMS; 
    CreationTime.dwLowDateTime = m_pffi->dwFileDateLS; 
    return CreationTime;
}
CString CVersionInfo::GetFileDescription ( )

Definition at line 217 of file VersionInfo.cpp.

{
    return GetValue(_T("FileDescription"));
}

Here is the call graph for this function:

DWORD CVersionInfo::GetFileFlags ( )

Definition at line 132 of file VersionInfo.cpp.

{
    ASSERT(m_VerData != NULL); //Must have been loaded successfully
    return m_pffi->dwFileFlags;
}
DWORD CVersionInfo::GetFileFlagsMask ( )

Definition at line 126 of file VersionInfo.cpp.

{
    ASSERT(m_VerData != NULL); //Must have been loaded successfully
    return m_pffi->dwFileFlagsMask;
}
DWORD CVersionInfo::GetFileSubType ( )

Definition at line 150 of file VersionInfo.cpp.

{
    ASSERT(m_VerData != NULL); //Must have been loaded successfully
    return m_pffi->dwFileSubtype;
}
DWORD CVersionInfo::GetFileType ( )

Definition at line 144 of file VersionInfo.cpp.

{
    ASSERT(m_VerData != NULL); //Must have been loaded successfully
    return m_pffi->dwFileType;
}
unsigned __int64 CVersionInfo::GetFileVersion ( )

Definition at line 165 of file VersionInfo.cpp.

{
    ASSERT(m_VerData != NULL); //Must have been loaded successfully
    unsigned __int64 nFileVersion = 0;
    nFileVersion = m_pffi->dwFileVersionLS;
    nFileVersion += ((static_cast<unsigned __int64>(m_pffi->dwFileVersionMS)) << 32);
    return nFileVersion;
}
CString CVersionInfo::GetFileVersionAsString ( )

Definition at line 222 of file VersionInfo.cpp.

{
    return GetValue(_T("FileVersion"));
}

Here is the call graph for this function:

VS_FIXEDFILEINFO * CVersionInfo::GetFixedFileInfo ( )

Definition at line 120 of file VersionInfo.cpp.

{
    ASSERT(m_VerData != NULL); //Must have been loaded successfully
    return m_pffi;
}
CString CVersionInfo::GetInternalName ( )

Definition at line 227 of file VersionInfo.cpp.

{
    return GetValue(_T("InternalName"));
}

Here is the call graph for this function:

CString CVersionInfo::GetLegalCopyright ( )

Definition at line 232 of file VersionInfo.cpp.

{
    return GetValue(_T("LegalCopyright"));
}

Here is the call graph for this function:

CString CVersionInfo::GetLegalTrademarks ( )

Definition at line 262 of file VersionInfo.cpp.

{
    return GetValue(_T("LegalTrademarks"));
}

Here is the call graph for this function:

int CVersionInfo::GetNumberOfTranslations ( )

Definition at line 252 of file VersionInfo.cpp.

{
    return m_nTranslations;
}
CString CVersionInfo::GetOriginalFilename ( )

Definition at line 237 of file VersionInfo.cpp.

{
    return GetValue(_T("OriginalFilename"));
}

Here is the call graph for this function:

DWORD CVersionInfo::GetOS ( )

Definition at line 138 of file VersionInfo.cpp.

{
    ASSERT(m_VerData != NULL); //Must have been loaded successfully
    return m_pffi->dwFileOS;
}
CString CVersionInfo::GetPrivateBuild ( )

Definition at line 267 of file VersionInfo.cpp.

{
    return GetValue(_T("PrivateBuild"));
}

Here is the call graph for this function:

CString CVersionInfo::GetProductName ( )

Definition at line 242 of file VersionInfo.cpp.

{
    return GetValue(_T("Productname"));
}

Here is the call graph for this function:

unsigned __int64 CVersionInfo::GetProductVersion ( )

Definition at line 174 of file VersionInfo.cpp.

{
    ASSERT(m_VerData != NULL); //Must have been loaded successfully
    unsigned __int64 nProductVersion = 0;
    nProductVersion = m_pffi->dwProductVersionLS;
    nProductVersion += ((static_cast<unsigned __int64>(m_pffi->dwProductVersionMS)) << 32);
    return nProductVersion;
}
CString CVersionInfo::GetProductVersionAsString ( )

Definition at line 247 of file VersionInfo.cpp.

{
    return GetValue(_T("ProductVersion"));
}

Here is the call graph for this function:

CString CVersionInfo::GetSpecialBuild ( )

Definition at line 272 of file VersionInfo.cpp.

{
    return GetValue(_T("SpecialBuild"));
}

Here is the call graph for this function:

CVersionInfo::TRANSLATION * CVersionInfo::GetTranslation ( int  nIndex)

Definition at line 277 of file VersionInfo.cpp.

{
    ASSERT(nIndex >= 0 && nIndex < m_nTranslations);
    AFXASSUME(m_pTranslations);
    return &m_pTranslations[nIndex];
}

Here is the caller graph for this function:

CString CVersionInfo::GetValue ( const CString &  sKeyName)

Definition at line 183 of file VersionInfo.cpp.

{
    //Validate our parameters
    AFXASSUME(m_VerData != NULL);

    //What will be the return value from this function
    CString sVal;

    //Form the string to query with
    CString sQueryValue;
    sQueryValue.Format(_T("\\StringFileInfo\\%04x%04x\\%s"), m_wLangID, m_wCharset, sKey.operator LPCTSTR());

    //Note that the definition for VerQueryValue in the VC 2005 Winver.h header file is incorrectly
    //defined as taking a non-const 2nd parameter, so to avoid this issue, lets get a non const pointer
    //to the "sQueryValue" buffer
    LPTSTR pszQueryValue = sQueryValue.GetBuffer(sQueryValue.GetLength());

    //Do the query
    LPTSTR pVal = NULL;
    UINT nLen = 0;
    if (VerQueryValue(m_VerData, pszQueryValue, reinterpret_cast<LPVOID*>(&pVal), &nLen)) 
        sVal = pVal;

    //Release the non-const buffer now that we are finished with it    
    sQueryValue.ReleaseBuffer();

    return sVal;
}

Here is the caller graph for this function:

BOOL CVersionInfo::Load ( LPCTSTR  szFileName)

Definition at line 76 of file VersionInfo.cpp.

{
    //Free up any previous memory lying around
    Unload();

    BOOL bSuccess = FALSE;
    DWORD dwHandle = 0;
    DWORD dwSize = GetFileVersionInfoSize(szFileName, &dwHandle);
    if (dwSize)
    {
        //Allocate some memory to hold the version info data
        ASSERT(m_VerData == NULL);
        if (!m_VerData.Allocate(dwSize))
        {
            SetLastError(ERROR_OUTOFMEMORY);
            return FALSE;
        }
        if (GetFileVersionInfo(szFileName, dwHandle, dwSize, m_VerData))
        {
            //Get the fixed size version info data
            UINT nLen = 0;
            if (VerQueryValue(m_VerData, _T("\\"), reinterpret_cast<LPVOID*>(&m_pffi), &nLen))
            {
                //Retrieve the Lang ID and Character set ID
                if (VerQueryValue(m_VerData, _T("\\VarFileInfo\\Translation"), reinterpret_cast<LPVOID*>(&m_pTranslations), &nLen) && (nLen >= sizeof(TRANSLATION))) 
                {
                    m_nTranslations = nLen / sizeof(TRANSLATION);
                    m_wLangID = m_pTranslations[0].m_wLangID;
                    m_wCharset = m_pTranslations[0].m_wCodePage;
                }
                bSuccess = TRUE;
            }
            else
                TRACE(_T("CVersionInfo::Load, Failed to query file size version info for file %s, LastError:%d\n"), szFileName, ::GetLastError());
        }
        else
            TRACE(_T("CVersionInfo::Load, Failed to read in version info for file %s, LastError:%d\n"), szFileName, ::GetLastError());
    }
    else
        TRACE(_T("CVersionInfo::Load, Failed to get version info for file %s, LastError:%d\n"), szFileName, ::GetLastError());

    return bSuccess;
}

Here is the call graph for this function:

void CVersionInfo::SetTranslation ( int  nIndex)

Definition at line 284 of file VersionInfo.cpp.

{
    TRANSLATION* pTranslation = GetTranslation(nIndex);
    m_wLangID = pTranslation->m_wLangID;
    m_wCharset = pTranslation->m_wCodePage;
}

Here is the call graph for this function:

void CVersionInfo::Unload ( ) [protected]

Definition at line 65 of file VersionInfo.cpp.

{
    m_pffi = NULL;
    if (m_VerData != NULL)
        m_VerData.Free();
    m_wLangID = 0;
    m_wCharset = 1252; //Use the ANSI code page as a default
    m_pTranslations = NULL;
    m_nTranslations = 0;
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 88 of file VersionInfo.h.

VS_FIXEDFILEINFO* CVersionInfo::m_pffi [protected]

Definition at line 89 of file VersionInfo.h.

Definition at line 87 of file VersionInfo.h.

ATL::CHeapPtr<BYTE> CVersionInfo::m_VerData [protected]

Definition at line 86 of file VersionInfo.h.

WORD CVersionInfo::m_wCharset [protected]

Definition at line 85 of file VersionInfo.h.

WORD CVersionInfo::m_wLangID [protected]

Definition at line 84 of file VersionInfo.h.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Enumerator Defines