OSDN Git Service

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