1 /*
2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
3 *
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 the
6 * source.
7 *
8 */
9
10 #include "globalincs/version.h"
11 #include "globalincs/pstypes.h"
12 #include "graphics/2d.h"
13
14 #include "parse/parselo.h"
15
16 namespace gameversion {
17
check_at_least(const version & v)18 bool check_at_least(const version& v) {
19 return get_executable_version() >= v;
20 }
21
format_version(const version & v)22 SCP_string format_version(const version& v) {
23 SCP_stringstream ss;
24
25 ss << v.major << "." << v.minor << "." << v.build;
26
27 if (v.revision != 0) {
28 ss << "." << v.revision;
29 }
30
31 return ss.str();
32 }
parse_version()33 version parse_version() {
34 version v;
35
36 required_string("+Major:");
37 stuff_int(&v.major);
38
39 required_string("+Minor:");
40 stuff_int(&v.minor);
41
42 required_string("+Build:");
43 stuff_int(&v.build);
44
45 if (optional_string("+Revision:")) {
46 stuff_int(&v.revision);
47 }
48
49 return v;
50 }
get_executable_version()51 version get_executable_version() {
52 version v;
53 v.major = FS_VERSION_MAJOR;
54 v.minor = FS_VERSION_MINOR;
55 v.build = FS_VERSION_BUILD;
56 v.revision = FS_VERSION_REVIS;
57
58 return v;
59 }
60
version(int major_in,int minor_in,int build_in,int revision_in)61 version::version(int major_in, int minor_in, int build_in, int revision_in) :
62 major(major_in), minor(minor_in), build(build_in), revision(revision_in) {
63 }
isValid() const64 bool version::isValid() const { return major != 0 || minor != 0 || build != 0 || revision != 0; }
operator <(const version & v) const65 bool version::operator<(const version& v) const {
66
67 if (major < v.major) {
68 return true;
69 }
70 if (major > v.major) {
71 // Major is greater than the given version => the rest doesn't matter
72 return false;
73 }
74 // major is now equal to our major version
75
76 if (minor < v.minor) {
77 return true;
78 }
79 if (minor > v.minor) {
80 // Minor is greater than the given version => the rest doesn't matter
81 return false;
82 }
83 // minor is now equal to our minor version
84
85 if (build < v.build) {
86 return true;
87 }
88 if (build > v.build) {
89 // build is greater than the given version => the rest doesn't matter
90 return false;
91 }
92 // build is now equal to our build version
93
94 if (revision == 0 || v.revision == 0) {
95 // Special case, if there is no revision info, then the versions are equal which means they are not less than each other
96 return false;
97 }
98
99 if (revision < v.revision) {
100 return true;
101 }
102 if (revision > v.revision) {
103 // build is greater than the given version => the rest doesn't matter
104 return false;
105 }
106
107 // revision is now equal to our revision version
108 return false;
109 }
operator ==(const version & other) const110 bool version::operator==(const version& other) const {
111 if (major == other.major && minor == other.minor && build == other.build) {
112 if (revision == 0 || other.revision == 0) {
113 // Zero revisions always means that these are equal
114 return true;
115 }
116
117 return revision == other.revision;
118 }
119
120 return false;
121 }
operator >(const version & other) const122 bool version::operator>(const version& other) const {
123 return other < *this;
124 }
operator <=(const version & other) const125 bool version::operator<=(const version& other) const {
126 return !(other < *this);
127 }
operator >=(const version & other) const128 bool version::operator>=(const version& other) const {
129 return !(*this < other);
130 }
operator !=(const version & other) const131 bool version::operator!=(const version& other) const {
132 return !(*this == other);
133 }
134
get_version_string()135 SCP_string get_version_string()
136 {
137 SCP_string str;
138
139 sprintf(str, "FreeSpace 2 Open v%s", FS_VERSION_FULL);
140
141 #ifndef NDEBUG
142 str += " Debug";
143 #endif
144
145 // Lets get some more info in here
146 switch (gr_screen.mode) {
147 case GR_OPENGL:
148 str += " OpenGL";
149 break;
150 case GR_VULKAN:
151 str += " Vulkan";
152 break;
153 }
154
155 return str;
156 }
157 }
158
159