version_info.hpp

来自「用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、W」· HPP 代码 · 共 1,342 行 · 第 1/3 页

HPP
1,342
字号
/* /////////////////////////////////////////////////////////////////////////
 * File:        winstl/system/version_info.hpp (originally in MWVerInf.h, ::SynesisWin)
 *
 * Purpose:     Helper for accessing version information.
 *
 * Created:     16th February 1998
 * Updated:     11th June 2006
 *
 * Home:        http://stlsoft.org/
 *
 * Copyright (c) 1998-2006, Matthew Wilson and Synesis Software
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
 *   any contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * ////////////////////////////////////////////////////////////////////// */


/** \file winstl/system/version_info.hpp
 *
 * \brief [C++ only] Definition of the winstl::version_info class
 *  template.
 *  (\ref group__library__system "System" Library.)
 */

#ifndef WINSTL_INCL_WINSTL_SYSTEM_HPP_VERSION_INFO
#define WINSTL_INCL_WINSTL_SYSTEM_HPP_VERSION_INFO

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define WINSTL_VER_WINSTL_SYSTEM_HPP_VERSION_INFO_MAJOR    5
# define WINSTL_VER_WINSTL_SYSTEM_HPP_VERSION_INFO_MINOR    0
# define WINSTL_VER_WINSTL_SYSTEM_HPP_VERSION_INFO_REVISION 1
# define WINSTL_VER_WINSTL_SYSTEM_HPP_VERSION_INFO_EDIT     102
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/* /////////////////////////////////////////////////////////////////////////
 * Includes
 */

#ifndef WINSTL_INCL_WINSTL_H_WINSTL
# include <winstl/winstl.h>
#endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
#ifndef WINSTL_INCL_WINSTL_HPP_EXCEPTIONS
# include <winstl/exceptions.hpp>
#endif /* !WINSTL_INCL_WINSTL_HPP_EXCEPTIONS */
#if defined(STLSOFT_COMPILER_IS_MSVC) && \
    _MSC_VER < 1200
# if defined(UNICODE) || \
     defined(_UNICODE)
#  error winstl::version_info is not supported on Visual C++ 5.0 (or previous) with UNICODE compilations
# endif /* Unicode */
# define WINSTL_VERSION_INFO_NO_USE_FILE_PATH_BUFFER
#else /* ? compiler */
# ifndef WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FILE_PATH_BUFFER
#  include <winstl/filesystem/file_path_buffer.hpp>
# endif /* !WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FILE_PATH_BUFFER */
#endif /* compiler */
#ifndef WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR
# include <winstl/memory/processheap_allocator.hpp>
#endif /* !WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR */
#ifndef STLSOFT_INCL_STLSOFT_CONVERSION_HPP_SAP_CAST
# include <stlsoft/conversion/sap_cast.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_CONVERSION_HPP_SAP_CAST */
#ifndef STLSOFT_INCL_STLSOFT_HPP_STRING_ACCESS
# include <stlsoft/string_access.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_HPP_STRING_ACCESS */
#ifndef STLSOFT_INCL_STLSOFT_HPP_ITERATOR
# include <stlsoft/iterator.hpp>                // for iterator base class templates
#endif /* !STLSOFT_INCL_STLSOFT_HPP_ITERATOR */
#ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_HPP_COLLECTIONS
# include <stlsoft/collections/collections.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_COLLECTIONS_HPP_COLLECTIONS */
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
# include <stdexcept>                           // for std::exception
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
#include <wchar.h>

#ifdef STLSOFT_UNITTEST
# include <stdio.h>
#endif /* STLSOFT_UNITTEST */

/* /////////////////////////////////////////////////////////////////////////
 * Namespace
 */

#ifndef _WINSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
     defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
/* There is no stlsoft namespace, so must define ::winstl */
namespace winstl
{
# else
/* Define stlsoft::winstl_project */

namespace stlsoft
{

namespace winstl_project
{

# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_WINSTL_NO_NAMESPACE */

/* /////////////////////////////////////////////////////////////////////////
 * Structure headers
 */

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION

template <int N>
struct hdr_
{
    WORD    wLength;
    WORD    wValueLength;
    WORD    wType;
    WCHAR   szKey[1];
};

typedef hdr_<1> VS_VERSIONINFO_hdr;
typedef hdr_<2> StringFileInfo_hdr;
typedef hdr_<3> VarFileInfo_hdr;
typedef hdr_<4> Var_hdr;
typedef hdr_<5> StringTable_hdr;
typedef hdr_<6> String_hdr;

template<ss_typename_param_k T>
T *rounded_ptr(T *p, ss_size_t n)
{
    union
    {
        T           *p;
        ss_size_t   cb;
    } u;

    u.p = p;

    u.cb = ((n - 1) + u.cb) & ~(n- 1);

    WINSTL_ASSERT(ptr_byte_diff(u.p, p) >= 0);

    return u.p;
}

template<ss_typename_param_k T>
T *rounded_ptr(T *p, ss_ptrdiff_t byteOffset, ss_size_t n)
{
    // 1. This has to be done in a ridiculously long-hand fashion because Borland is a *very* stupid compiler!
#if defined(STLSOFT_COMPILER_IS_BORLAND)
    void const  *pv =   &byteOffset[(char*)p];
#else /* ? compiler */
    void const  *pv =   ptr_byte_offset(p, byteOffset);
#endif /* compiler */

    WINSTL_ASSERT(((char*)pv - (char*)p) == byteOffset);

    T       *p_     =   static_cast<T*>(pv);
    T       *r      =   rounded_ptr(p_, n);

#ifdef STLSOFT_COMPILER_IS_BORLAND
    STLSOFT_SUPPRESS_UNUSED(p);
    STLSOFT_SUPPRESS_UNUSED(byteOffset);
#endif /* compiler */

    WINSTL_ASSERT(ptr_byte_diff(r, p_) >= 0);

    return r;
}

#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/* /////////////////////////////////////////////////////////////////////////
 * Classes
 */

#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
/// \brief Exception thrown by the version_info class
///
/// \ingroup group__library__system
class version_info_exception
    : public windows_exception
{
/// \name Member Types
/// @{
public:
    typedef windows_exception           parent_class_type;
    typedef version_info_exception      class_type;
/// @}

/// \name Construction
/// @{
public:
    version_info_exception(char const *reason, error_code_type err)
        : parent_class_type(reason, err)
    {}
/// @}
};
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */

/// \brief Represents the fixed part of a version information block
///
/// \ingroup group__library__system
class fixed_file_info
{
    typedef fixed_file_info class_type;

public:
    /// Constructor
    fixed_file_info(VS_FIXEDFILEINFO const *ffi);

public:
    ws_uint16_t ApiVerHigh() const;
    ws_uint16_t ApiVerLow() const;

    /// The major part of the file version
    ws_uint16_t FileVerMajor() const;
    /// The minor part of the file version
    ws_uint16_t FileVerMinor() const;
    /// The revision part of the file version
    ws_uint16_t FileVerRevision() const;
    /// The build increment part of the file version
    ws_uint16_t FileVerBuild() const;

    /// The major part of the product version
    ws_uint16_t ProductVerMajor() const;
    /// The minor part of the product version
    ws_uint16_t ProductVerMinor() const;
    /// The revision part of the product version
    ws_uint16_t ProductVerRevision() const;
    /// The build increment part of the product version
    ws_uint16_t ProductVerBuild() const;

    /// The file flags mask
    ws_uint32_t FileFlagsMask() const;
    /// The file flags
    ws_uint32_t FileFlags() const;

    /// The file operating system
    ws_uint32_t FileOS() const;

    /// The file type
    ws_uint32_t FileType() const;
    /// The file subtype
    ws_uint32_t FileSubtype() const;

    /// The timestamp of the file
    FILETIME const &FileDateTime() const;

private:
    static FILETIME calc_FileDateTime_(VS_FIXEDFILEINFO const *ffi);

private:
    VS_FIXEDFILEINFO const *const   m_ffi;
    FILETIME const                  m_fileDateTime;

private:
    class_type &operator =(class_type const &);
};

/// \brief Represents a variable file part of a version information block
///
/// \ingroup group__library__system
class VsVar
{
public:
    typedef VsVar   class_type;

    /// Represents a language/code-page pair
    struct LangCodePage
    {
        /// The language
        ss_uint16_t language;
        /// The code-page
        ss_uint16_t codePage;
    };
public:
    /// Constructor
    VsVar(Var_hdr const *p);

    /// The length of the variable
    ss_size_t   length() const;

    /// Subscript operator
    LangCodePage const  &operator [](ss_size_t index) const;

private:
    Var_hdr const       *m_p;
    LangCodePage const  *m_values;
};

/// \brief Represents a string part of a version information block
///
/// \ingroup group__library__system
class VsString
{
public:
    typedef VsString    class_type;

public:
    /// Constructor
    VsString(String_hdr const *p);

    /// The name of the variable
    wchar_t const *name() const;

    /// The value of the variable
    wchar_t const *value() const;

private:
    wchar_t const   *m_name;
    wchar_t const   *m_value;
};

/// \brief Represents a string table
///
/// \ingroup group__library__system
class VsStringTable
    : public stlsoft_ns_qual(stl_collection_tag)
{
public:
    typedef VsStringTable   class_type;
    typedef VsString        value_type;

public:
    /// Constructor
    VsStringTable(StringTable_hdr const *p);

    /// The key
    wchar_t const *Key() const;

    /// The non-mutating (const) iterator
    class const_iterator
        : public stlsoft_ns_qual(iterator_base)<winstl_ns_qual_std(forward_iterator_tag)
                                            ,   value_type
                                            ,   ws_ptrdiff_t
                                            ,   void        // By-Value Temporary reference
                                            ,   value_type  // By-Value Temporary reference
                                            >
    {
    public:
        typedef const_iterator  class_type;
        typedef VsString        value_type;

    public:
        /// Constructor
        const_iterator(void const *p);

        /// Pre-increment operator
        class_type &operator ++();

        /// Post-increment operator
        class_type operator ++(int);

        value_type operator *() const;

        ws_bool_t operator ==(class_type const &rhs) const;

        ws_bool_t operator !=(class_type const &rhs) const;

    private:
        void const  *m_p;
    };

    const_iterator begin() const;

    const_iterator end() const;

private:
    StringTable_hdr const   *m_p;
    void const              *m_strings;
};

/// \brief Represents a variable file info part of a version information block
///
/// \ingroup group__library__system
class VsVarFileInfo
    : public stlsoft_ns_qual(stl_collection_tag)
{
public:
    typedef VsVarFileInfo   class_type;
    typedef VsVar           value_type;

public:
    /// Constructor
    ///
    /// \param p The header of the block for which the instance will act
    VsVarFileInfo(VarFileInfo_hdr const *p);

    /// The Key property
    wchar_t const *Key() const;

    /// Iterator class
    class const_iterator
        : public stlsoft_ns_qual(iterator_base)<winstl_ns_qual_std(forward_iterator_tag)
                                            ,   value_type
                                            ,   ws_ptrdiff_t
                                            ,   void        // By-Value Temporary reference
                                            ,   value_type  // By-Value Temporary reference
                                            >
    {
    public:
        typedef const_iterator  class_type;

    public:
        /// Constructor
        const_iterator(void const *p);

        /// Pre-increment operator
        class_type &operator ++();

        /// Post-increment operator
        class_type operator ++(int);

        value_type operator *() const;

        ws_bool_t operator ==(class_type const &rhs) const;

        ws_bool_t operator !=(class_type const &rhs) const;

    private:
        const void  *m_p;
    };

    const_iterator begin() const;

    const_iterator end() const;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?