OSDN Git Service

Fixed a bug that could lead to an infinite loop when trying to install an update...
[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 //MSVC
25 #include "Targetver.h"
26
27 //Stdlib
28 #include <stdio.h>
29 #include <tchar.h>
30
31 //Win32
32 #include <Windows.h>
33
34 //Declarations
35 class QString;
36 class QStringList;
37 class QDate;
38 class LockedFile;
39 enum QtMsgType;
40
41 //Types definitions
42 typedef struct
43 {
44         int family;
45         int model;
46         int stepping;
47         int count;
48         bool x64;
49         bool mmx;
50         bool sse;
51         bool sse2;
52         bool sse3;
53         bool ssse3;
54         char vendor[0x40];
55         char brand[0x40];
56         bool intel;
57 }
58 lamexp_cpu_t;
59
60 //Known folders
61 typedef enum
62 {
63         lamexp_folder_localappdata = 0,
64         lamexp_folder_programfiles = 2,
65         lamexp_folder_systemfolder = 3
66 }
67 lamexp_known_folder_t;
68
69 //LameXP version info
70 unsigned int lamexp_version_major(void);
71 unsigned int lamexp_version_minor(void);
72 unsigned int lamexp_version_build(void);
73 const QDate &lamexp_version_date(void);
74 const char *lamexp_version_release(void);
75 bool lamexp_version_demo(void);
76 const char *lamexp_version_compiler(void);
77 QDate lamexp_version_expires(void);
78 unsigned int lamexp_toolver_neroaac(void);
79
80 //Public functions
81 void lamexp_init_console(int argc, char* argv[]);
82 bool lamexp_init_qt(int argc, char* argv[]);
83 int lamexp_init_ipc(void);
84 void lamexp_message_handler(QtMsgType type, const char *msg);
85 void lamexp_register_tool(const QString &toolName, LockedFile *file, unsigned int version = 0);
86 bool lamexp_check_tool(const QString &toolName);
87 const QString lamexp_lookup_tool(const QString &toolName);
88 unsigned int lamexp_tool_version(const QString &toolName);
89 void lamexp_finalization(void);
90 QString lamexp_rand_str(void);
91 const QString &lamexp_temp_folder(void);
92 void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize);
93 void lamexp_ipc_send(unsigned int command, const char* message);
94 lamexp_cpu_t lamexp_detect_cpu_features(void);
95 bool lamexp_portable_mode(void);
96
97 //Translation support
98 QStringList lamexp_query_translations(void);
99 bool lamexp_translation_register(const QString &langId, const QString &qmFile, const QString &langName, unsigned int &systemId);
100 QString lamexp_translation_name(const QString &language);
101 unsigned int lamexp_translation_sysid(const QString &langId);
102 bool lamexp_install_translator_from_file(const QString &qmFile);
103 bool lamexp_install_translator(const QString &language);
104 static const char* LAMEXP_DEFAULT_LANGID = "en";
105
106 //Auxiliary functions
107 bool lamexp_clean_folder(const QString folderPath);
108 const QString lamexp_version2string(const QString &pattern, unsigned int version, const QString &defaultText);
109 QString lamexp_known_folder(lamexp_known_folder_t folder_id);
110 __int64 lamexp_free_diskspace(const QString &path);
111 bool lamexp_remove_file(const QString &filename);
112 bool lamexp_themes_enabled(void);
113
114 //Debug-only functions
115 SIZE_T lamexp_dbg_private_bytes(void);
116
117 //Helper macros
118 #define LAMEXP_DELETE(PTR) if(PTR) { delete PTR; PTR = NULL; }
119 #define LAMEXP_CLOSE(HANDLE) if(HANDLE != NULL && HANDLE != INVALID_HANDLE_VALUE) { CloseHandle(HANDLE); HANDLE = NULL; }
120 #define QWCHAR(STR) reinterpret_cast<const wchar_t*>(STR.utf16())
121 #define LAMEXP_DYNCAST(OUT,CLASS,SRC) try { OUT = dynamic_cast<CLASS>(SRC); } catch(std::bad_cast) { OUT = NULL; }
122 #define LAMEXP_BOOL(X) (X ? "1" : "0")
123
124 //Check for debug build
125 #if defined(_DEBUG) || defined(QT_DEBUG) || !defined(NDEBUG) || !defined(QT_NO_DEBUG)
126 #define LAMEXP_DEBUG 1
127 #define LAMEXP_CHECK_DEBUG_BUILD \
128         qWarning("---------------------------------------------------------"); \
129         qWarning("DEBUG BUILD: DO NOT RELEASE THIS BINARY TO THE PUBLIC !!!"); \
130         qWarning("---------------------------------------------------------\n"); 
131 #else
132 #define LAMEXP_DEBUG 0
133 #define LAMEXP_CHECK_DEBUG_BUILD
134 #endif
135
136 //Memory check
137 #if defined(_DEBUG)
138 #define LAMEXP_MEMORY_CHECK(CMD) \
139 { \
140         SIZE_T _privateBytesBefore = lamexp_dbg_private_bytes(); \
141         CMD; \
142         SIZE_T _privateBytesLeak = (lamexp_dbg_private_bytes() - _privateBytesBefore) / 1024; \
143         if(_privateBytesLeak > 10) { \
144                 qWarning("Memory leak: Lost %u KiloBytes.", _privateBytesLeak); \
145         } \
146 }
147 #else
148 #define LAMEXP_MEMORY_CHECK(CMD) CMD
149 #endif
150
151 //Check for CPU-compatibility options
152 #if _M_IX86_FP != 0
153 #error We should not enabled SSE or SSE2 in release builds!
154 #endif