OSDN Git Service

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