2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/GlobalIncs/version.cpp $
17 * Revision 1.3 2002/06/09 04:41:17 relnev
18 * added copyright header
20 * Revision 1.2 2002/05/07 03:16:45 theoddone33
21 * The Great Newline Fix
23 * Revision 1.1.1.1 2002/05/03 03:28:09 root
27 * 4 8/09/99 2:21p Andsager
28 * Fix patching from multiplayer direct to launcher update tab.
30 * 3 8/06/99 3:32p Andsager
31 * Handle update when no registry is set
33 * 2 5/19/99 4:07p Dave
34 * Moved versioning code into a nice isolated common place. Fixed up
35 * updating code on the pxo screen. Fixed several stub problems.
37 * 1 5/18/99 4:28p Dave
45 #include "osregistry.h"
49 // ----------------------------------------------------------------------------------------------------------------
50 // VERSION DEFINES/VARS
54 #define VER(major, minor, build) (100*100*major+100*minor+build)
55 #define MAX_LINE_LENGTH 512
58 // ----------------------------------------------------------------------------------------------------------------
62 // compare version against the passed version file
63 // returns -1 on error
64 // 0 if we are an earlier version
66 // 2 if higher version
67 // fills in user version and latest version values if non-NULL
68 int version_compare(const char *filename, int *u_major, int *u_minor, int *u_build, int *l_major, int *l_minor, int *l_build)
70 int usr_major, usr_minor, usr_build;
71 int latest_major, latest_minor, latest_build;
73 // open file and try backup, if needed
74 CFILE *f = cfopen(filename, "rt", CFILE_NORMAL, CF_TYPE_DATA);
79 // grab the last line in file which isn't empty and isn't a comment
80 char buffer[MAX_LINE_LENGTH+1], verbuffer[MAX_LINE_LENGTH+1];
82 SDL_strlcpy(verbuffer, "", SDL_arraysize(verbuffer));
83 SDL_strlcpy(buffer, "", SDL_arraysize(buffer));
85 // Read the line into a temporary buffer
86 if ( cfgets(buffer, MAX_LINE_LENGTH, f) == NULL ) {
90 // take the \n off the end of it
91 if (strlen(buffer)>0 && buffer[strlen(buffer) - 1] == '\n')
92 buffer[strlen(buffer) - 1] = 0;
94 // If the line is empty, go get another one
95 if (strlen(buffer) == 0) continue;
97 // If the line is a comment, go get another one
98 if (buffer[0] == VERSION_FILE_COMMENT_CHAR) continue;
100 // Line is a good one, so save it...
101 SDL_strlcpy(verbuffer, buffer, SDL_arraysize(verbuffer));
105 // Make sure a version line was found
106 if (strlen(verbuffer) == 0) {
107 // MessageBox(XSTR("Couldn't parse Version file!", 1205), XSTR("Error!", 1185), MB_OK|MB_ICONERROR);
111 // Get the most up to date Version number
116 if (sscanf(verbuffer, "%i %i %i", &latest_major, &latest_minor, &latest_build) != 3) {
117 // MessageBox(XSTR("Couldn't parse Version file!", 1205), XSTR("Error!", 1185), MB_OK|MB_ICONERROR);
121 // retrieve the user's current version
122 usr_major = os_config_read_uint("Version", "Major", 0);
123 usr_minor = os_config_read_uint("Version", "Minor", 0);
124 usr_build = os_config_read_uint("Version", "Build", 0);
126 // Make sure the user's Version was found!
127 if ( VER(usr_major, usr_minor, usr_build) == 0 ) {
128 // MessageBox(XSTR("The Freespace 2 Auto-Update program could not find your current game Version in the system registry.\n\nThis should be corrected by starting up the game, exiting the game, and then running the Auto-Update program.", 1206), XSTR("Unable to Determine User's Version", 1207), MB_OK|MB_ICONERROR);
129 return NO_VERSION_IN_REGISTRY;
132 // stuff outgoing values
134 *u_major = usr_major;
137 *u_minor = usr_minor;
140 *u_build = usr_build;
143 *l_major = latest_major;
146 *l_minor = latest_minor;
149 *l_build = latest_build;
152 // check to see if the user's version is up to date
153 if (VER(usr_major, usr_minor, usr_build) < VER(latest_major, latest_minor, latest_build)) {