feisty meow concerns codebase  2.140
versions::version_checker Class Reference

Provides version checking for shared libraries. More...

#include <version_checker.h>

Inheritance diagram for versions::version_checker:
Collaboration diagram for versions::version_checker:

Public Member Functions

 version_checker (const basis::astring &library_file_name, const structures::version &expected, const basis::astring &version_complaint)
 Constructs a checking object and ensures the version is appropriate. More...
 
virtual ~version_checker ()
 Destructor releases any resources. More...
 
bool good_version () const
 Performs the actual version check. More...
 
 DEFINE_CLASS_NAME ("version_checker")
 
basis::astring text_form () const
 
void complain_wrong_version (const basis::astring &library_file_name, const structures::version &expected_version, const structures::version &version_found) const
 Reports that the file has the wrong version. More...
 
void complain_cannot_load (const basis::astring &library_file_name) const
 Reports that the dll could not be loaded. More...
 

Static Public Member Functions

static basis::astring module_name (const void *module_handle)
 returns the module name where this object resides; only sensible on win32. More...
 
static bool loaded (const basis::astring &library_file_name)
 returns true if the "library_file_name" is currently loaded. More...
 
static void * get_handle (const basis::astring &library_file_name)
 retrieves the module handle for the "library_file_name". More...
 
static basis::astring get_name (const void *to_find)
 returns the name of the HMODULE specified by "to_find". More...
 
static structures::version retrieve_version (const basis::astring &pathname)
 Returns the version given a "pathname" to the DLL or EXE file. More...
 
static bool get_record (const basis::astring &pathname, structures::version_record &to_fill)
 Retrieves a version record for the file at "pathname". More...
 
static bool retrieve_version_info (const basis::astring &filename, basis::byte_array &to_fill)
 Retrieves the version info for the "filename" into the array "to_fill". More...
 
static bool get_language (basis::byte_array &version_chunk, basis::un_short &high, basis::un_short &low)
 Gets the language identifier out of the "version_chunk". More...
 

Detailed Description

Provides version checking for shared libraries.

Definition at line 26 of file version_checker.h.

Constructor & Destructor Documentation

◆ version_checker()

versions::version_checker::version_checker ( const basis::astring library_file_name,
const structures::version expected,
const basis::astring version_complaint 
)

Constructs a checking object and ensures the version is appropriate.

the version checking (a call to the good_version() function) will succeed if the library with the "library_file_name" (such as "basis32.dll") has the "expected" version. the simplest way to check if the version is correct is probably similar to:

if (!version_checker("my.dll", version(1.2.3.4)).good_version()) {
...program exit or version failure management...
}
bool good_version() const
Performs the actual version check.
version_checker(const basis::astring &library_file_name, const structures::version &expected, const basis::astring &version_complaint)
Constructs a checking object and ensures the version is appropriate.

the "version_complaint" is the message that will be displayed on a failure in version checking (with noisy mode enabled). it should describe that a version failure occurred and include contact information for the customer to get the most recent versions. for example:

astring version_grievance = "Please contact Floobert Corporation for "
"the latest DLL and Executable files (http://www.floobert.com).";

Definition at line 61 of file version_checker.cpp.

◆ ~version_checker()

versions::version_checker::~version_checker ( )
virtual

Destructor releases any resources.

Definition at line 68 of file version_checker.cpp.

References basis::WHACK().

Member Function Documentation

◆ complain_cannot_load()

void versions::version_checker::complain_cannot_load ( const basis::astring library_file_name) const

Reports that the dll could not be loaded.

Definition at line 372 of file version_checker.cpp.

References continuable_error, and basis::astring::s().

◆ complain_wrong_version()

void versions::version_checker::complain_wrong_version ( const basis::astring library_file_name,
const structures::version expected_version,
const structures::version version_found 
) const

Reports that the file has the wrong version.

Definition at line 343 of file version_checker.cpp.

References continuable_error, structures::version::flex_text_form(), get_name(), module_name(), and basis::astring::s().

Referenced by good_version().

◆ DEFINE_CLASS_NAME()

versions::version_checker::DEFINE_CLASS_NAME ( "version_checker"  )

◆ get_handle()

void * versions::version_checker::get_handle ( const basis::astring library_file_name)
static

retrieves the module handle for the "library_file_name".

This returns zero if the library cannot be located. the returned pointer wraps a win32 HMODULE currently, or it is meaningless.

Definition at line 110 of file version_checker.cpp.

References NULL_POINTER, and basis::astring::t().

Referenced by loaded().

◆ get_language()

bool versions::version_checker::get_language ( basis::byte_array version_chunk,
basis::un_short high,
basis::un_short low 
)
static

Gets the language identifier out of the "version_chunk".

Returns true if the language identifier for the dll's version chunk could be stored in "high" and "low". This is a win32-only method.

Definition at line 171 of file version_checker.cpp.

References basis::array< contents >::access(), and basis::array< contents >::length().

Referenced by get_record(), and retrieve_version().

◆ get_name()

astring versions::version_checker::get_name ( const void *  to_find)
static

returns the name of the HMODULE specified by "to_find".

If that handle cannot be located, then an empty string is returned.

Definition at line 139 of file version_checker.cpp.

References module_name().

Referenced by complain_wrong_version().

◆ get_record()

bool versions::version_checker::get_record ( const basis::astring pathname,
structures::version_record to_fill 
)
static

Retrieves a version record for the file at "pathname".

Returns the full version record found for a given "pathname" to the DLL or EXE file in the record "to_fill". if the directory component of the path is not included, then the search path will be used. false is returned if some piece of information could not be located; this does not necessarily indicate a total failure of the retrieval.

Definition at line 249 of file version_checker.cpp.

References basis::array< contents >::access(), structures::version_record::company_name, structures::version_record::copyright, structures::version_record::description, structures::version_record::file_version, get_language(), structures::version_record::internal_name, NULL_POINTER, structures::version_record::original_name, structures::version_record::product_name, structures::version_record::product_version, retrieve_version_info(), and structures::version_record::trademarks.

◆ good_version()

bool versions::version_checker::good_version ( ) const

Performs the actual version check.

If the version check is unsuccessful, then a message that describes the problem is shown to the user and false is returned. NOTE: the version check will also fail if the version information structure cannot be found for that library.

Definition at line 82 of file version_checker.cpp.

References structures::version::compatible(), complain_wrong_version(), retrieve_version(), and basis::astring::s().

◆ loaded()

bool versions::version_checker::loaded ( const basis::astring library_file_name)
static

returns true if the "library_file_name" is currently loaded.

Definition at line 99 of file version_checker.cpp.

References get_handle(), and basis::astring::t().

◆ module_name()

astring versions::version_checker::module_name ( const void *  module_handle)
static

returns the module name where this object resides; only sensible on win32.

Definition at line 120 of file version_checker.cpp.

References MAX_ABS_PATH, and basis::astring::to_lower().

Referenced by complain_wrong_version(), and get_name().

◆ retrieve_version()

version versions::version_checker::retrieve_version ( const basis::astring pathname)
static

Returns the version given a "pathname" to the DLL or EXE file.

If the directory component is not included, then the search path will be used.

Definition at line 197 of file version_checker.cpp.

References basis::array< contents >::access(), get_language(), basis::astring::length(), NULL_POINTER, retrieve_version_info(), and basis::astring::zap().

Referenced by good_version().

◆ retrieve_version_info()

bool versions::version_checker::retrieve_version_info ( const basis::astring filename,
basis::byte_array to_fill 
)
static

Retrieves the version info for the "filename" into the array "to_fill".

Definition at line 142 of file version_checker.cpp.

References basis::array< contents >::access(), basis::array< contents >::reset(), and basis::astring::t().

Referenced by get_record(), and retrieve_version().

◆ text_form()

astring versions::version_checker::text_form ( ) const

Definition at line 75 of file version_checker.cpp.

References structures::version::text_form().


The documentation for this class was generated from the following files: