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