OSDN Git Service

Now each tool can also have a "tag" in addition to the version number.
[lamexp/LameXP.git] / src / Global.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2013 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.
9 //
10 // This program 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
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #pragma once
23
24 //Target version
25 #include "Targetver.h"
26
27 //inlcude C standard library
28 #define _CRT_RAND_S
29 #include <stdio.h>
30 #include <tchar.h>
31
32 //Windows includes
33 #define NOMINMAX
34 #define WIN32_LEAN_AND_MEAN
35 #include <Windows.h>
36
37 //Visual Leaks Detector
38 #include <vld.h>
39
40 //Declarations
41 class QString;
42 class QStringList;
43 class QDate;
44 class QTime;
45 class QIcon;
46 class QWidget;
47 class LockedFile;
48 enum QtMsgType;
49
50 //Types definitions
51 typedef struct
52 {
53         int family;
54         int model;
55         int stepping;
56         int count;
57         bool x64;
58         bool mmx;
59         bool sse;
60         bool sse2;
61         bool sse3;
62         bool ssse3;
63         char vendor[0x40];
64         char brand[0x40];
65         bool intel;
66 }
67 lamexp_cpu_t;
68
69 //Known folders
70 typedef enum
71 {
72         lamexp_folder_localappdata = 0,
73         lamexp_folder_programfiles = 2,
74         lamexp_folder_systemfolder = 3
75 }
76 lamexp_known_folder_t;
77
78 //LameXP user-defined events
79 typedef enum
80 {
81         lamexp_event = 1000,           /*QEvent::User*/
82         lamexp_event_queryendsession = lamexp_event + 666,
83         lamexp_event_endsession      = lamexp_event + 667
84 }
85 lamexp_event_t;
86
87 //OS version number
88 typedef struct
89 {
90         unsigned int versionMajor;
91         unsigned int versionMinor;
92 }
93 lamexp_os_version_t;
94
95 //LameXP version info
96 unsigned int lamexp_version_major(void);
97 unsigned int lamexp_version_minor(void);
98 unsigned int lamexp_version_build(void);
99 const QDate &lamexp_version_date(void);
100 const char *lamexp_version_time(void);
101 const char *lamexp_version_release(void);
102 bool lamexp_version_demo(void);
103 const char *lamexp_version_compiler(void);
104 const char *lamexp_version_arch(void);
105 QDate lamexp_version_expires(void);
106 unsigned int lamexp_toolver_neroaac(void);
107 unsigned int lamexp_toolver_fhgaacenc(void);
108 unsigned int lamexp_toolver_qaacenc(void);
109 unsigned int lamexp_toolver_coreaudio(void);
110 const char *lamexp_website_url(void);
111 const char *lamexp_support_url(void);
112 const lamexp_os_version_t *lamexp_get_os_version(void);
113 bool lamexp_detect_wine(void);
114
115 //Public functions
116 void lamexp_init_console(const QStringList &argv);
117 bool lamexp_init_qt(int argc, char* argv[]);
118 int lamexp_init_ipc(void);
119 LONG WINAPI lamexp_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionInfo);
120 void lamexp_invalid_param_handler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t);
121 void lamexp_message_handler(QtMsgType type, const char *msg);
122 void lamexp_register_tool(const QString &toolName, LockedFile *file, unsigned int version = 0, const QString *tag = NULL);
123 bool lamexp_check_tool(const QString &toolName);
124 const QString lamexp_lookup_tool(const QString &toolName);
125 unsigned int lamexp_tool_version(const QString &toolName, QString *tag = NULL);
126 void lamexp_finalization(void);
127 QString lamexp_rand_str(void);
128 const QString &lamexp_temp_folder2(void);
129 void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize);
130 void lamexp_ipc_send(unsigned int command, const char* message);
131 lamexp_cpu_t lamexp_detect_cpu_features(const QStringList &argv);
132 bool lamexp_portable_mode(void);
133 bool lamexp_shutdown_computer(const QString &message, const unsigned long timeout = 30, const bool forceShutdown = true, const bool hibernate = false);
134 bool lamexp_is_hibernation_supported(void);
135 QIcon lamexp_app_icon(const QDate *date = NULL, const QTime *time = NULL);
136 const QStringList &lamexp_arguments(void);
137
138 //Translation support
139 QStringList lamexp_query_translations(void);
140 bool lamexp_translation_register(const QString &langId, const QString &qmFile, const QString &langName, unsigned int &systemId, unsigned int &country);
141 QString lamexp_translation_name(const QString &language);
142 unsigned int lamexp_translation_sysid(const QString &langId);
143 unsigned int lamexp_translation_country(const QString &langId);
144 bool lamexp_install_translator_from_file(const QString &qmFile);
145 bool lamexp_install_translator(const QString &language);
146 QStringList lamexp_available_codepages(bool noAliases = true);
147 extern const char* LAMEXP_DEFAULT_LANGID;
148 extern const char* LAMEXP_DEFAULT_TRANSLATION;
149
150 //Auxiliary functions
151 bool lamexp_clean_folder(const QString &folderPath);
152 const QString lamexp_version2string(const QString &pattern, unsigned int version, const QString &defaultText, const QString *tag = NULL);
153 const QString &lamexp_known_folder(lamexp_known_folder_t folder_id);
154 unsigned __int64 lamexp_free_diskspace(const QString &path, bool *ok = NULL);
155 bool lamexp_remove_file(const QString &filename);
156 bool lamexp_themes_enabled(void);
157 void lamexp_blink_window(QWidget *poWindow, unsigned int count = 10, unsigned int delay = 150);
158 const QString lamexp_clean_filename(const QString &str);
159 const QString lamexp_clean_filepath(const QString &str);
160 void lamexp_seed_rand(void);
161 unsigned int lamexp_rand(void);
162 QDate lamexp_current_date_safe(void);
163 void lamexp_fatal_exit(const wchar_t* exitMessage, const wchar_t* errorBoxMessage = NULL);
164
165 //Debug-only functions
166 SIZE_T lamexp_dbg_private_bytes(void);
167
168 //Helper macros
169 #define LAMEXP_DELETE(PTR) do { if(PTR) { delete PTR; PTR = NULL; } } while(0)
170 #define LAMEXP_DELETE_ARRAY(PTR) do { if(PTR) { delete [] PTR; PTR = NULL; } } while(0)
171 #define LAMEXP_SAFE_FREE(PTR) do { if(PTR) { free((void*) PTR); PTR = NULL; } } while(0)
172 #define LAMEXP_CLOSE(HANDLE) do { if(HANDLE != NULL && HANDLE != INVALID_HANDLE_VALUE) { CloseHandle(HANDLE); HANDLE = NULL; } } while(0)
173 #define LAMEXP_MIN_OS_VER(VER_INFO, VER_MAJ, VER_MIN) (((VER_INFO)->versionMajor > (VER_MAJ)) || (((VER_INFO)->versionMajor == (VER_MAJ)) && ((VER_INFO)->versionMinor >= (VER_MIN))))
174 #define LAMEXP_MAX_OS_VER(VER_INFO, VER_MAJ, VER_MIN) (((VER_INFO)->versionMajor < (VER_MAJ)) || (((VER_INFO)->versionMajor == (VER_MAJ)) && ((VER_INFO)->versionMinor <= (VER_MIN))))
175 #define LAMEXP_EQL_OS_VER(VER_INFO, VER_MAJ, VER_MIN) (((VER_INFO)->versionMajor == (VER_MAJ)) && ((VER_INFO)->versionMinor == (VER_MIN)))
176 #define QWCHAR(STR) reinterpret_cast<const wchar_t*>((STR).utf16())
177 #define WCHAR2QSTR(STR) QString::fromUtf16(reinterpret_cast<const unsigned short*>(STR))
178 #define LAMEXP_BOOL2STR(X) (X ? "1" : "0")
179 #define LAMEXP_MAKE_STRING_EX(X) #X
180 #define LAMEXP_MAKE_STRING(X) LAMEXP_MAKE_STRING_EX(X)
181 #define LAMEXP_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" LAMEXP_MAKE_STRING(__LINE__) ") : warning: " TXT))
182 #define NOBR(STR) (QString("<nobr>%1</nobr>").arg((STR)).replace("-", "&minus;"))
183
184 //Output Qt debug message (Unicode-safe versions)
185 /*
186 #define qDebug64(FORMAT, ...) qDebug("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData());
187 #define qWarning64(FORMAT, ...) qWarning("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData());
188 #define qFatal64(FORMAT, ...) qFatal("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData());
189 */
190
191 //Check for debug build
192 #if defined(_DEBUG) && defined(QT_DEBUG) && !defined(NDEBUG) && !defined(QT_NO_DEBUG)
193         #define LAMEXP_DEBUG (1)
194 #elif defined(NDEBUG) && defined(QT_NO_DEBUG) && !defined(_DEBUG) && !defined(QT_DEBUG)
195         #define LAMEXP_DEBUG (0)
196 #else
197         #error Inconsistent debug defines detected!
198 #endif
199
200 //Memory check
201 #if LAMEXP_DEBUG
202 #define LAMEXP_MEMORY_CHECK(FUNC, RETV,  ...) do \
203 { \
204         SIZE_T _privateBytesBefore = lamexp_dbg_private_bytes(); \
205         RETV = FUNC(__VA_ARGS__); \
206         SIZE_T _privateBytesLeak = (lamexp_dbg_private_bytes() - _privateBytesBefore) / 1024; \
207         if(_privateBytesLeak > 0) { \
208                 char _buffer[128]; \
209                 _snprintf_s(_buffer, 128, _TRUNCATE, "Memory leak: Lost %u KiloBytes of PrivateUsage memory.\n", _privateBytesLeak); \
210                 OutputDebugStringA("----------\n"); \
211                 OutputDebugStringA(_buffer); \
212                 OutputDebugStringA("----------\n"); \
213         } \
214 } \
215 while(0)
216 #else
217 #define LAMEXP_MEMORY_CHECK(FUNC, RETV,  ...) do \
218 { \
219         RETV = __noop(__VA_ARGS__); \
220 } \
221 while(0)
222 #endif
223
224 //Check for CPU-compatibility options
225 #if !defined(_M_X64) && defined(_MSC_VER) && defined(_M_IX86_FP)
226         #if (_M_IX86_FP != 0)
227                 #error We should not enabled SSE or SSE2 in release builds!
228         #endif
229 #endif