1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
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.
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.
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.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
26 #define LAMEXP_INC_CONFIG
31 #include <QApplication>
34 #include <QReadWriteLock>
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
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;
52 (10 * VER_LAMEXP_MINOR_HI) + VER_LAMEXP_MINOR_LO,
62 bool bPortableModeEnabled;
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__;
73 //Official web-site URL
74 static const char *g_lamexp_website_url = "http://lamexp.sourceforge.net/";
75 static const char *g_lamexp_mulders_url = "http://muldersoft.com/";
76 static const char *g_lamexp_support_url = "http://forum.doom9.org/showthread.php?t=157726";
77 static const char *g_lamexp_tracker_url = "https://github.com/lordmulder/LameXP/issues";
79 //Tool versions (expected versions!)
80 static const unsigned int g_lamexp_toolver_neroaac = VER_LAMEXP_TOOL_NEROAAC;
81 static const unsigned int g_lamexp_toolver_fhgaacenc = VER_LAMEXP_TOOL_FHGAACENC;
82 static const unsigned int g_lamexp_toolver_qaacenc = VER_LAMEXP_TOOL_QAAC;
83 static const unsigned int g_lamexp_toolver_coreaudio = VER_LAMEXP_TOOL_COREAUDIO;
85 ///////////////////////////////////////////////////////////////////////////////
87 ///////////////////////////////////////////////////////////////////////////////
90 * Disclaimer: Parts of the following code were borrowed from MPC-HC project: http://mpc-hc.sf.net/
94 #if defined(__INTEL_COMPILER)
95 #if (__INTEL_COMPILER >= 1300)
96 static const char *g_lamexp_version_compiler = "ICL 13." LAMEXP_MAKE_STR(__INTEL_COMPILER_BUILD_DATE);
97 #elif (__INTEL_COMPILER >= 1200)
98 static const char *g_lamexp_version_compiler = "ICL 12." LAMEXP_MAKE_STR(__INTEL_COMPILER_BUILD_DATE);
99 #elif (__INTEL_COMPILER >= 1100)
100 static const char *g_lamexp_version_compiler = "ICL 11.x";
101 #elif (__INTEL_COMPILER >= 1000)
102 static const char *g_lamexp_version_compiler = "ICL 10.x";
104 #error Compiler is not supported!
106 #elif defined(_MSC_VER)
107 #if (_MSC_VER == 1800)
108 #if (_MSC_FULL_VER == 180021005)
109 static const char *g_lamexp_version_compiler = "MSVC 2013";
110 #elif (_MSC_FULL_VER == 180030501)
111 static const char *g_lamexp_version_compiler = "MSVC 2013.2";
112 #elif (_MSC_FULL_VER == 180030723)
113 static const char *g_lamexp_version_compiler = "MSVC 2013.3";
114 #elif (_MSC_FULL_VER == 180031101)
115 static const char *g_lamexp_version_compiler = "MSVC 2013.4";
117 #error Compiler version is not supported yet!
119 #elif (_MSC_VER == 1700)
120 #if (_MSC_FULL_VER == 170050727)
121 static const char *g_lamexp_version_compiler = "MSVC 2012";
122 #elif (_MSC_FULL_VER == 170051106)
123 static const char *g_lamexp_version_compiler = "MSVC 2012.1";
124 #elif (_MSC_FULL_VER == 170060315)
125 static const char *g_lamexp_version_compiler = "MSVC 2012.2";
126 #elif (_MSC_FULL_VER == 170060610)
127 static const char *g_lamexp_version_compiler = "MSVC 2012.3";
128 #elif (_MSC_FULL_VER == 170061030)
129 static const char *g_lamexp_version_compiler = "MSVC 2012.4";
131 #error Compiler version is not supported yet!
133 #elif (_MSC_VER == 1600)
134 #if (_MSC_FULL_VER >= 160040219)
135 static const char *g_lamexp_version_compiler = "MSVC 2010-SP1";
137 static const char *g_lamexp_version_compiler = "MSVC 2010";
139 #elif (_MSC_VER == 1500)
140 #if (_MSC_FULL_VER >= 150030729)
141 static const char *g_lamexp_version_compiler = "MSVC 2008-SP1";
143 static const char *g_lamexp_version_compiler = "MSVC 2008";
146 #error Compiler is not supported!
149 // Note: /arch:SSE and /arch:SSE2 are only available for the x86 platform
150 #if !defined(_M_X64) && defined(_M_IX86_FP)
151 #if (_M_IX86_FP == 1)
152 LAMEXP_COMPILER_WARNING("SSE instruction set is enabled!")
153 #elif (_M_IX86_FP == 2)
154 LAMEXP_COMPILER_WARNING("SSE2 (or higher) instruction set is enabled!")
158 #error Compiler is not supported!
161 //Architecture detection
163 static const char *g_lamexp_version_arch = "x64";
164 #elif defined(_M_IX86)
165 static const char *g_lamexp_version_arch = "x86";
167 #error Architecture is not supported!
170 ///////////////////////////////////////////////////////////////////////////////
172 ///////////////////////////////////////////////////////////////////////////////
177 unsigned int lamexp_version_major(void) { return g_lamexp_version.ver_major; }
178 unsigned int lamexp_version_minor(void) { return g_lamexp_version.ver_minor; }
179 unsigned int lamexp_version_build(void) { return g_lamexp_version.ver_build; }
180 unsigned int lamexp_version_confg(void) { return g_lamexp_version.ver_confg; }
181 const char *lamexp_version_release(void) { return g_lamexp_version.ver_release_name; }
182 const char *lamexp_version_time(void) { return g_lamexp_version_raw_time; }
183 const char *lamexp_version_compiler(void) { return g_lamexp_version_compiler; }
184 const char *lamexp_version_arch(void) { return g_lamexp_version_arch; }
185 unsigned int lamexp_toolver_neroaac(void) { return g_lamexp_toolver_neroaac; }
186 unsigned int lamexp_toolver_fhgaacenc(void) { return g_lamexp_toolver_fhgaacenc; }
187 unsigned int lamexp_toolver_qaacenc(void) { return g_lamexp_toolver_qaacenc; }
188 unsigned int lamexp_toolver_coreaudio(void) { return g_lamexp_toolver_coreaudio; }
193 const char *lamexp_website_url(void) { return g_lamexp_website_url; }
194 const char *lamexp_mulders_url(void) { return g_lamexp_mulders_url; }
195 const char *lamexp_support_url(void) { return g_lamexp_support_url; }
196 const char *lamexp_tracker_url(void) { return g_lamexp_tracker_url; }
199 * Check for Demo (pre-release) version
201 bool lamexp_version_demo(void)
204 bool releaseVersion = false;
205 if(!strncpy_s(buffer, 128, g_lamexp_version.ver_release_name, _TRUNCATE))
207 char *context, *prefix = strtok_s(buffer, "-,; ", &context);
210 releaseVersion = (!_stricmp(prefix, "Final")) || (!_stricmp(prefix, "Hotfix"));
213 return (!releaseVersion);
217 * Calculate expiration date
219 QDate lamexp_version_expires(void)
221 return lamexp_version_date().addDays(LAMEXP_DEBUG ? 7 : 30);
225 * Convert month string to integer value
227 static int lamexp_month2int(const char *str)
231 for(int j = 0; j < 12; j++)
233 if(!_strcmpi(str, g_lamexp_months[j]))
244 * Get build date date
246 const QDate &lamexp_version_date(void)
248 //Format of __DATE__ is defined as: "MMM DD YYYY"
249 if(!g_lamexp_version_date.isValid())
251 int date[3] = {0, 0, 0};
252 char temp_m[4], temp_d[3], temp_y[5];
254 temp_m[0] = g_lamexp_version_raw_date[0x0];
255 temp_m[1] = g_lamexp_version_raw_date[0x1];
256 temp_m[2] = g_lamexp_version_raw_date[0x2];
259 temp_d[0] = g_lamexp_version_raw_date[0x4];
260 temp_d[1] = g_lamexp_version_raw_date[0x5];
263 temp_y[0] = g_lamexp_version_raw_date[0x7];
264 temp_y[1] = g_lamexp_version_raw_date[0x8];
265 temp_y[2] = g_lamexp_version_raw_date[0x9];
266 temp_y[3] = g_lamexp_version_raw_date[0xA];
269 date[0] = atoi(temp_y);
270 date[1] = lamexp_month2int(temp_m);
271 date[2] = atoi(temp_d);
273 if((date[0] > 0) && (date[1] > 0) && (date[2] > 0))
276 g_lamexp_version_date = QDate(date[0], date[1], date[2]);
280 THROW("Internal error: Date format could not be recognized!");
284 return g_lamexp_version_date;
288 * Check for LameXP "portable" mode
290 bool lamexp_portable_mode(void)
292 QReadLocker readLock(&g_lamexp_portable.lock);
294 if(g_lamexp_portable.bInitialized)
296 return g_lamexp_portable.bPortableModeEnabled;
300 QWriteLocker writeLock(&g_lamexp_portable.lock);
302 if(!g_lamexp_portable.bInitialized)
304 if(VER_LAMEXP_PORTABLE_EDITION)
306 qWarning("LameXP portable edition!\n");
307 g_lamexp_portable.bPortableModeEnabled = true;
311 QString baseName = QFileInfo(QApplication::applicationFilePath()).completeBaseName();
312 int idx1 = baseName.indexOf("lamexp", 0, Qt::CaseInsensitive);
313 int idx2 = baseName.lastIndexOf("portable", -1, Qt::CaseInsensitive);
314 g_lamexp_portable.bPortableModeEnabled = ((idx1 >= 0) && (idx2 >= 0) && (idx1 < idx2));
316 g_lamexp_portable.bInitialized = true;
319 return g_lamexp_portable.bPortableModeEnabled;
322 ///////////////////////////////////////////////////////////////////////////////
324 ///////////////////////////////////////////////////////////////////////////////
326 extern "C" void _lamexp_global_init_versn(void)
328 LAMEXP_ZERO_MEMORY(g_lamexp_portable);
331 ///////////////////////////////////////////////////////////////////////////////
333 ///////////////////////////////////////////////////////////////////////////////
335 extern "C" void _lamexp_global_free_versn(void)
337 /*nothing to do here*/