1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
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.
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.
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.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
28 //Forward declarations
41 extern const char* LAMEXP_DEFAULT_LANGID;
42 extern const char* LAMEXP_DEFAULT_TRANSLATION;
44 ///////////////////////////////////////////////////////////////////////////////
46 ///////////////////////////////////////////////////////////////////////////////
70 lamexp_folder_localappdata = 0,
71 lamexp_folder_programfiles = 2,
72 lamexp_folder_systemfolder = 3
74 lamexp_known_folder_t;
76 //LameXP user-defined events
79 lamexp_event = 1000, /*QEvent::User*/
80 lamexp_event_queryendsession = lamexp_event + 666,
81 lamexp_event_endsession = lamexp_event + 667
86 typedef struct _lamexp_os_version_t
88 unsigned int versionMajor;
89 unsigned int versionMinor;
92 //comparision operators
93 inline bool operator== (const _lamexp_os_version_t &rhs) const { return (versionMajor == rhs.versionMajor) && (versionMinor == rhs.versionMinor); }
94 inline bool operator!= (const _lamexp_os_version_t &rhs) const { return (versionMajor != rhs.versionMajor) || (versionMinor != rhs.versionMinor); }
95 inline bool operator> (const _lamexp_os_version_t &rhs) const { return (versionMajor > rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor > rhs.versionMinor)); }
96 inline bool operator>= (const _lamexp_os_version_t &rhs) const { return (versionMajor > rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor >= rhs.versionMinor)); }
97 inline bool operator< (const _lamexp_os_version_t &rhs) const { return (versionMajor < rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor < rhs.versionMinor)); }
98 inline bool operator<= (const _lamexp_os_version_t &rhs) const { return (versionMajor < rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor <= rhs.versionMinor)); }
102 //Known Windows versions
103 extern const lamexp_os_version_t lamexp_winver_win2k;
104 extern const lamexp_os_version_t lamexp_winver_winxp;
105 extern const lamexp_os_version_t lamexp_winver_xpx64;
106 extern const lamexp_os_version_t lamexp_winver_vista;
107 extern const lamexp_os_version_t lamexp_winver_win70;
108 extern const lamexp_os_version_t lamexp_winver_win80;
109 extern const lamexp_os_version_t lamexp_winver_win81;
114 lamexp_beep_info = 0,
115 lamexp_beep_warning = 1,
116 lamexp_beep_error = 2
120 //Network connection types
123 lamexp_network_err = 0, /*unknown*/
124 lamexp_network_non = 1, /*not connected*/
125 lamexp_network_yes = 2 /*connected*/
132 lamexp_syscolor_text = 0,
133 lamexp_syscolor_background = 1,
134 lamexp_syscolor_caption = 2
138 ///////////////////////////////////////////////////////////////////////////////
140 ///////////////////////////////////////////////////////////////////////////////
142 QIcon lamexp_app_icon(const QDate *date = NULL, const QTime *time = NULL);
143 bool lamexp_append_sysmenu(const QWidget *win, const unsigned int identifier, const QString &text);
144 const QStringList &lamexp_arguments(void);
145 QStringList lamexp_available_codepages(bool noAliases = true);
146 bool lamexp_beep(int beepType);
147 void lamexp_blink_window(QWidget *poWindow, unsigned int count = 10, unsigned int delay = 150);
148 bool lamexp_bring_process_to_front(const unsigned long pid);
149 bool lamexp_bring_to_front(const QWidget *win);
150 bool lamexp_broadcast(int eventType, bool onlyToVisible);
151 bool lamexp_change_process_priority(const int priority);
152 bool lamexp_change_process_priority(void *hProcess, const int priority);
153 bool lamexp_change_process_priority(const QProcess *proc, const int priority);
154 bool lamexp_check_escape_state(void);
155 bool lamexp_check_sysmenu_msg(void *message, const unsigned int identifier);
156 bool lamexp_check_tool(const QString &toolName);
157 const QString lamexp_clean_filename(const QString &str);
158 const QString lamexp_clean_filepath(const QString &str);
159 void lamexp_clean_all_tools(void);
160 void lamexp_clean_all_translations(void);
161 bool lamexp_clean_folder(const QString &folderPath);
162 QDate lamexp_current_date_safe(void);
163 unsigned __int64 lamexp_current_file_time(void);
164 void lamexp_dbg_dbg_output_string(const char* format, ...);
165 unsigned long lamexp_dbg_private_bytes(void);
166 lamexp_cpu_t lamexp_detect_cpu_features(const QStringList &argv);
167 bool lamexp_detect_wine(void);
168 bool lamexp_enable_close_button(const QWidget *win, const bool bEnable = true);
169 bool lamexp_exec_shell(const QWidget *win, const QString &url, const bool explore = false);
170 bool lamexp_exec_shell(const QWidget *win, const QString &url, const QString ¶meters, const QString &directory, const bool explore = false);
171 void lamexp_fatal_exit(const wchar_t* exitMessage, const wchar_t* errorBoxMessage = NULL);
172 void lamexp_finalization(void);
173 unsigned __int64 lamexp_free_diskspace(const QString &path, bool *ok = NULL);
174 const lamexp_os_version_t &lamexp_get_os_version(void);
175 void lamexp_init_console(const QStringList &argv);
176 void lamexp_init_error_handlers(void);
177 int lamexp_init_ipc(void);
178 void lamexp_init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir = true);
179 bool lamexp_init_qt(int argc, char* argv[]);
180 bool lamexp_install_translator(const QString &language);
181 bool lamexp_install_translator_from_file(const QString &qmFile);
182 void lamexp_invalid_param_handler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t);
183 void lamexp_ipc_exit(void);
184 void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize);
185 void lamexp_ipc_send(unsigned int command, const char* message);
186 bool lamexp_is_hibernation_supported(void);
187 const QString &lamexp_known_folder(lamexp_known_folder_t folder_id);
188 const QString lamexp_lookup_tool(const QString &toolName);
189 void lamexp_message_handler(QtMsgType type, const char *msg);
190 const char *lamexp_mulders_url(void);
191 void lamexp_natural_string_sort(QStringList &list, const bool bIgnoreCase);
192 int lamexp_network_status(void);
193 bool lamexp_open_media_file(const QString &mediaFilePath);
194 QString lamexp_path_to_short(const QString &longPath);
195 __int64 lamexp_perfcounter_frequ(void);
196 __int64 lamexp_perfcounter_value(void);
197 bool lamexp_play_sound(const unsigned short uiSoundIdx, const bool bAsync, const wchar_t *alias = NULL);
198 bool lamexp_play_sound_file(const QString &library, const unsigned short uiSoundIdx, const bool bAsync);
199 bool lamexp_portable_mode(void);
200 unsigned long lamexp_process_id(const QProcess *proc);
201 QStringList lamexp_query_translations(void);
202 unsigned int lamexp_rand(void);
203 QString lamexp_rand_str(const bool bLong = false);
204 void lamexp_register_tool(const QString &toolName, LockedFile *file, unsigned int version = 0, const QString *tag = NULL);
205 bool lamexp_remove_file(const QString &filename);
206 void lamexp_seed_rand(void);
207 bool lamexp_sheet_of_glass(QWidget *window);
208 bool lamexp_sheet_of_glass_update(QWidget *window);
209 bool lamexp_shutdown_computer(const QString &message, const unsigned long timeout = 30, const bool forceShutdown = true, const bool hibernate = false);
210 void lamexp_sleep(const unsigned int delay);
211 QColor lamexp_system_color(const int color_id);
212 const char *lamexp_support_url(void);
213 const QString &lamexp_temp_folder2(void);
214 void lamexp_temp_folder_clear(void);
215 bool lamexp_themes_enabled(void);
216 unsigned int lamexp_tool_version(const QString &toolName, QString *tag = NULL);
217 unsigned int lamexp_toolver_coreaudio(void);
218 unsigned int lamexp_toolver_fhgaacenc(void);
219 unsigned int lamexp_toolver_neroaac(void);
220 unsigned int lamexp_toolver_qaacenc(void);
221 unsigned int lamexp_translation_country(const QString &langId);
222 bool lamexp_translation_init(void);
223 QString lamexp_translation_name(const QString &language);
224 bool lamexp_translation_register(const QString &langId, const QString &qmFile, const QString &langName, unsigned int &systemId, unsigned int &country);
225 unsigned int lamexp_translation_sysid(const QString &langId);
226 bool lamexp_update_sysmenu(const QWidget *win, const unsigned int identifier, const QString &text);
227 const QString lamexp_version2string(const QString &pattern, unsigned int version, const QString &defaultText, const QString *tag = NULL);
228 const char *lamexp_version_arch(void);
229 unsigned int lamexp_version_build(void);
230 const char *lamexp_version_compiler(void);
231 unsigned int lamexp_version_confg(void);
232 const QDate &lamexp_version_date(void);
233 bool lamexp_version_demo(void);
234 QDate lamexp_version_expires(void);
235 unsigned int lamexp_version_major(void);
236 unsigned int lamexp_version_minor(void);
237 const char *lamexp_version_release(void);
238 const char *lamexp_version_time(void);
239 const char *lamexp_website_url(void);
241 ///////////////////////////////////////////////////////////////////////////////
243 ///////////////////////////////////////////////////////////////////////////////
245 #define LAMEXP_BOOL2STR(X) ((X) ? "1" : "0")
246 #define LAMEXP_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" LAMEXP_MAKE_STRING(__LINE__) ") : warning: " TXT))
247 #define LAMEXP_CLOSE(HANDLE) do { if(HANDLE != NULL && HANDLE != INVALID_HANDLE_VALUE) { CloseHandle(HANDLE); HANDLE = NULL; } } while(0)
248 #define LAMEXP_DELETE(PTR) do { if(PTR) { delete PTR; PTR = NULL; } } while(0)
249 #define LAMEXP_DELETE_ARRAY(PTR) do { if(PTR) { delete [] PTR; PTR = NULL; } } while(0)
250 #define LAMEXP_MAKE_STRING_EX(X) #X
251 #define LAMEXP_MAKE_STRING(X) LAMEXP_MAKE_STRING_EX(X)
252 #define LAMEXP_SAFE_FREE(PTR) do { if(PTR) { free((void*) PTR); PTR = NULL; } } while(0)
253 #define LAMEXP_ZERO_MEMORY(X) memset(&(X), 0, sizeof((X)))
254 #define NOBR(STR) (QString("<nobr>%1</nobr>").arg((STR)).replace("-", "−"))
255 #define QUTF8(STR) ((STR).toUtf8().constData())
256 #define QWCHAR(STR) (reinterpret_cast<const wchar_t*>((STR).utf16()))
257 #define WCHAR2QSTR(STR) (QString::fromUtf16(reinterpret_cast<const unsigned short*>((STR))))
259 //Check for debug build
260 #if defined(_DEBUG) && defined(QT_DEBUG) && !defined(NDEBUG) && !defined(QT_NO_DEBUG)
261 #define LAMEXP_DEBUG (1)
262 #elif defined(NDEBUG) && defined(QT_NO_DEBUG) && !defined(_DEBUG) && !defined(QT_DEBUG)
263 #define LAMEXP_DEBUG (0)
265 #error Inconsistent debug defines detected!
268 //Check for CPU-compatibility options
269 #if !defined(_M_X64) && defined(_MSC_VER) && defined(_M_IX86_FP)
270 #if (_M_IX86_FP != 0)
271 #error We should not enabled SSE or SSE2 in release builds!
275 //Helper macro for throwing exceptions
276 #define THROW(MESSAGE) do \
278 throw std::runtime_error((MESSAGE)); \
281 #define THROW_FMT(FORMAT, ...) do \
283 char _error_msg[512]; \
284 _snprintf_s(_error_msg, 512, _TRUNCATE, (FORMAT), __VA_ARGS__); \
285 throw std::runtime_error(_error_msg); \
291 #define LAMEXP_MEMORY_CHECK(FUNC, RETV, ...) do \
293 size_t _privateBytesBefore = lamexp_dbg_private_bytes(); \
294 RETV = FUNC(__VA_ARGS__); \
295 size_t _privateBytesLeak = (lamexp_dbg_private_bytes() - _privateBytesBefore) / 1024; \
296 if(_privateBytesLeak > 0) { \
297 lamexp_dbg_dbg_output_string("\nMemory leak: Lost %u KiloBytes of PrivateUsage memory!\n\n", _privateBytesLeak); \
302 #define LAMEXP_MEMORY_CHECK(FUNC, RETV, ...) do \
304 RETV = __noop(__VA_ARGS__); \