OSDN Git Service

Moved CPU capabilities check to the main window init function.
[x264-launcher/x264-launcher.git] / src / main.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2012 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
25 //Qt includes
26 #include <QCoreApplication>
27 #include <QDate>
28 #include <QPlastiqueStyle>
29
30 ///////////////////////////////////////////////////////////////////////////////
31 // Main function
32 ///////////////////////////////////////////////////////////////////////////////
33
34 static int x264_main(int argc, char* argv[])
35 {
36         //Init console
37         x264_init_console(argc, argv);
38
39         //Print version info
40         qDebug("Simple x264 Launcher v%u.%02u - use 64-Bit x264 with 32-Bit Avisynth", x264_version_major(), x264_version_minor());
41         qDebug("Copyright (c) 2004-%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.", qMax(x264_version_date().year(),QDate::currentDate().year()));
42         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());
43         
44         //print license info
45         qDebug("This program is free software: you can redistribute it and/or modify");
46         qDebug("it under the terms of the GNU General Public License <http://www.gnu.org/>.");
47         qDebug("Note that this program is distributed with ABSOLUTELY NO WARRANTY.\n");
48
49         //Print warning, if this is a "debug" build
50         if(X264_DEBUG)
51         {
52                 qWarning("---------------------------------------------------------");
53                 qWarning("DEBUG BUILD: DO NOT RELEASE THIS BINARY TO THE PUBLIC !!!");
54                 qWarning("---------------------------------------------------------\n"); 
55         }
56
57         //Detect CPU capabilities
58         const x264_cpu_t cpuFeatures = x264_detect_cpu_features(argc, argv);
59         qDebug("   CPU vendor id  :  %s (Intel: %s)", cpuFeatures.vendor, X264_BOOL(cpuFeatures.intel));
60         qDebug("CPU brand string  :  %s", cpuFeatures.brand);
61         qDebug("   CPU signature  :  Family: %d, Model: %d, Stepping: %d", cpuFeatures.family, cpuFeatures.model, cpuFeatures.stepping);
62         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));
63         qDebug(" Number of CPU's  :  %d\n", cpuFeatures.count);
64
65         //Initialize Qt
66         if(!x264_init_qt(argc, argv))
67         {
68                 return -1;
69         }
70
71         //Set style
72         qApp->setStyle(new QPlastiqueStyle());
73
74         //Create Main Window
75         MainWindow *mainWin = new MainWindow(&cpuFeatures);
76         mainWin->show();
77
78         //Run application
79         int ret = qApp->exec();
80         
81         X264_DELETE(mainWin);
82         return ret;
83 }
84
85 ///////////////////////////////////////////////////////////////////////////////
86 // Applicaton entry point
87 ///////////////////////////////////////////////////////////////////////////////
88
89 static int _main(int argc, char* argv[])
90 {
91         if(X264_DEBUG)
92         {
93                 int iResult = -1;
94                 qInstallMsgHandler(x264_message_handler);
95                 X264_MEMORY_CHECK(iResult = x264_main(argc, argv));
96                 x264_finalization();
97                 return iResult;
98         }
99         else
100         {
101                 int iResult = -1;
102                 try
103                 {
104                         qInstallMsgHandler(x264_message_handler);
105                         iResult = x264_main(argc, argv);
106                         x264_finalization();
107                 }
108                 catch(char *error)
109                 {
110                         fflush(stdout);
111                         fflush(stderr);
112                         fprintf(stderr, "\nGURU MEDITATION !!!\n\nException error message: %s\n", error);
113                         FatalAppExit(0, L"Unhandeled C++ exception error, application will exit!");
114                         TerminateProcess(GetCurrentProcess(), -1);
115                 }
116                 catch(int error)
117                 {
118                         fflush(stdout);
119                         fflush(stderr);
120                         fprintf(stderr, "\nGURU MEDITATION !!!\n\nException error code: 0x%X\n", error);
121                         FatalAppExit(0, L"Unhandeled C++ exception error, application will exit!");
122                         TerminateProcess(GetCurrentProcess(), -1);
123                 }
124                 catch(...)
125                 {
126                         fflush(stdout);
127                         fflush(stderr);
128                         fprintf(stderr, "\nGURU MEDITATION !!!\n");
129                         FatalAppExit(0, L"Unhandeled C++ exception error, application will exit!");
130                         TerminateProcess(GetCurrentProcess(), -1);
131                 }
132                 return iResult;
133         }
134 }
135
136 int main(int argc, char* argv[])
137 {
138         if(X264_DEBUG)
139         {
140                 return _main(argc, argv);
141         }
142         else
143         {
144                 __try
145                 {
146                         SetUnhandledExceptionFilter(x264_exception_handler);
147                         _set_invalid_parameter_handler(x264_invalid_param_handler);
148                         return _main(argc, argv);
149                 }
150                 __except(1)
151                 {
152                         fflush(stdout);
153                         fflush(stderr);
154                         fprintf(stderr, "\nGURU MEDITATION !!!\n\nUnhandeled structured exception error! [code: 0x%X]\n", GetExceptionCode());
155                         FatalAppExit(0, L"Unhandeled structured exception error, application will exit!");
156                         TerminateProcess(GetCurrentProcess(), -1);
157                 }
158         }
159 }