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