OSDN Git Service

Switched the method for including the UIC header files to "Using a Pointer Member...
[x264-launcher/x264-launcher.git] / src / main.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2013 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 #include "global.h"
23 #include "win_main.h"
24 #include "taskbar7.h"
25
26 //Qt includes
27 #include <QApplication>
28 #include <QDate>
29 #include <QPlastiqueStyle>
30
31 //Windows includes
32 #define NOMINMAX
33 #define WIN32_LEAN_AND_MEAN
34 #include <Windows.h>
35
36 ///////////////////////////////////////////////////////////////////////////////
37 // Main function
38 ///////////////////////////////////////////////////////////////////////////////
39
40 static int x264_main(int argc, char* argv[])
41 {
42         //Init console
43         x264_init_console(argc, argv);
44
45         //Print version info
46         qDebug("Simple x264 Launcher v%u.%02u.%u - use 64-Bit x264 with 32-Bit Avisynth", x264_version_major(), x264_version_minor(), x264_version_build());
47         qDebug("Copyright (c) 2004-%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.", qMax(x264_version_date().year(),QDate::currentDate().year()));
48         qDebug("Built on %s at %s with %s for Win-%s.\n", x264_version_date().toString(Qt::ISODate).toLatin1().constData(), x264_version_time(), x264_version_compiler(), x264_version_arch());
49         
50         //print license info
51         qDebug("This program is free software: you can redistribute it and/or modify");
52         qDebug("it under the terms of the GNU General Public License <http://www.gnu.org/>.");
53         qDebug("Note that this program is distributed with ABSOLUTELY NO WARRANTY.\n");
54
55         //Print warning, if this is a "debug" build
56         if(X264_DEBUG)
57         {
58                 qWarning("---------------------------------------------------------");
59                 qWarning("DEBUG BUILD: DO NOT RELEASE THIS BINARY TO THE PUBLIC !!!");
60                 qWarning("---------------------------------------------------------\n"); 
61         }
62
63         //Get CLI arguments
64         const QStringList &arguments = x264_arguments();
65
66         //Detect CPU capabilities
67         const x264_cpu_t cpuFeatures = x264_detect_cpu_features(arguments);
68         qDebug("   CPU vendor id  :  %s (Intel: %s)", cpuFeatures.vendor, X264_BOOL(cpuFeatures.intel));
69         qDebug("CPU brand string  :  %s", cpuFeatures.brand);
70         qDebug("   CPU signature  :  Family: %d, Model: %d, Stepping: %d", cpuFeatures.family, cpuFeatures.model, cpuFeatures.stepping);
71         qDebug("CPU capabilities  :  MMX=%s, MMXEXT=%s, SSE=%s, SSE2=%s, SSE3=%s, SSSE3=%s, X64=%s", X264_BOOL(cpuFeatures.mmx), X264_BOOL(cpuFeatures.mmx2), X264_BOOL(cpuFeatures.sse), X264_BOOL(cpuFeatures.sse2), X264_BOOL(cpuFeatures.sse3), X264_BOOL(cpuFeatures.ssse3), X264_BOOL(cpuFeatures.x64));
72         qDebug(" Number of CPU's  :  %d\n", cpuFeatures.count);
73
74         //Initialize Qt
75         if(!x264_init_qt(argc, argv))
76         {
77                 return -1;
78         }
79         
80         //Running in portable mode?
81         if(x264_portable())
82         {
83                 qDebug("Application is running in portable mode!\n");
84         }
85
86         //Taskbar init
87         WinSevenTaskbar::init();
88
89         //Set style
90         if(!qApp->arguments().contains("--no-style", Qt::CaseInsensitive))
91         {
92                 qApp->setStyle(new QPlastiqueStyle());
93         }
94
95         //Create Main Window
96         MainWindow *mainWin = new MainWindow(&cpuFeatures);
97         mainWin->show();
98
99         //Run application
100         int ret = qApp->exec();
101
102         //Taskbar uninit
103         WinSevenTaskbar::init();
104         
105         X264_DELETE(mainWin);
106         return ret;
107 }
108
109 ///////////////////////////////////////////////////////////////////////////////
110 // Applicaton entry point
111 ///////////////////////////////////////////////////////////////////////////////
112
113 LONG WINAPI x264_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionInfo);
114 void x264_invalid_param_handler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t);
115
116 static int _main(int argc, char* argv[])
117 {
118         if(X264_DEBUG)
119         {
120                 int iResult = -1;
121                 qInstallMsgHandler(x264_message_handler);
122                 X264_MEMORY_CHECK(x264_main, iResult, argc, argv);
123                 x264_finalization();
124                 return iResult;
125         }
126         else
127         {
128                 int iResult = -1;
129                 try
130                 {
131                         qInstallMsgHandler(x264_message_handler);
132                         iResult = x264_main(argc, argv);
133                         x264_finalization();
134                 }
135                 catch(char *error)
136                 {
137                         fflush(stdout);
138                         fflush(stderr);
139                         fprintf(stderr, "\nGURU MEDITATION !!!\n\nException error message: %s\n", error);
140                         x264_fatal_exit(L"Unhandeled C++ exception error, application will exit!");
141                 }
142                 catch(int error)
143                 {
144                         fflush(stdout);
145                         fflush(stderr);
146                         fprintf(stderr, "\nGURU MEDITATION !!!\n\nException error code: 0x%X\n", error);
147                         x264_fatal_exit(L"Unhandeled C++ exception error, application will exit!");
148                 }
149                 catch(...)
150                 {
151                         fflush(stdout);
152                         fflush(stderr);
153                         fprintf(stderr, "\nGURU MEDITATION !!!\n");
154                         x264_fatal_exit(L"Unhandeled C++ exception error, application will exit!");
155                 }
156                 return iResult;
157         }
158 }
159
160 int main(int argc, char* argv[])
161 {
162         if(X264_DEBUG)
163         {
164                 return _main(argc, argv);
165         }
166         else
167         {
168                 __try
169                 {
170                         SetUnhandledExceptionFilter(x264_exception_handler);
171                         _set_invalid_parameter_handler(x264_invalid_param_handler);
172                         return _main(argc, argv);
173                 }
174                 __except(1)
175                 {
176                         fflush(stdout);
177                         fflush(stderr);
178                         fprintf(stderr, "\nGURU MEDITATION !!!\n\nUnhandeled structured exception error! [code: 0x%X]\n", GetExceptionCode());
179                         x264_fatal_exit(L"Unhandeled structured exception error, application will exit!");
180                 }
181         }
182 }