|
7 | 7 | * |
8 | 8 | */ |
9 | 9 |
|
10 | | - |
11 | | - |
12 | | -#include <stdio.h> |
13 | | -#include <string.h> |
14 | 10 | #include "globalincs/pstypes.h" |
15 | 11 | #include "globalincs/version.h" |
16 | | -#include "osapi/osregistry.h" |
17 | | - |
18 | | - |
19 | | -// ---------------------------------------------------------------------------------------------------------------- |
20 | | -// VERSION DEFINES/VARS |
21 | | -// |
22 | | - |
23 | | -// Defines |
24 | | -// NB: for compatibility reasons, this must not include the SVN revision |
25 | | -#define VER(major, minor, build) (100*100*major+100*minor+build) |
26 | | -#define MAX_LINE_LENGTH 512 |
27 | | - |
28 | | - |
29 | | -// ---------------------------------------------------------------------------------------------------------------- |
30 | | -// VERSION FUNCTIONS |
31 | | -// |
32 | | - |
33 | | -// compare version against the passed version file |
34 | | -// returns -1 on error |
35 | | -// 0 if we are an earlier version |
36 | | -// 1 if same version |
37 | | -// 2 if higher version |
38 | | -// fills in user version and latest version values if non-NULL |
39 | | -// |
40 | | -// NB: since this function is only used for multiplayer (in multi_update.cpp - and actually commented out), and since multiplayer |
41 | | -// doesn't care about SVN revisions, this function doesn't need to check the SVN revision |
42 | | -int version_compare(char *filename, int *u_major, int *u_minor, int *u_build, int *l_major, int *l_minor, int *l_build) |
43 | | -{ |
44 | | - int usr_major, usr_minor, usr_build; |
45 | | - int latest_major, latest_minor, latest_build; |
46 | | - |
47 | | - // open file and try backup, if needed |
48 | | - FILE *f = fopen(filename, "rt"); |
49 | | - if (f == NULL) { |
50 | | - return -1; |
51 | | - } |
52 | 12 |
|
53 | | - // grab the last line in file which isn't empty and isn't a comment |
54 | | - char buffer[MAX_LINE_LENGTH+1] = {0}; |
55 | | - char verbuffer[MAX_LINE_LENGTH+1] = {0}; |
| 13 | +#include <sstream> |
56 | 14 |
|
57 | | - while ( !feof(f) ) { |
58 | | - // Read the line into a temporary buffer or break if there is nothing |
59 | | - if (fgets(buffer, MAX_LINE_LENGTH, f) == nullptr) { |
60 | | - break; |
| 15 | +namespace version |
| 16 | +{ |
| 17 | + bool check_at_least(int major, int minor, int build, int revision) |
| 18 | + { |
| 19 | + if (FS_VERSION_MAJOR < major) |
| 20 | + { |
| 21 | + return false; |
61 | 22 | } |
62 | | - |
63 | | - // take the \n off the end of it |
64 | | - if (buffer[0] != '\0' && buffer[strlen(buffer) - 1] == '\n') |
65 | | - buffer[strlen(buffer) - 1] = 0; |
66 | | - |
67 | | - // If the line is empty, go get another one |
68 | | - if (buffer[0] == '\0') continue; |
69 | | - |
70 | | - // If the line is a comment, go get another one |
71 | | - if (buffer[0] == VERSION_FILE_COMMENT_CHAR) continue; |
72 | | - |
73 | | - // Line is a good one, so save it... |
74 | | - strcpy_s(verbuffer, buffer); |
75 | | - } |
76 | | - fclose(f); |
77 | | - |
78 | | - // Make sure a version line was found |
79 | | - if (verbuffer[0] == '\0') { |
80 | | - // MessageBox(XSTR("Couldn't parse Version file!", 1205), XSTR("Error!", 1185), MB_OK|MB_ICONERROR); |
81 | | - return -1; |
82 | | - } |
83 | | - |
84 | | - // Get the most up to date Version number |
85 | | - latest_major = 0; |
86 | | - latest_minor = 0; |
87 | | - latest_build = 0; |
88 | | - |
89 | | - if (sscanf(verbuffer, "%i %i %i", &latest_major, &latest_minor, &latest_build) != 3) { |
90 | | - // MessageBox(XSTR("Couldn't parse Version file!", 1205), XSTR("Error!", 1185), MB_OK|MB_ICONERROR); |
91 | | - return -1; |
| 23 | + if (FS_VERSION_MAJOR > major) |
| 24 | + { |
| 25 | + // Major is greater than the given version => the rest doesn't matter |
| 26 | + return true; |
| 27 | + } |
| 28 | + // major is now equal to our major version |
| 29 | + |
| 30 | + if (FS_VERSION_MINOR < minor) |
| 31 | + { |
| 32 | + return false; |
| 33 | + } |
| 34 | + if (FS_VERSION_MINOR > minor) |
| 35 | + { |
| 36 | + // Minor is greater than the given version => the rest doesn't matter |
| 37 | + return true; |
| 38 | + } |
| 39 | + // minor is now equal to our minor version |
| 40 | + |
| 41 | + if (FS_VERSION_BUILD < build) |
| 42 | + { |
| 43 | + return false; |
| 44 | + } |
| 45 | + if (FS_VERSION_BUILD > build) |
| 46 | + { |
| 47 | + // build is greater than the given version => the rest doesn't matter |
| 48 | + return true; |
| 49 | + } |
| 50 | + // build is now equal to our build version |
| 51 | + |
| 52 | + if (revision == 0) |
| 53 | + { |
| 54 | + // Special case, if there is no revision info, skip it |
| 55 | + return true; |
| 56 | + } |
| 57 | + if (FS_VERSION_REVIS == 0) |
| 58 | + { |
| 59 | + // Special case, when there is no revision ignore it |
| 60 | + return true; |
| 61 | + } |
| 62 | + |
| 63 | + if (FS_VERSION_REVIS < revision) |
| 64 | + { |
| 65 | + return false; |
| 66 | + } |
| 67 | + if (FS_VERSION_REVIS > revision) |
| 68 | + { |
| 69 | + // build is greater than the given version => the rest doesn't matter |
| 70 | + return true; |
| 71 | + } |
| 72 | + |
| 73 | + // revision is now equal to our revision version |
| 74 | + return true; |
92 | 75 | } |
93 | | - |
94 | | - // retrieve the user's current version |
95 | | - usr_major = os_config_read_uint("Version", "Major", 0); |
96 | | - usr_minor = os_config_read_uint("Version", "Minor", 0); |
97 | | - usr_build = os_config_read_uint("Version", "Build", 0); |
98 | 76 |
|
99 | | - // Make sure the user's Version was found! |
100 | | - if ( VER(usr_major, usr_minor, usr_build) == 0 ) { |
101 | | - // 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); |
102 | | - return NO_VERSION_IN_REGISTRY; |
103 | | - } |
104 | | - |
105 | | - // stuff outgoing values |
106 | | - if(u_major != NULL){ |
107 | | - *u_major = usr_major; |
108 | | - } |
109 | | - if(u_minor != NULL){ |
110 | | - *u_minor = usr_minor; |
111 | | - } |
112 | | - if(u_build != NULL){ |
113 | | - *u_build = usr_build; |
114 | | - } |
115 | | - if(l_major != NULL){ |
116 | | - *l_major = latest_major; |
117 | | - } |
118 | | - if(l_minor != NULL){ |
119 | | - *l_minor = latest_minor; |
120 | | - } |
121 | | - if(l_build != NULL){ |
122 | | - *l_build = latest_build; |
123 | | - } |
124 | | - |
125 | | - // check to see if the user's version is up to date |
126 | | - if (VER(usr_major, usr_minor, usr_build) < VER(latest_major, latest_minor, latest_build)) { |
127 | | - return 0; |
| 77 | + SCP_string format_version(int major, int minor, int build, int revision) |
| 78 | + { |
| 79 | + SCP_stringstream ss; |
| 80 | + |
| 81 | + ss << major << "." << minor << "." << build; |
| 82 | + |
| 83 | + if (revision != 0) |
| 84 | + { |
| 85 | + ss << "." << revision; |
| 86 | + } |
| 87 | + |
| 88 | + return ss.str(); |
128 | 89 | } |
129 | | - |
130 | | - // same version |
131 | | - return 1; |
132 | 90 | } |
| 91 | + |
0 commit comments