OSDN Git Service

Moved translation support into MUtilities library + make clean-up of temporary files...
[mutilities/MUtilities.git] / src / Version.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 //
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
20 //////////////////////////////////////////////////////////////////////////////////
21
22 //MUtils
23 #include <MUtils/Version.h>
24 #include <MUtils/Global.h>
25 #include <MUtils/Exception.h>
26 #include <MUtils/OSSupport.h>
27
28 //Internal
29 #define MUTILS_INC_CONFIG 1
30 #include "Config.h"
31
32 ///////////////////////////////////////////////////////////////////////////////
33 // HELPER FUNCTIONS
34 ///////////////////////////////////////////////////////////////////////////////
35
36 static const char *g_months_lut[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
37
38 static int month_str2int(const char *str)
39 {
40         int ret = 0;
41
42         for(int j = 0; j < 12; j++)
43         {
44                 if(!_strnicmp(str, g_months_lut[j], 3))
45                 {
46                         ret = j+1;
47                         break;
48                 }
49         }
50
51         return ret;
52 }
53
54 static const QDate decode_date_str(const char *const date_str) //Mmm dd yyyy
55 {
56         int date[3] = {0, 0, 0};
57
58         if(sscanf_s(date_str, "%*3s %2d %4d", &date[2], &date[0]) != 2)
59         {
60                 MUTILS_THROW("Internal error: Date format could not be recognized!");
61         }
62
63         if((date[1] = month_str2int(date_str)) < 1)
64         {
65                 MUTILS_THROW("Internal error: Date format could not be recognized!");
66         }
67
68         //qWarning("MUtils::Version::build_date: y=%d, m=%d, d=%d", date[0], date[1], date[2]);
69         return QDate(date[0], date[1], date[2]);
70 }
71
72 static const QTime decode_time_str(const char *const time_str) //hh:mm:ss
73 {
74         int time[3] = {0, 0, 0};
75
76         if(sscanf_s(time_str, "%2d:%2d:%2d", &time[0], &time[1], &time[2]) != 3)
77         {
78                 MUTILS_THROW("Internal error: Time format could not be recognized!");
79         }
80
81         //qWarning("MUtils::Version::build_date: h=%d, m=%d, s=%d", time[0], time[1], time[2]);
82         return QTime(time[0], time[1], time[2]);
83 }
84
85 ///////////////////////////////////////////////////////////////////////////////
86 // LIB VERSION
87 ///////////////////////////////////////////////////////////////////////////////
88
89 const QDate MUtils::Version::lib_build_date(void)
90 {
91         static const char *const BUILD_DATE = __DATE__;
92         return decode_date_str(BUILD_DATE);
93 }
94
95 const QTime MUtils::Version::lib_build_time(void)
96 {
97         static const char *const BUILD_TIME = __TIME__;
98         return decode_time_str(BUILD_TIME);
99 }
100
101 const quint32 &MUtils::Version::lib_version_major(void)
102 {
103         static const quint32 VERSION_MAJOR = VER_MUTILS_MAJOR;
104         return VERSION_MAJOR;
105 }
106
107 const quint32 &MUtils::Version::lib_version_minor(void)
108 {
109         static const quint32 VERSION_MINOR = (10 * VER_MUTILS_MINOR_HI) + VER_MUTILS_MINOR_LO;
110         return VERSION_MINOR;
111 }
112
113
114 ///////////////////////////////////////////////////////////////////////////////
115 // APP VERSION
116 ///////////////////////////////////////////////////////////////////////////////
117
118 const QDate MUtils::Version::app_build_date(const char *const date_str)
119 {
120         return decode_date_str(date_str);
121 }
122
123 const QTime MUtils::Version::app_build_time(const char *const time_str)
124 {
125         return decode_time_str(time_str);
126 }
127
128 ///////////////////////////////////////////////////////////////////////////////