OSDN Git Service

Set creation/modified time of the encoded file the same value as the original file...
[lamexp/LameXP.git] / src / Global_Version.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2015 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 1
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 static QReadWriteLock g_lamexp_version_lock;
44
45 //Build version
46 static const unsigned int g_lamexp_version_major = VER_LAMEXP_MAJOR;
47 static const unsigned int g_lamexp_version_minor = (10 * VER_LAMEXP_MINOR_HI) + VER_LAMEXP_MINOR_LO;
48 static const unsigned int g_lamexp_version_build = VER_LAMEXP_BUILD;
49 static const unsigned int g_lamexp_version_confg = VER_LAMEXP_CONFG;
50 static const char*        g_lamexp_version_rname = VER_LAMEXP_RNAME;
51
52 //Demo Version
53 static int g_lamexp_demo = -1;
54
55 //Portable Mode
56 static int g_lamexp_portable = -1;
57
58 //Expiration date
59 static QScopedPointer<QDate> g_lamexp_expiration_date;
60
61 //Official web-site URL
62 static const char *g_lamexp_website_url = "http://lamexp.sourceforge.net/";
63 static const char *g_lamexp_mulders_url = "http://muldersoft.com/";
64 static const char *g_lamexp_support_url = "http://forum.doom9.org/showthread.php?t=157726";
65 static const char *g_lamexp_tracker_url = "https://github.com/lordmulder/LameXP/issues";
66
67 //Tool versions (expected versions!)
68 static const unsigned int g_lamexp_toolver_neroaac   = VER_LAMEXP_TOOL_NEROAAC;
69 static const unsigned int g_lamexp_toolver_fhgaacenc = VER_LAMEXP_TOOL_FHGAACENC;
70 static const unsigned int g_lamexp_toolver_fdkaacenc = VER_LAMEXP_TOOL_FDKAACENC;
71 static const unsigned int g_lamexp_toolver_qaacenc   = VER_LAMEXP_TOOL_QAAC;
72 static const unsigned int g_lamexp_toolver_coreaudio = VER_LAMEXP_TOOL_COREAUDIO;
73
74 ///////////////////////////////////////////////////////////////////////////////
75 // GLOBAL FUNCTIONS
76 ///////////////////////////////////////////////////////////////////////////////
77
78 /*
79  * Version getters
80  */
81 unsigned int lamexp_version_major(void)     { return g_lamexp_version_major;     }
82 unsigned int lamexp_version_minor(void)     { return g_lamexp_version_minor;     }
83 unsigned int lamexp_version_build(void)     { return g_lamexp_version_build;     }
84 unsigned int lamexp_version_confg(void)     { return g_lamexp_version_confg;     }
85 const char*  lamexp_version_release(void)   { return g_lamexp_version_rname;     }
86 unsigned int lamexp_toolver_neroaac(void)   { return g_lamexp_toolver_neroaac;   }
87 unsigned int lamexp_toolver_fhgaacenc(void) { return g_lamexp_toolver_fhgaacenc; }
88 unsigned int lamexp_toolver_fdkaacenc(void) { return g_lamexp_toolver_fdkaacenc; }
89 unsigned int lamexp_toolver_qaacenc(void)   { return g_lamexp_toolver_qaacenc;   }
90 unsigned int lamexp_toolver_coreaudio(void) { return g_lamexp_toolver_coreaudio; }
91
92 /*
93  * URL getters
94  */
95 const char *lamexp_website_url(void) { return g_lamexp_website_url; }
96 const char *lamexp_mulders_url(void) { return g_lamexp_mulders_url; }
97 const char *lamexp_support_url(void) { return g_lamexp_support_url; }
98 const char *lamexp_tracker_url(void) { return g_lamexp_tracker_url; }
99
100 /*
101  * Check for Demo (pre-release) version
102  */
103 bool lamexp_version_demo(void)
104 {
105         QReadLocker readLock(&g_lamexp_version_lock);
106
107         if(g_lamexp_demo >= 0)
108         {
109                 return (g_lamexp_demo > 0);
110         }
111         
112         readLock.unlock();
113         QWriteLocker writeLock(&g_lamexp_version_lock);
114
115         if(g_lamexp_demo < 0)
116         {
117                 g_lamexp_demo = (_strnicmp(g_lamexp_version_rname, "Final", 5) && _strnicmp(g_lamexp_version_rname, "Hotfix", 6)) ? (1) : (0);
118         }
119
120         return (g_lamexp_demo > 0);
121 }
122
123 /*
124  * Calculate expiration date
125  */
126 const QDate &lamexp_version_expires(void)
127 {
128         QReadLocker readLock(&g_lamexp_version_lock);
129
130         if(!g_lamexp_expiration_date.isNull())
131         {
132                 return *g_lamexp_expiration_date;
133         }
134
135         readLock.unlock();
136         QWriteLocker writeLock(&g_lamexp_version_lock);
137
138         if(g_lamexp_expiration_date.isNull())
139         {
140                 g_lamexp_expiration_date.reset(new QDate(MUtils::Version::app_build_date().addDays(MUTILS_DEBUG ? 7 : 30)));
141         }
142
143         return *g_lamexp_expiration_date;
144 }
145
146 /*
147  * Check for LameXP "portable" mode
148  */
149 bool lamexp_version_portable(void)
150 {
151         QReadLocker readLock(&g_lamexp_version_lock);
152
153         if(g_lamexp_portable >= 0)
154         {
155                 return (g_lamexp_portable > 0);
156         }
157         
158         readLock.unlock();
159         QWriteLocker writeLock(&g_lamexp_version_lock);
160
161         if(g_lamexp_portable < 0)
162         {
163                 if(VER_LAMEXP_PORTABLE_EDITION)
164                 {
165                         qWarning("LameXP portable edition!\n");
166                         g_lamexp_portable = 1;
167                 }
168                 else
169                 {
170                         const QString baseName = QFileInfo(QApplication::applicationFilePath()).completeBaseName();
171                         const int idx1 = baseName.indexOf("lamexp", 0, Qt::CaseInsensitive);
172                         const int idx2 = baseName.lastIndexOf("portable", -1, Qt::CaseInsensitive);
173                         g_lamexp_portable = ((idx1 >= 0) && (idx2 >= 0) && (idx1 < idx2)) ? (1) : (0);
174                 }
175         }
176         
177         return (g_lamexp_portable > 0);
178 }