1 #ifndef VERSION_INI_CLASS
2 #define VERSION_INI_CLASS
4 /*****************************************************************************\
6 * Name : version_ini editing support *
7 * Author : Chris Koeritz *
9 *******************************************************************************
10 * Copyright (c) 1995-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
18 #include <basis/contracts.h>
19 #include <configuration/ini_configurator.h>
20 #include <filesystem/filename.h>
21 #include <structures/version_record.h>
25 //! This provides support for writing windows version files.
27 The class loads version information out of an initialization file and writes
28 it into a standard windows VERSION_INFO RC file entry. It also creates the
29 headers we use with our version control support.
32 class version_ini : public virtual basis::root_object
35 version_ini(const basis::astring &path_name);
36 //!< the "path_name" is where the version INI file is located.
37 /*!< this file will be read for the key fields that will be used to name
38 the version RC file and generate information in the resource. */
42 DEFINE_CLASS_NAME("version_ini");
45 //!< returns true if the INI file specified in the constructor is writable.
47 structures::version get_version();
48 //!< observes or modifies the version number structure held here.
49 /*!< if the record had not been previously loaded, it is loaded. */
51 void set_version(const structures::version &to_write, bool write_to_ini);
52 //!< sets the version held here.
53 /*!< if "write_ini" is true, then the ini file is written to also. note
54 that if get_record() had not previously been done and "write_ini" is not
55 true, then the next get_record() or get_version() will wipe out the
56 version that is set in the interim. */
58 structures::version_record get_record();
59 //!< observes the entire version record.
60 /*!< The information is assembled from any cached record, the ini file and
61 other sources. if the record has been loaded before, the last loaded
62 version is returned plus any changes that have been made to the held
63 record since then. otherwise, the record is read from the ini file. */
65 structures::version_record &access_record();
66 //!< provides access to change the version_record held here.
67 /*!< this does not read from the INI file, unlike get_record(). */
69 void set_record(const structures::version_record &to_write, bool write_to_ini);
70 //!< modifies the entire version record.
71 /*!< if "write_to_ini" is true, then the new information is actually
72 written to our configuration file. otherwise the information just
73 replaces the source record here. */
76 //!< returns true if this version file is for an executable.
78 //!< returns true if this version file is for a dynamic library.
80 bool ole_auto_registering();
81 //!< returns true if this version file specifies ole auto registration.
83 bool write_rc(const structures::version_record &to_write);
84 //!< writes out the file 'X_version.rc' for the X library or application.
85 /*!< the contents will include the information specified in "to_write",
86 where X is the library name from that record. */
88 bool write_code(const structures::version_record &to_write);
89 //!< writes out the header ('X_version.h') with the version information.
90 /*!< this file is needed for other libraries or application to know this
91 project's version number. the users can make sure that the header info
92 agrees with the actual version seen on the file. */
94 bool write_assembly(const structures::version_record &to_write, bool do_logging);
95 //!< fixes any assemblies with the info in "to_write".
97 static bool executable(const basis::astring &path_name);
98 //!< returns true if "path_name" is for an executable.
99 static bool library(const basis::astring &path_name);
100 //!< returns true if "path_name" is for a dynamic library.
102 structures::version read_version_from_ini();
103 //!< specialized version ignores cache and gets version directly from file.
105 static bool one_stop_version_stamp(const basis::astring &path,
106 const basis::astring &source_version, bool do_logging);
107 //!< performs version stamping using the ini file in "path".
108 /*!< "source_version" supplies the name of the main version file where
109 we retrieve the current version numbers. if that is not specified, then
110 only the version header and RC file are created. if "do_logging" is
111 true, then version info will be sent to the program-wide logger. */
113 // constants for strings found in the version INI file.
114 static const char *VERSION_SECTION;
115 static const char *COMPANY_KEY;
116 static const char *COPYRIGHT_KEY;
117 static const char *LEGAL_INFO_KEY;
118 static const char *PRODUCT_KEY;
119 static const char *WEB_SITE_KEY;
120 static const char *MAJOR;
121 static const char *MINOR;
122 static const char *REVISION;
123 static const char *BUILD;
124 static const char *DESCRIPTION;
125 static const char *ROOT;
126 static const char *NAME;
127 static const char *EXTENSION;
128 static const char *OLE_AUTO;
131 bool _loaded; //!< did we grab the data from the ini file yet?
132 filesystem::filename *_path_name; //!< where to find the ini file.
133 configuration::ini_configurator *_ini; //!< accesses the ini file.
134 structures::version_record *_held_record; //!< the data we cache for the ini file.
136 static void check_name(filesystem::filename &to_examine);
137 //!< adds the default file name if "to_examine" turns out to be a directory.