OSDN Git Service

208e9276bafb3ff50d4df2e5b666d0aefa228553
[lamexp/LameXP.git] / src / Global.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 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 WIN32_LEAN_AND_MEAN
33 #include <Windows.h>
34
35 //Declarations
36 class QString;
37 class QStringList;
38 class QDate;
39 class QWidget;
40 class LockedFile;
41 enum QtMsgType;
42
43 //Types definitions
44 typedef struct
45 {
46         int family;
47         int model;
48         int stepping;
49         int count;
50         bool x64;
51         bool mmx;
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 lamexp_cpu_t;
61
62 //Known folders
63 typedef enum
64 {
65         lamexp_folder_localappdata = 0,
66         lamexp_folder_programfiles = 2,
67         lamexp_folder_systemfolder = 3
68 }
69 lamexp_known_folder_t;
70
71 //LameXP version info
72 unsigned int lamexp_version_major(void);
73 unsigned int lamexp_version_minor(void);
74 unsigned int lamexp_version_build(void);
75 const QDate &lamexp_version_date(void);
76 const char *lamexp_version_time(void);
77 const char *lamexp_version_release(void);
78 bool lamexp_version_demo(void);
79 const char *lamexp_version_compiler(void);
80 const char *lamexp_version_arch(void);
81 QDate lamexp_version_expires(void);
82 unsigned int lamexp_toolver_neroaac(void);
83 unsigned int lamexp_toolver_fhgaacenc(void);
84 unsigned int lamexp_toolver_qaacenc(void);
85 unsigned int lamexp_toolver_coreaudio(void);
86 const char *lamexp_website_url(void);
87 const char *lamexp_support_url(void);
88 DWORD lamexp_get_os_version(void);
89
90 //Public functions
91 void lamexp_init_console(int argc, char* argv[]);
92 bool lamexp_init_qt(int argc, char* argv[]);
93 int lamexp_init_ipc(void);
94 LONG WINAPI lamexp_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionInfo);
95 void lamexp_invalid_param_handler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t);
96 void lamexp_message_handler(QtMsgType type, const char *msg);
97 void lamexp_register_tool(const QString &toolName, LockedFile *file, unsigned int version = 0);
98 bool lamexp_check_tool(const QString &toolName);
99 const QString lamexp_lookup_tool(const QString &toolName);
100 unsigned int lamexp_tool_version(const QString &toolName);
101 void lamexp_finalization(void);
102 QString lamexp_rand_str(void);
103 const QString &lamexp_temp_folder2(void);
104 void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize);
105 void lamexp_ipc_send(unsigned int command, const char* message);
106 lamexp_cpu_t lamexp_detect_cpu_features(int argc = 0, char **argv = NULL);
107 bool lamexp_portable_mode(void);
108 bool lamexp_shutdown_computer(const QString &message, const unsigned long timeout = 30, const bool forceShutdown = true, const bool hibernate = false);
109 bool lamexp_is_hibernation_supported(void);
110
111 //Translation support
112 QStringList lamexp_query_translations(void);
113 bool lamexp_translation_register(const QString &langId, const QString &qmFile, const QString &langName, unsigned int &systemId);
114 QString lamexp_translation_name(const QString &language);
115 unsigned int lamexp_translation_sysid(const QString &langId);
116 bool lamexp_install_translator_from_file(const QString &qmFile);
117 bool lamexp_install_translator(const QString &language);
118 static const char* LAMEXP_DEFAULT_LANGID = "en";
119
120 //Auxiliary functions
121 bool lamexp_clean_folder(const QString &folderPath);
122 const QString lamexp_version2string(const QString &pattern, unsigned int version, const QString &defaultText);
123 QString lamexp_known_folder(lamexp_known_folder_t folder_id);
124 unsigned __int64 lamexp_free_diskspace(const QString &path, bool *ok = NULL);
125 bool lamexp_remove_file(const QString &filename);
126 bool lamexp_themes_enabled(void);
127 void lamexp_blink_window(QWidget *poWindow, unsigned int count = 10, unsigned int delay = 150);
128 const QString lamexp_clean_filename(const QString &str);
129 const QString lamexp_clean_filepath(const QString &str);
130
131 //Debug-only functions
132 SIZE_T lamexp_dbg_private_bytes(void);
133
134 //Helper macros
135 #define LAMEXP_DELETE(PTR) if(PTR) { delete PTR; PTR = NULL; }
136 #define LAMEXP_SAFE_FREE(PTR) if(PTR) { free((void*) PTR); PTR = NULL; }
137 #define LAMEXP_CLOSE(HANDLE) if(HANDLE != NULL && HANDLE != INVALID_HANDLE_VALUE) { CloseHandle(HANDLE); HANDLE = NULL; }
138 #define QWCHAR(STR) reinterpret_cast<const wchar_t*>(STR.utf16())
139 #define WCHAR2QSTR(STR) QString::fromUtf16(reinterpret_cast<const unsigned short*>(STR))
140 #define LAMEXP_DYNCAST(OUT,CLASS,SRC) try { OUT = dynamic_cast<CLASS>(SRC); } catch(std::bad_cast) { OUT = NULL; }
141 #define LAMEXP_BOOL(X) (X ? "1" : "0")
142 #define LAMEXP_MAKE_STRING_EX(X) #X
143 #define LAMEXP_MAKE_STRING(X) LAMEXP_MAKE_STRING_EX(X)
144 #define LAMEXP_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" LAMEXP_MAKE_STRING(__LINE__) ") : warning: " TXT))
145 #define NOBR(STR) QString("<nobr>%1</nobr>").arg(STR).replace("-", "&minus;")
146
147 //Output Qt debug message (Unicode-safe versions)
148 //#define qDebug64(FORMAT, ...) qDebug("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData());
149 //#define qWarning64(FORMAT, ...) qWarning("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData());
150 //#define qFatal64(FORMAT, ...) qFatal("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData());
151
152 //Check for debug build
153 #if defined(_DEBUG) && defined(QT_DEBUG) && !defined(NDEBUG) && !defined(QT_NO_DEBUG)
154         #define LAMEXP_DEBUG (1)
155 #elif defined(NDEBUG) && defined(QT_NO_DEBUG) && !defined(_DEBUG) && !defined(QT_DEBUG)
156         #define LAMEXP_DEBUG (0)
157 #else
158         #error Inconsistent debug defines detected!
159 #endif
160
161 //Memory check
162 #if defined(_DEBUG)
163 #define LAMEXP_MEMORY_CHECK(CMD) \
164 { \
165         SIZE_T _privateBytesBefore = lamexp_dbg_private_bytes(); \
166         CMD; \
167         SIZE_T _privateBytesLeak = (lamexp_dbg_private_bytes() - _privateBytesBefore) / 1024; \
168         if(_privateBytesLeak > 10) { \
169                 qWarning("Memory leak: Lost %u KiloBytes.", _privateBytesLeak); \
170         } \
171 }
172 #else
173 #define LAMEXP_MEMORY_CHECK(CMD) CMD
174 #endif
175
176 //Check for CPU-compatibility options
177 #if !defined(_M_X64) && defined(_M_IX86_FP)
178         #if (_M_IX86_FP != 0)
179                 #error We should not enabled SSE or SSE2 in release builds!
180         #endif
181 #endif