OSDN Git Service

Added compiler detection for Visual Studio 2013 with Update-2.
[lamexp/LameXP.git] / src / Global_Version.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 //
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
22
23 #include "Global.h"
24
25 //LameXP includes
26 #define LAMEXP_INC_CONFIG
27 #include "Resource.h"
28 #include "Config.h"
29
30 //Qt includes
31 #include <QApplication>
32 #include <QDate>
33 #include <QFileInfo>
34 #include <QReadWriteLock>
35
36 ///////////////////////////////////////////////////////////////////////////////
37 // GLOBAL VARS
38 ///////////////////////////////////////////////////////////////////////////////
39
40 //Build version
41 static const struct
42 {
43         unsigned int ver_major;
44         unsigned int ver_minor;
45         unsigned int ver_build;
46         unsigned int ver_confg;
47         char *ver_release_name;
48 }
49 g_lamexp_version =
50 {
51         VER_LAMEXP_MAJOR,
52         (10 * VER_LAMEXP_MINOR_HI) + VER_LAMEXP_MINOR_LO,
53         VER_LAMEXP_BUILD,
54         VER_LAMEXP_CONFG,
55         VER_LAMEXP_RNAME,
56 };
57
58 //Portable Mode
59 static struct
60 {
61         bool bInitialized;
62         bool bPortableModeEnabled;
63         QReadWriteLock lock;
64 }
65 g_lamexp_portable;
66
67 //Build date
68 static QDate g_lamexp_version_date;
69 static const char *g_lamexp_months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
70 static const char *g_lamexp_version_raw_date = __DATE__;
71 static const char *g_lamexp_version_raw_time = __TIME__;
72
73 //Official web-site URL
74 static const char *g_lamexp_website_url = "http://lamexp.sourceforge.net/";
75 static const char *g_lamexp_support_url = "http://forum.doom9.org/showthread.php?t=157726";
76 static const char *g_lamexp_mulders_url = "http://muldersoft.com/";
77
78 //Tool versions (expected versions!)
79 static const unsigned int g_lamexp_toolver_neroaac = VER_LAMEXP_TOOL_NEROAAC;
80 static const unsigned int g_lamexp_toolver_fhgaacenc = VER_LAMEXP_TOOL_FHGAACENC;
81 static const unsigned int g_lamexp_toolver_qaacenc = VER_LAMEXP_TOOL_QAAC;
82 static const unsigned int g_lamexp_toolver_coreaudio = VER_LAMEXP_TOOL_COREAUDIO;
83
84 ///////////////////////////////////////////////////////////////////////////////
85 // COMPILER INFO
86 ///////////////////////////////////////////////////////////////////////////////
87
88 /*
89  * Disclaimer: Parts of the following code were borrowed from MPC-HC project: http://mpc-hc.sf.net/
90  */
91
92 //Compiler detection
93 #if defined(__INTEL_COMPILER)
94         #if (__INTEL_COMPILER >= 1300)
95                 static const char *g_lamexp_version_compiler = "ICL 13." LAMEXP_MAKE_STR(__INTEL_COMPILER_BUILD_DATE);
96         #elif (__INTEL_COMPILER >= 1200)
97                 static const char *g_lamexp_version_compiler = "ICL 12." LAMEXP_MAKE_STR(__INTEL_COMPILER_BUILD_DATE);
98         #elif (__INTEL_COMPILER >= 1100)
99                 static const char *g_lamexp_version_compiler = "ICL 11.x";
100         #elif (__INTEL_COMPILER >= 1000)
101                 static const char *g_lamexp_version_compiler = "ICL 10.x";
102         #else
103                 #error Compiler is not supported!
104         #endif
105 #elif defined(_MSC_VER)
106         #if (_MSC_VER == 1800)
107                 #if (_MSC_FULL_VER < 180021005)
108                         static const char *g_lamexp_version_compiler = "MSVC 2013-Beta";
109                 #elif (_MSC_FULL_VER < 180030501)
110                         static const char *g_lamexp_version_compiler = "MSVC 2013";
111                 #elif (_MSC_FULL_VER == 180030501)
112                         static const char *g_lamexp_version_compiler = "MSVC 2013.2";
113                 #else
114                         #error Compiler version is not supported yet!
115                 #endif
116         #elif (_MSC_VER == 1700)
117                 #if (_MSC_FULL_VER < 170050727)
118                         static const char *g_lamexp_version_compiler = "MSVC 2012-Beta";
119                 #elif (_MSC_FULL_VER < 170051020)
120                         static const char *g_lamexp_version_compiler = "MSVC 2012";
121                 #elif (_MSC_FULL_VER < 170051106)
122                         static const char *g_lamexp_version_compiler = "MSVC 2012.1-CTP";
123                 #elif (_MSC_FULL_VER < 170060315)
124                         static const char *g_lamexp_version_compiler = "MSVC 2012.1";
125                 #elif (_MSC_FULL_VER < 170060610)
126                         static const char *g_lamexp_version_compiler = "MSVC 2012.2";
127                 #elif (_MSC_FULL_VER < 170061030)
128                         static const char *g_lamexp_version_compiler = "MSVC 2012.3";
129                 #elif (_MSC_FULL_VER == 170061030)
130                         static const char *g_lamexp_version_compiler = "MSVC 2012.4";
131                 #else
132                         #error Compiler version is not supported yet!
133                 #endif
134         #elif (_MSC_VER == 1600)
135                 #if (_MSC_FULL_VER < 160040219)
136                         static const char *g_lamexp_version_compiler = "MSVC 2010";
137                 #elif (_MSC_FULL_VER == 160040219)
138                         static const char *g_lamexp_version_compiler = "MSVC 2010-SP1";
139                 #else
140                         #error Compiler version is not supported yet!
141                 #endif
142         #elif (_MSC_VER == 1500)
143                 #if (_MSC_FULL_VER >= 150030729)
144                         static const char *g_lamexp_version_compiler = "MSVC 2008-SP1";
145                 #else
146                         static const char *g_lamexp_version_compiler = "MSVC 2008";
147                 #endif
148         #else
149                 #error Compiler is not supported!
150         #endif
151
152         // Note: /arch:SSE and /arch:SSE2 are only available for the x86 platform
153         #if !defined(_M_X64) && defined(_M_IX86_FP)
154                 #if (_M_IX86_FP == 1)
155                         LAMEXP_COMPILER_WARNING("SSE instruction set is enabled!")
156                 #elif (_M_IX86_FP == 2)
157                         LAMEXP_COMPILER_WARNING("SSE2 (or higher) instruction set is enabled!")
158                 #endif
159         #endif
160 #else
161         #error Compiler is not supported!
162 #endif
163
164 //Architecture detection
165 #if defined(_M_X64)
166         static const char *g_lamexp_version_arch = "x64";
167 #elif defined(_M_IX86)
168         static const char *g_lamexp_version_arch = "x86";
169 #else
170         #error Architecture is not supported!
171 #endif
172
173 ///////////////////////////////////////////////////////////////////////////////
174 // GLOBAL FUNCTIONS
175 ///////////////////////////////////////////////////////////////////////////////
176
177 /*
178  * Version getters
179  */
180 unsigned int lamexp_version_major(void)     { return g_lamexp_version.ver_major; }
181 unsigned int lamexp_version_minor(void)     { return g_lamexp_version.ver_minor; }
182 unsigned int lamexp_version_build(void)     { return g_lamexp_version.ver_build; }
183 unsigned int lamexp_version_confg(void)     { return g_lamexp_version.ver_confg; }
184 const char *lamexp_version_release(void)    { return g_lamexp_version.ver_release_name; }
185 const char *lamexp_version_time(void)       { return g_lamexp_version_raw_time; }
186 const char *lamexp_version_compiler(void)   { return g_lamexp_version_compiler; }
187 const char *lamexp_version_arch(void)       { return g_lamexp_version_arch; }
188 unsigned int lamexp_toolver_neroaac(void)   { return g_lamexp_toolver_neroaac; }
189 unsigned int lamexp_toolver_fhgaacenc(void) { return g_lamexp_toolver_fhgaacenc; }
190 unsigned int lamexp_toolver_qaacenc(void)   { return g_lamexp_toolver_qaacenc; }
191 unsigned int lamexp_toolver_coreaudio(void) { return g_lamexp_toolver_coreaudio; }
192
193 /*
194  * URL getters
195  */
196 const char *lamexp_website_url(void) { return g_lamexp_website_url; }
197 const char *lamexp_mulders_url(void) { return g_lamexp_mulders_url; }
198 const char *lamexp_support_url(void) { return g_lamexp_support_url; }
199
200 /*
201  * Check for Demo (pre-release) version
202  */
203 bool lamexp_version_demo(void)
204 {
205         char buffer[128];
206         bool releaseVersion = false;
207         if(!strncpy_s(buffer, 128, g_lamexp_version.ver_release_name, _TRUNCATE))
208         {
209                 char *context, *prefix = strtok_s(buffer, "-,; ", &context);
210                 if(prefix)
211                 {
212                         releaseVersion = (!_stricmp(prefix, "Final")) || (!_stricmp(prefix, "Hotfix"));
213                 }
214         }
215         return (!releaseVersion);
216 }
217
218 /*
219  * Calculate expiration date
220  */
221 QDate lamexp_version_expires(void)
222 {
223         return lamexp_version_date().addDays(LAMEXP_DEBUG ? 7 : 30);
224 }
225
226 /*
227  * Convert month string to integer value
228  */
229 static int lamexp_month2int(const char *str)
230 {
231         int ret = 0;
232
233         for(int j = 0; j < 12; j++)
234         {
235                 if(!_strcmpi(str, g_lamexp_months[j]))
236                 {
237                         ret = j+1;
238                         break;
239                 }
240         }
241
242         return ret;
243 }
244
245 /*
246  * Get build date date
247  */
248 const QDate &lamexp_version_date(void)
249 {
250         //Format of __DATE__ is defined as: "MMM DD YYYY"
251         if(!g_lamexp_version_date.isValid())
252         {
253                 int date[3] = {0, 0, 0};
254                 char temp_m[4], temp_d[3], temp_y[5];
255
256                 temp_m[0] = g_lamexp_version_raw_date[0x0];
257                 temp_m[1] = g_lamexp_version_raw_date[0x1];
258                 temp_m[2] = g_lamexp_version_raw_date[0x2];
259                 temp_m[3] = 0x00;
260
261                 temp_d[0] = g_lamexp_version_raw_date[0x4];
262                 temp_d[1] = g_lamexp_version_raw_date[0x5];
263                 temp_d[2] = 0x00;
264
265                 temp_y[0] = g_lamexp_version_raw_date[0x7];
266                 temp_y[1] = g_lamexp_version_raw_date[0x8];
267                 temp_y[2] = g_lamexp_version_raw_date[0x9];
268                 temp_y[3] = g_lamexp_version_raw_date[0xA];
269                 temp_y[4] = 0x00;
270                 
271                 date[0] = atoi(temp_y);
272                 date[1] = lamexp_month2int(temp_m);
273                 date[2] = atoi(temp_d);
274
275                 if((date[0] > 0) && (date[1] > 0) && (date[2] > 0))
276                 {
277
278                         g_lamexp_version_date = QDate(date[0], date[1], date[2]);
279                 }
280                 else
281                 {
282                         THROW("Internal error: Date format could not be recognized!");
283                 }
284         }
285
286         return g_lamexp_version_date;
287 }
288
289 /*
290  * Check for LameXP "portable" mode
291  */
292 bool lamexp_portable_mode(void)
293 {
294         QReadLocker readLock(&g_lamexp_portable.lock);
295
296         if(g_lamexp_portable.bInitialized)
297         {
298                 return g_lamexp_portable.bPortableModeEnabled;
299         }
300         
301         readLock.unlock();
302         QWriteLocker writeLock(&g_lamexp_portable.lock);
303
304         if(!g_lamexp_portable.bInitialized)
305         {
306                 if(VER_LAMEXP_PORTABLE_EDITION)
307                 {
308                         qWarning("LameXP portable edition!\n");
309                         g_lamexp_portable.bPortableModeEnabled = true;
310                 }
311                 else
312                 {
313                         QString baseName = QFileInfo(QApplication::applicationFilePath()).completeBaseName();
314                         int idx1 = baseName.indexOf("lamexp", 0, Qt::CaseInsensitive);
315                         int idx2 = baseName.lastIndexOf("portable", -1, Qt::CaseInsensitive);
316                         g_lamexp_portable.bPortableModeEnabled = ((idx1 >= 0) && (idx2 >= 0) && (idx1 < idx2));
317                 }
318                 g_lamexp_portable.bInitialized = true;
319         }
320         
321         return g_lamexp_portable.bPortableModeEnabled;
322 }
323
324 ///////////////////////////////////////////////////////////////////////////////
325 // INITIALIZATION
326 ///////////////////////////////////////////////////////////////////////////////
327
328 extern "C" void _lamexp_global_init_versn(void)
329 {
330         LAMEXP_ZERO_MEMORY(g_lamexp_portable);
331 }
332
333 ///////////////////////////////////////////////////////////////////////////////
334 // FINALIZATION
335 ///////////////////////////////////////////////////////////////////////////////
336
337 extern "C" void _lamexp_global_free_versn(void)
338 {
339         /*nothing to do here*/
340 }