OSDN Git Service

Fixed IPC initialization + some code refactoring.
[x264-launcher/x264-launcher.git] / src / global.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2014 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 #define _CRT_RAND_S
25 #include <cstdlib>
26
27 //Forward declarations
28 class QString;
29 class QStringList;
30 class QDate;
31 class QTime;
32 class QIcon;
33 class QWidget;
34 class LockedFile;
35 class QProcess;
36 enum QtMsgType;
37
38 ///////////////////////////////////////////////////////////////////////////////
39 // TYPE DEFINITIONS
40 ///////////////////////////////////////////////////////////////////////////////
41
42 //Types definitions
43 typedef struct
44 {
45         int family;
46         int model;
47         int stepping;
48         int count;
49         bool x64;
50         bool mmx;
51         bool mmx2;
52         bool sse;
53         bool sse2;
54         bool sse3;
55         bool ssse3;
56         char vendor[0x40];
57         char brand[0x40];
58         bool intel;
59 }
60 x264_cpu_t;
61
62 //OS version number
63 typedef struct _x264_os_version_t
64 {
65         unsigned int versionMajor;
66         unsigned int versionMinor;
67         bool overrideFlag;
68
69         //comparision operators
70         inline bool operator== (const _x264_os_version_t &rhs) const { return (versionMajor == rhs.versionMajor) && (versionMinor == rhs.versionMinor); }
71         inline bool operator!= (const _x264_os_version_t &rhs) const { return (versionMajor != rhs.versionMajor) || (versionMinor != rhs.versionMinor); }
72         inline bool operator>  (const _x264_os_version_t &rhs) const { return (versionMajor > rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor >  rhs.versionMinor)); }
73         inline bool operator>= (const _x264_os_version_t &rhs) const { return (versionMajor > rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor >= rhs.versionMinor)); }
74         inline bool operator<  (const _x264_os_version_t &rhs) const { return (versionMajor < rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor <  rhs.versionMinor)); }
75         inline bool operator<= (const _x264_os_version_t &rhs) const { return (versionMajor < rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor <= rhs.versionMinor)); }
76 }
77 x264_os_version_t;
78
79 //Beep types
80 typedef enum
81 {
82         x264_beep_info = 0,
83         x264_beep_warning = 1,
84         x264_beep_error = 2
85 }
86 x264_beep_t;
87
88 //Known folders
89 typedef enum
90 {
91         x264_folder_localappdata = 0,
92         x264_folder_programfiles = 2,
93         x264_folder_systemfolder = 3,
94         x264_folder_systroot_dir = 4
95 }
96 x264_known_folder_t;
97
98 //Network connection types
99 typedef enum
100 {
101         x264_network_err = 0,   /*unknown*/
102         x264_network_non = 1,   /*not connected*/
103         x264_network_yes = 2    /*connected*/
104 }
105 x264_network_t;
106
107 //Known Windows versions
108 extern const x264_os_version_t x264_winver_win2k;
109 extern const x264_os_version_t x264_winver_winxp;
110 extern const x264_os_version_t x264_winver_xpx64;
111 extern const x264_os_version_t x264_winver_vista;
112 extern const x264_os_version_t x264_winver_win70;
113 extern const x264_os_version_t x264_winver_win80;
114 extern const x264_os_version_t x264_winver_win81;
115
116 ///////////////////////////////////////////////////////////////////////////////
117 // GLOBAL FUNCTIONS
118 ///////////////////////////////////////////////////////////////////////////////
119
120 const QStringList &x264_arguments(void);
121 bool x264_beep(int beepType);
122 void x264_blink_window(QWidget *poWindow, unsigned int count, unsigned int delay);
123 bool x264_bring_process_to_front(const unsigned long pid);
124 bool x264_bring_to_front(const QWidget *win);
125 bool x264_change_process_priority(const QProcess *proc, const int priority);
126 bool x264_change_process_priority(const int priority);
127 bool x264_change_process_priority(void *hProcess, const int priority);
128 QDate x264_current_date_safe(void);
129 const QString &x264_data_path(void);
130 size_t x264_dbg_private_bytes(void);
131 x264_cpu_t x264_detect_cpu_features(const QStringList &argv);
132 bool x264_enable_close_button(const QWidget *win, const bool bEnable);
133 void x264_fatal_exit(const wchar_t* exitMessage, const wchar_t* errorBoxMessage = NULL);
134 void x264_finalization(void);
135 void x264_init_console(int argc, char* argv[]);
136 void x264_init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir = true);
137 bool x264_init_qt(int argc, char* argv[]);
138 bool x264_is_executable(const QString &path);
139 bool x264_is_prerelease(void);
140 const QString &x264_known_folder(x264_known_folder_t folder_id);
141 void x264_message_handler(QtMsgType type, const char *msg);
142 int x264_network_status(void);
143 QString x264_path2ansi(const QString &longPath, bool makeLowercase = false);
144 bool x264_play_sound(const unsigned short uiSoundIdx, const bool bAsync, const wchar_t *alias = NULL);
145 bool x264_portable(void);
146 unsigned int x264_process_id(void);
147 unsigned int x264_process_id(QProcess &process);
148 QString x264_query_reg_string(const bool bUser, const QString &path, const QString &name);
149 unsigned int x264_rand(void);
150 QString x264_rand_str(const bool bLong = false);
151 void x264_seed_rand(void);
152 bool x264_set_thread_execution_state(const bool systemRequired);
153 bool x264_shutdown_computer(const QString &message, const unsigned long timeout, const bool forceShutdown);
154 void x264_sleep(const unsigned int delay);
155 bool x264_suspendProcess(const QProcess *proc, const bool suspend);
156 const QString &x264_temp_directory(void);
157 bool x264_user_is_admin(void);
158 const char *x264_version_arch(void);
159 unsigned int x264_version_build(void);
160 const char *x264_version_compiler(void);
161 const QDate &x264_version_date(void);
162 unsigned int x264_version_major(void);
163 unsigned int x264_version_minor(void);
164 const char *x264_version_time(void);
165 unsigned int x264_version_x264_minimum_rev(void);
166 unsigned int x264_version_x264_current_api(void);
167 unsigned int x264_version_x264_avs2yuv_ver(void);
168
169 ///////////////////////////////////////////////////////////////////////////////
170 // HELPER MACROS
171 ///////////////////////////////////////////////////////////////////////////////
172
173 #define QWCHAR(STR) reinterpret_cast<const wchar_t*>(STR.utf16())
174 #define QUTF8(STR) ((STR).toUtf8().constData())
175 #define WCHAR2QSTR(STR) (QString::fromUtf16(reinterpret_cast<const unsigned short*>((STR))))
176 #define X264_BOOL(X) ((X) ? "1" : "0")
177 #define X264_DELETE(PTR) if(PTR) { delete PTR; PTR = NULL; }
178 #define X264_DELETE_ARRAY(PTR) if(PTR) { delete [] PTR; PTR = NULL; }
179 #define _X264_MAKE_STRING_(X) #X
180 #define X264_MAKE_STRING(X) _X264_MAKE_STRING_(X)
181 #define X264_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" X264_MAKE_STRING(__LINE__) ") : warning: " TXT))
182 #define X264_STRCMP(X,Y) ((X).compare((Y), Qt::CaseInsensitive) == 0)
183
184 //Debug build
185 #if defined(_DEBUG) && defined(QT_DEBUG) && !defined(NDEBUG) && !defined(QT_NO_DEBUG)
186         #define X264_DEBUG (1)
187 #else
188         #define X264_DEBUG (0)
189 #endif
190
191 //Check for CPU-compatibility options
192 #if !defined(_M_X64) && defined(_MSC_VER) && defined(_M_IX86_FP)
193         #if (_M_IX86_FP != 0)
194                 #error We should not enabled SSE or SSE2 in release builds!
195         #endif
196 #endif
197
198 //Helper macro for throwing exceptions
199 #define THROW(MESSAGE) do \
200 { \
201         throw std::runtime_error((MESSAGE)); \
202 } \
203 while(0)
204 #define THROW_FMT(FORMAT, ...) do \
205 { \
206         char _error_msg[512]; \
207         _snprintf_s(_error_msg, 512, _TRUNCATE, (FORMAT), __VA_ARGS__); \
208         throw std::runtime_error(_error_msg); \
209 } \
210 while(0)
211
212 //Memory check
213 #if X264_DEBUG
214         #define X264_MEMORY_CHECK(FUNC, RETV,  ...) do \
215         { \
216                 size_t _privateBytesBefore = x264_dbg_private_bytes(); \
217                 RETV = FUNC(__VA_ARGS__); \
218                 size_t _privateBytesLeak = (x264_dbg_private_bytes() - _privateBytesBefore) / 1024; \
219                 if(_privateBytesLeak > 0) { \
220                         x264_dbg_dbg_output_string("\nMemory leak: Lost %u KiloBytes of PrivateUsage memory!\n\n", _privateBytesLeak); \
221                 } \
222         } \
223         while(0)
224 #else
225         #define X264_MEMORY_CHECK(FUNC, RETV,  ...) do \
226         { \
227                 RETV = __noop(__VA_ARGS__); \
228         } \
229         while(0)
230 #endif