31
31
#include " GameClient/GameText.h"
32
32
#include " Common/version.h"
33
33
34
+ #include " gitinfo.h"
35
+
34
36
Version *TheVersion = NULL ; // /< The Version singleton
35
37
36
38
Version::Version ()
@@ -39,8 +41,14 @@ Version::Version()
39
41
m_minor = 0 ;
40
42
m_buildNum = 0 ;
41
43
m_localBuildNum = 0 ;
42
- m_buildUser = AsciiString (" somebody" );
43
- m_buildLocation = AsciiString (" somewhere" );
44
+ m_buildUser = " somebody" ;
45
+ m_buildLocation = " somewhere" ;
46
+ m_asciiGitRevision = buildAsciiGitRevision ();
47
+ m_asciiGitVersion = buildAsciiGitVersion ();
48
+ m_asciiGitCommitTime = buildAsciiGitCommitTime ();
49
+ m_unicodeGitRevision = buildUnicodeGitRevision ();
50
+ m_unicodeGitVersion = buildUnicodeGitVersion ();
51
+ m_unicodeGitCommitTime = buildUnicodeGitCommitTime ();
44
52
#if defined RTS_DEBUG || defined RTS_INTERNAL
45
53
m_showFullVersion = TRUE ;
46
54
#else
@@ -62,12 +70,12 @@ void Version::setVersion(Int major, Int minor, Int buildNum,
62
70
m_buildDate = buildDate;
63
71
}
64
72
65
- UnsignedInt Version::getVersionNumber ( void )
73
+ UnsignedInt Version::getVersionNumber ( void ) const
66
74
{
67
75
return m_major << 16 | m_minor;
68
76
}
69
77
70
- AsciiString Version::getAsciiVersion ( void )
78
+ AsciiString Version::getAsciiVersion ( void ) const
71
79
{
72
80
AsciiString version;
73
81
#if defined RTS_DEBUG || defined RTS_INTERNAL
@@ -83,19 +91,22 @@ AsciiString Version::getAsciiVersion( void )
83
91
return version;
84
92
}
85
93
86
- UnicodeString Version::getUnicodeVersion ( void )
94
+ UnicodeString Version::getUnicodeVersion ( void ) const
87
95
{
88
96
UnicodeString version;
89
97
90
- #if defined RTS_DEBUG || defined RTS_INTERNAL
91
- if (!m_localBuildNum)
92
- version.format (TheGameText->fetch (" Version:Format3" ).str (), m_major, m_minor, m_buildNum);
98
+ if (m_showFullVersion)
99
+ {
100
+ if (!m_localBuildNum)
101
+ version.format (TheGameText->fetch (" Version:Format3" ).str (), m_major, m_minor, m_buildNum);
102
+ else
103
+ version.format (TheGameText->fetch (" Version:Format4" ).str (), m_major, m_minor, m_buildNum, m_localBuildNum,
104
+ m_buildUser.getCharAt (0 ), m_buildUser.getCharAt (1 ));
105
+ }
93
106
else
94
- version.format (TheGameText->fetch (" Version:Format4" ).str (), m_major, m_minor, m_buildNum, m_localBuildNum,
95
- m_buildUser.getCharAt (0 ), m_buildUser.getCharAt (1 ));
96
- #else // defined RTS_DEBUG || defined RTS_INTERNAL
97
- version.format (TheGameText->fetch (" Version:Format2" ).str (), m_major, m_minor);
98
- #endif // defined RTS_DEBUG || defined RTS_INTERNAL
107
+ {
108
+ version.format (TheGameText->fetch (" Version:Format2" ).str (), m_major, m_minor);
109
+ }
99
110
100
111
#ifdef RTS_DEBUG
101
112
version.concat (UnicodeString (L" Debug" ));
@@ -108,36 +119,15 @@ UnicodeString Version::getUnicodeVersion( void )
108
119
return version;
109
120
}
110
121
111
- UnicodeString Version::getFullUnicodeVersion ( void )
112
- {
113
- UnicodeString version;
114
-
115
- if (!m_localBuildNum)
116
- version.format (TheGameText->fetch (" Version:Format3" ).str (), m_major, m_minor, m_buildNum);
117
- else
118
- version.format (TheGameText->fetch (" Version:Format4" ).str (), m_major, m_minor, m_buildNum, m_localBuildNum,
119
- m_buildUser.getCharAt (0 ), m_buildUser.getCharAt (1 ));
120
-
121
- #ifdef RTS_DEBUG
122
- version.concat (UnicodeString (L" Debug" ));
123
- #endif
124
-
125
- #ifdef RTS_INTERNAL
126
- version.concat (UnicodeString (L" Internal" ));
127
- #endif
128
-
129
- return version;
130
- }
131
-
132
- AsciiString Version::getAsciiBuildTime ( void )
122
+ AsciiString Version::getAsciiBuildTime ( void ) const
133
123
{
134
124
AsciiString timeStr;
135
125
timeStr.format (" %s %s" , m_buildDate.str (), m_buildTime.str ());
136
126
137
127
return timeStr;
138
128
}
139
129
140
- UnicodeString Version::getUnicodeBuildTime ( void )
130
+ UnicodeString Version::getUnicodeBuildTime ( void ) const
141
131
{
142
132
UnicodeString build;
143
133
UnicodeString dateStr;
@@ -150,34 +140,117 @@ UnicodeString Version::getUnicodeBuildTime( void )
150
140
return build;
151
141
}
152
142
153
- AsciiString Version::getAsciiBuildLocation ( void )
143
+ AsciiString Version::getAsciiBuildLocation ( void ) const
154
144
{
155
- return AsciiString ( m_buildLocation) ;
145
+ return m_buildLocation;
156
146
}
157
147
158
- UnicodeString Version::getUnicodeBuildLocation ( void )
148
+ UnicodeString Version::getUnicodeBuildLocation ( void ) const
159
149
{
160
150
UnicodeString build;
161
151
UnicodeString machine;
162
152
163
- machine.translate (AsciiString ( m_buildLocation) );
153
+ machine.translate (m_buildLocation);
164
154
build.format (TheGameText->fetch (" Version:BuildMachine" ).str (), machine.str ());
165
155
166
156
return build;
167
157
}
168
158
169
- AsciiString Version::getAsciiBuildUser ( void )
159
+ AsciiString Version::getAsciiBuildUser ( void ) const
170
160
{
171
- return AsciiString ( m_buildUser) ;
161
+ return m_buildUser;
172
162
}
173
163
174
- UnicodeString Version::getUnicodeBuildUser ( void )
164
+ UnicodeString Version::getUnicodeBuildUser ( void ) const
175
165
{
176
166
UnicodeString build;
177
167
UnicodeString user;
178
168
179
- user.translate (AsciiString ( m_buildUser) );
169
+ user.translate (m_buildUser);
180
170
build.format (TheGameText->fetch (" Version:BuildUser" ).str (), user.str ());
181
171
182
172
return build;
183
173
}
174
+
175
+ Int Version::getGitRevision ()
176
+ {
177
+ return GitRevision;
178
+ }
179
+
180
+ time_t Version::getGitCommitTime ()
181
+ {
182
+ return GitCommitTimeStamp;
183
+ }
184
+
185
+ UnicodeString Version::getUnicodeGameAndGitVersion ( void ) const
186
+ {
187
+ UnicodeString str;
188
+ if (m_showFullVersion)
189
+ {
190
+ str.format (L" %s %s %s" ,
191
+ getUnicodeVersion ().str (),
192
+ getUnicodeGitRevision ().str (),
193
+ getUnicodeGitVersion ().str ());
194
+ }
195
+ else
196
+ {
197
+ str.format (L" %s %s" ,
198
+ getUnicodeVersion ().str (),
199
+ getUnicodeGitRevision ().str ());
200
+ }
201
+ return str;
202
+ }
203
+
204
+ AsciiString Version::buildAsciiGitRevision ()
205
+ {
206
+ AsciiString str;
207
+ str.format (" R %s%d" ,
208
+ GitUncommittedChanges ? " ~" : " " ,
209
+ GitRevision);
210
+ return str;
211
+ }
212
+
213
+ AsciiString Version::buildAsciiGitVersion ()
214
+ {
215
+ AsciiString str;
216
+ str.format (" %s%s" ,
217
+ GitUncommittedChanges ? " ~" : " " ,
218
+ GitTag[0 ] ? GitTag : GitShortSHA1);
219
+ return str;
220
+ }
221
+
222
+ AsciiString Version::buildAsciiGitCommitTime ()
223
+ {
224
+ const Int len = 19 ;
225
+ AsciiString str;
226
+ Char* buf = str.getBufferForRead (len);
227
+ tm* time = gmtime (&GitCommitTimeStamp);
228
+ strftime (buf, len+1 , " %Y-%m-%d %H:%M:%S" , time);
229
+ return str;
230
+ }
231
+
232
+ UnicodeString Version::buildUnicodeGitRevision ()
233
+ {
234
+ UnicodeString str;
235
+ str.format (L" R %s%d" ,
236
+ GitUncommittedChanges ? L" ~" : L" " ,
237
+ GitRevision);
238
+ return str;
239
+ }
240
+
241
+ UnicodeString Version::buildUnicodeGitVersion ()
242
+ {
243
+ UnicodeString str;
244
+ str.translate (buildAsciiGitVersion ());
245
+ return str;
246
+ }
247
+
248
+ UnicodeString Version::buildUnicodeGitCommitTime ()
249
+ {
250
+ const Int len = 19 ;
251
+ UnicodeString str;
252
+ WideChar* buf = str.getBufferForRead (len);
253
+ tm* time = gmtime (&GitCommitTimeStamp);
254
+ wcsftime (buf, len+1 , L" %Y-%m-%d %H:%M:%S" , time);
255
+ return str;
256
+ }
0 commit comments