OSDN Git Service

Moved various functions into MUtils library and removed obsolete code from LameXP.
[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 //MUtils
31 #include <MUtils/Version.h>
32
33 //Qt includes
34 #include <QApplication>
35 #include <QDate>
36 #include <QFileInfo>
37 #include <QReadWriteLock>
38
39 ///////////////////////////////////////////////////////////////////////////////
40 // GLOBAL VARS
41 ///////////////////////////////////////////////////////////////////////////////
42
43 //Build version
44 static const struct
45 {
46         unsigned int ver_major;
47         unsigned int ver_minor;
48         unsigned int ver_build;
49         unsigned int ver_confg;
50         char *ver_release_name;
51 }
52 g_lamexp_version =
53 {
54         VER_LAMEXP_MAJOR,
55         (10 * VER_LAMEXP_MINOR_HI) + VER_LAMEXP_MINOR_LO,
56         VER_LAMEXP_BUILD,
57         VER_LAMEXP_CONFG,
58         VER_LAMEXP_RNAME,
59 };
60
61 //Portable Mode
62 static struct
63 {
64         bool bInitialized;
65         bool bPortableModeEnabled;
66         QReadWriteLock lock;
67 }
68 g_lamexp_portable;
69
70 //Official web-site URL
71 static const char *g_lamexp_website_url = "http://lamexp.sourceforge.net/";
72 static const char *g_lamexp_mulders_url = "http://muldersoft.com/";
73 static const char *g_lamexp_support_url = "http://forum.doom9.org/showthread.php?t=157726";
74 static const char *g_lamexp_tracker_url = "https://github.com/lordmulder/LameXP/issues";
75
76 //Tool versions (expected versions!)
77 static const unsigned int g_lamexp_toolver_neroaac   = VER_LAMEXP_TOOL_NEROAAC;
78 static const unsigned int g_lamexp_toolver_fhgaacenc = VER_LAMEXP_TOOL_FHGAACENC;
79 static const unsigned int g_lamexp_toolver_qaacenc   = VER_LAMEXP_TOOL_QAAC;
80 static const unsigned int g_lamexp_toolver_coreaudio = VER_LAMEXP_TOOL_COREAUDIO;
81
82 ///////////////////////////////////////////////////////////////////////////////
83 // GLOBAL FUNCTIONS
84 ///////////////////////////////////////////////////////////////////////////////
85
86 /*
87  * Version getters
88  */
89 unsigned int lamexp_version_major(void)     { return g_lamexp_version.ver_major; }
90 unsigned int lamexp_version_minor(void)     { return g_lamexp_version.ver_minor; }
91 unsigned int lamexp_version_build(void)     { return g_lamexp_version.ver_build; }
92 unsigned int lamexp_version_confg(void)     { return g_lamexp_version.ver_confg; }
93 const char*  lamexp_version_release(void)   { return g_lamexp_version.ver_release_name; }
94 unsigned int lamexp_toolver_neroaac(void)   { return g_lamexp_toolver_neroaac; }
95 unsigned int lamexp_toolver_fhgaacenc(void) { return g_lamexp_toolver_fhgaacenc; }
96 unsigned int lamexp_toolver_qaacenc(void)   { return g_lamexp_toolver_qaacenc; }
97 unsigned int lamexp_toolver_coreaudio(void) { return g_lamexp_toolver_coreaudio; }
98
99 /*
100  * URL getters
101  */
102 const char *lamexp_website_url(void) { return g_lamexp_website_url; }
103 const char *lamexp_mulders_url(void) { return g_lamexp_mulders_url; }
104 const char *lamexp_support_url(void) { return g_lamexp_support_url; }
105 const char *lamexp_tracker_url(void) { return g_lamexp_tracker_url; }
106
107 /*
108  * Check for Demo (pre-release) version
109  */
110 bool lamexp_version_demo(void)
111 {
112         char buffer[128];
113         bool releaseVersion = false;
114         if(!strncpy_s(buffer, 128, g_lamexp_version.ver_release_name, _TRUNCATE))
115         {
116                 char *context, *prefix = strtok_s(buffer, "-,; ", &context);
117                 if(prefix)
118                 {
119                         releaseVersion = (!_stricmp(prefix, "Final")) || (!_stricmp(prefix, "Hotfix"));
120                 }
121         }
122         return (!releaseVersion);
123 }
124
125 /*
126  * Calculate expiration date
127  */
128 QDate lamexp_version_expires(void)
129 {
130         return MUtils::Version::build_date().addDays(MUTILS_DEBUG ? 7 : 30);
131 }
132
133 /*
134  * Check for LameXP "portable" mode
135  */
136 bool lamexp_portable_mode(void)
137 {
138         QReadLocker readLock(&g_lamexp_portable.lock);
139
140         if(g_lamexp_portable.bInitialized)
141         {
142                 return g_lamexp_portable.bPortableModeEnabled;
143         }
144         
145         readLock.unlock();
146         QWriteLocker writeLock(&g_lamexp_portable.lock);
147
148         if(!g_lamexp_portable.bInitialized)
149         {
150                 if(VER_LAMEXP_PORTABLE_EDITION)
151                 {
152                         qWarning("LameXP portable edition!\n");
153                         g_lamexp_portable.bPortableModeEnabled = true;
154                 }
155                 else
156                 {
157                         QString baseName = QFileInfo(QApplication::applicationFilePath()).completeBaseName();
158                         int idx1 = baseName.indexOf("lamexp", 0, Qt::CaseInsensitive);
159                         int idx2 = baseName.lastIndexOf("portable", -1, Qt::CaseInsensitive);
160                         g_lamexp_portable.bPortableModeEnabled = ((idx1 >= 0) && (idx2 >= 0) && (idx1 < idx2));
161                 }
162                 g_lamexp_portable.bInitialized = true;
163         }
164         
165         return g_lamexp_portable.bPortableModeEnabled;
166 }
167
168 ///////////////////////////////////////////////////////////////////////////////
169 // INITIALIZATION
170 ///////////////////////////////////////////////////////////////////////////////
171
172 extern "C" void _lamexp_global_init_versn(void)
173 {
174         LAMEXP_ZERO_MEMORY(g_lamexp_portable);
175 }
176
177 ///////////////////////////////////////////////////////////////////////////////
178 // FINALIZATION
179 ///////////////////////////////////////////////////////////////////////////////
180
181 extern "C" void _lamexp_global_free_versn(void)
182 {
183         /*nothing to do here*/
184 }