32 using namespace basis;
41 const char *version_ini::VERSION_SECTION =
"version";
43 const char *version_ini::COMPANY_KEY=
"company";
44 const char *version_ini::COPYRIGHT_KEY=
"copyright";
45 const char *version_ini::LEGAL_INFO_KEY=
"legal_info";
46 const char *version_ini::PRODUCT_KEY=
"product_name";
47 const char *version_ini::WEB_SITE_KEY=
"web_site";
54 const char *version_ini::MAJOR =
"major";
55 const char *version_ini::MINOR =
"minor";
56 const char *version_ini::REVISION =
"revision";
57 const char *version_ini::BUILD =
"build";
58 const char *version_ini::DESCRIPTION =
"description";
59 const char *version_ini::ROOT =
"root";
60 const char *version_ini::NAME =
"name";
61 const char *version_ini::EXTENSION =
"extension";
62 const char *version_ini::OLE_AUTO =
"ole_auto";
68 #define LOG(t) CLASS_EMERGENCY_LOG(program_wide_logger::get(), t)
70 version_ini::version_ini(
const astring &path_name)
76 check_name(*_path_name);
77 _ini->
name(*_path_name);
90 return (extension.
lower().
t());
104 void version_ini::check_name(
filename &to_examine)
115 to_examine =
astring(
"./") + to_examine;
123 check_name(path_name);
127 if (extension ==
astring(
"exe"))
return true;
150 if (!write_ini)
return;
172 if (_loaded)
return *_held_record;
185 else if (extension.
equal_to(
"exe")) {}
199 *_held_record = to_return;
206 *_held_record = to_write;
219 #ifndef NO_VERSION\n\
220 #include <winver.h>\n\
221 #include <__build_version.h>\n\
222 #include <__build_configuration.h>\n\
223 #define BI_PLAT_WIN32\n\
224 // force 32 bit compile.\n\
225 1 VERSIONINFO LOADONCALL MOVEABLE\n\
226 FILEVERSION __build_FILE_VERSION_COMMAS\n\
227 PRODUCTVERSION __build_PRODUCT_VERSION_COMMAS\n\
229 FILEFLAGS VS_FFI_FILEFLAGSMASK\n\
230 #if defined(BI_PLAT_WIN32)\n\
231 FILEOS VOS__WINDOWS32\n\
233 FILEOS VOS__WINDOWS16\n\
237 BLOCK \"StringFileInfo\"\n\
239 // Language type = U.S. English(0x0409) and Character Set = Windows, Multilingual(0x04b0)\n\
240 BLOCK \"040904b0\" // Matches VarFileInfo Translation hex value.\n\
242 VALUE \"CompanyName\", __build_company \"\\000\"\n\
244 VALUE \"FileDescription\", \"$file_desc\\000\"\n\
246 VALUE \"FileDescription\", \"$file_desc (DEBUG)\\000\"\n\
248 VALUE \"FileVersion\", __build_FILE_VERSION \"\\000\" \n\
249 VALUE \"ProductVersion\", __build_PRODUCT_VERSION \"\\000\" \n\
250 VALUE \"InternalName\", \"$internal\\000\"\n\
251 VALUE \"LegalCopyright\", __build_copyright \"\\000\"\n\
252 VALUE \"LegalTrademarks\", __build_legal_info \"\\000\"\n\
253 VALUE \"OriginalFilename\", \"$original_name\\000\"\n\
254 VALUE \"ProductName\", __build_product_name \"\\000\"\n\
259 BLOCK \"VarFileInfo\"\n\
261 VALUE \"Translation\", 0x0409, 0x04b0 // US English (0x0409) and win32 multilingual (0x04b0)\n\
269 #define REPLACE(tag, replacement) \
270 new_version_entry.replace_all(tag, replacement); \
289 REPLACE(
"$file_desc", description_release);
291 +
astring(
" -- Debug Version");
292 REPLACE(
"$file_desc", description_debug);
318 special_filler =
"VALUE \"OLESelfRegister\", \"\\0\"";
319 REPLACE(
"$special_ole_flag", special_filler);
324 astring rc_filename(header_store +
"/" + root_part
327 filename(rc_filename).
chmod(filename::ALLOW_BOTH, filename::USER_RIGHTS);
331 if (!rc_file.
good())
return false;
340 #ifndef $lib_prefix_VERSION_HEADER\n\
341 #define $lib_prefix_VERSION_HEADER\n\
350 #include <__build_version.h>\n\
351 #include <__build_configuration.h>\n\
352 #include <basis/version_checker.h>\n\
353 #include <basis/version_record.h>\n\
357 // this macro can be used to check that the current version of the\n\
358 // $lib_name library is the same version as expected. to use it, check\n\
359 // whether it returns true or false. if false, the version is incorrect.\n\
360 #define CHECK_$lib_prefix() (version_checker(astring(\"$lib_prefix\")\\\n\
361 + astring(\".dll\"), version(__build_SYSTEM_VERSION),\\\n\
362 astring(\"Please contact $company_name for the latest DLL and \"\\\n\
363 \"Executable files ($web_address).\")).good_version())\n\
367 // null checking for embedded or other platforms without versions.\n\
369 #define CHECK_$lib_prefix() 1\n\
371 #endif //__WIN32__\n\
414 astring header_filename(header_store +
"/" + root_part
417 filename(header_filename).
chmod(filename::ALLOW_BOTH, filename::USER_RIGHTS);
421 if (!header.
good())
return false;
432 bool to_return =
false;
435 while (posn < full_string.
length()) {
436 int ver_posn = full_string.
find(look_for, posn);
437 if (ver_posn < 0)
break;
438 int quote_posn = full_string.
find(
"\"", ver_posn);
439 if (quote_posn < 0)
break;
440 int second_quote_posn = full_string.
find(
"\"", quote_posn + 1);
441 if (second_quote_posn < 0)
break;
442 full_string.
zap(quote_posn + 1, second_quote_posn - 1);
443 full_string.
insert(quote_posn + 1, new_ver);
446 posn = quote_posn + new_ver.
length();
466 to_patch = just_dir.
raw() +
"/AssemblyInfo.cpp";
468 to_patch = just_dir.
raw() +
"/AssemblyInfo.cs";
469 if (!to_patch.
raw()) {
471 directory dir2(just_dir +
"/Properties");
473 to_patch = just_dir.
raw() +
"/Properties/AssemblyInfo.cpp";
475 to_patch = just_dir.
raw() +
"/Properties/AssemblyInfo.cs";
478 if (to_patch.
raw().
t()) {
480 filename(to_patch).
chmod(filename::ALLOW_BOTH, filename::USER_RIGHTS);
484 modfile.
read(contents, 1000000);
485 while (contents[contents.
end()] ==
'\032') {
487 contents.
zap(contents.
end(), contents.
end());
498 if (!did_replace)
return true;
524 modfile.
write(contents);
530 program_wide_logger::get().log(
astring(
" patching: ") + dirbase
531 +
"/" + just_base, basis::ALWAYS_PRINT);
539 const astring &header_store,
const astring &source_version,
bool do_logging)
541 FUNCDEF(
"one_stop_version_stamp");
544 path_name = application_configuration::current_directory();
550 if (source_version.
t()) {
580 LOG(
a_sprintf(
"The file \"%s\" contains this version information:",
586 critical_events::alert_message(
a_sprintf(
"Could not write the RC file in \"%s\".",
587 filename(path_name).basename().raw().s()));
592 critical_events::alert_message(
astring(
"Could not write the C++ header file for "
599 critical_events::alert_message(
astring(
"Could not write the Assembly info file for "
a_sprintf is a specialization of astring that provides printf style support.
Provides a dynamically resizable ASCII character string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
astring lower() const
like to_lower(), but returns a new string rather than modifying this.
bool t() const
t() is a shortcut for the string being "true", as in non-empty.
bool replace(const astring &tag, const astring &replacement)
replaces the first occurrence of "tag" text with the "replacement".
virtual void zap(int start, int end)
Deletes the characters between "start" and "end" inclusively.
void insert(int position, const astring &to_insert)
Copies "to_insert" into "this" at the "position".
bool equal_to(const char *that) const
returns true if "that" is equal to this.
int end() const
returns the index of the last (non-null) character in the string.
bool replace_all(char to_replace, char new_char)
changes all occurrences of "to_replace" with "new_char".
int length() const
Returns the current length of the string.
astring upper() const
like to_upper(), but returns a new string rather than modifying this.
int find(char to_find, int position=0, bool reverse=false) const
Locates "to_find" in "this".
void to_lower()
to_lower modifies "this" by replacing capitals with lower-case.
bool store(const basis::astring §ion, const basis::astring &entry, const basis::astring &to_store)
a synonym for put.
basis::astring load(const basis::astring §ion, const basis::astring &entry, const basis::astring &default_value)
a synonym for get that implements the auto-store behavior.
Supports a configurator-based interface on text initialization files.
basis::astring name() const
observes the name of the file used for ini entries.
Provides file managment services using the standard I/O support.
int write(const basis::abyte *buffer, int buffer_size)
writes "buffer_size" bytes into the file from "buffer".
void close()
shuts down the open file, if any.
bool seek(int where, origins origin=FROM_START)
places the cursor in the file at "where", based on the "origin".
const basis::astring & name() const
returns the file name that the object is operating on.
int read(basis::abyte *buffer, int buffer_size)
reads "buffer_size" bytes from the file into "buffer".
bool truncate()
truncates the file after the current position.
bool good()
returns true if the file seems to be in the appropriate desired state.
Implements a scanner that finds all filenames in the directory specified.
const structures::string_array & files() const
returns the list of files that we found in this directory.
Provides operations commonly needed on file names.
void canonicalize()
cleans up the filename as needed for the current operating system.
bool chmod(int write_mode, int owner_mode) const
changes the access rights on the file.
bool is_directory() const
const basis::astring & raw() const
returns the astring that we're holding onto for the path.
filename dirname() const
returns the directory for the filename.
filename basename() const
returns the base of the filename; no directory.
An array of strings with some additional helpful methods.
int find(const basis::astring &to_find) const
locates string specified and returns its index, or negative if missing.
Holds all information about a file's versioning.
basis::astring product_name
basis::astring text_form() const
basis::astring company_name
basis::astring description
basis::astring original_name
basis::astring web_address
basis::astring trademarks
basis::astring internal_name
Holds a file's version identifier.
virtual basis::astring text_form() const
basis::astring get_component(int index) const
returns the component at the specified index.
void set_component(int index, const basis::astring &to_set)
sets the component at "index" to "to_set".
basis::astring flex_text_form(version_style style=DOTS, int including=-1) const
returns a textual form of the version number.
This provides support for writing windows version files.
static const char * EXTENSION
structures::version read_version_from_ini()
specialized version ignores cache and gets version directly from file.
structures::version get_version()
observes or modifies the version number structure held here.
bool write_code(const basis::astring &header_store, const structures::version_record &to_write)
writes out the header ('X_version.h') with the version information.
static const char * PRODUCT_KEY
void set_record(const structures::version_record &to_write, bool write_to_ini)
modifies the entire version record.
static const char * COMPANY_KEY
void set_version(const structures::version &to_write, bool write_to_ini)
sets the version held here.
bool write_assembly(const basis::astring &header_store, const structures::version_record &to_write, bool do_logging)
fixes any assemblies with the info in "to_write".
static bool one_stop_version_stamp(const basis::astring &path, const basis::astring &header_store, const basis::astring &source_version, bool do_logging)
performs version stamping using the ini file in "path".
static const char * DESCRIPTION
structures::version_record get_record()
observes the entire version record.
bool library()
returns true if this version file is for a dynamic library.
static const char * COPYRIGHT_KEY
static const char * MINOR
bool writable()
returns true if the INI file specified in the constructor is writable.
static const char * LEGAL_INFO_KEY
static const char * REVISION
static const char * OLE_AUTO
static const char * MAJOR
static const char * WEB_SITE_KEY
static const char * BUILD
static const char * VERSION_SECTION
bool ole_auto_registering()
returns true if this version file specifies ole auto registration.
bool write_rc(const basis::astring &header_store, const structures::version_record &to_write)
writes out the file 'X_version.rc' for the X library or application.
bool executable()
returns true if this version file is for an executable.
structures::version_record & access_record()
provides access to change the version_record held here.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
unsigned char abyte
A fairly important unit which is seldom defined...
bool non_negative(const type &a)
non_negative returns true if "a" is greater than or equal to zero.
A platform independent way to obtain the timestamp of a file.
A logger that sends to the console screen using the standard output device.
A dynamic container class that holds any kind of object via pointers.
const astring version_header_template
bool replace_version_entry(astring &full_string, const astring &look_for, const astring &new_ver)
const astring version_rc_template
const char * VERSION_INI_FILE
#define REPLACE(tag, replacement)