OSDN Git Service

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