1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
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.
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.
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.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
28 #include <QApplication>
30 #include <QPlastiqueStyle>
34 #define WIN32_LEAN_AND_MEAN
38 void handleMultipleInstances(QStringList args, IPC *ipc);
40 ///////////////////////////////////////////////////////////////////////////////
42 ///////////////////////////////////////////////////////////////////////////////
44 static int x264_main(int argc, char* argv[])
47 x264_init_console(argc, argv);
50 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());
51 qDebug("Copyright (c) 2004-%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.", qMax(x264_version_date().year(),QDate::currentDate().year()));
52 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());
55 qDebug("This program is free software: you can redistribute it and/or modify");
56 qDebug("it under the terms of the GNU General Public License <http://www.gnu.org/>.");
57 qDebug("Note that this program is distributed with ABSOLUTELY NO WARRANTY.\n");
59 //Print warning, if this is a "debug" build
62 qWarning("---------------------------------------------------------");
63 qWarning("DEBUG BUILD: DO NOT RELEASE THIS BINARY TO THE PUBLIC !!!");
64 qWarning("---------------------------------------------------------\n");
68 const QStringList &arguments = x264_arguments();
70 //Detect CPU capabilities
71 const x264_cpu_t cpuFeatures = x264_detect_cpu_features(arguments);
72 qDebug(" CPU vendor id : %s (Intel: %s)", cpuFeatures.vendor, X264_BOOL(cpuFeatures.intel));
73 qDebug("CPU brand string : %s", cpuFeatures.brand);
74 qDebug(" CPU signature : Family: %d, Model: %d, Stepping: %d", cpuFeatures.family, cpuFeatures.model, cpuFeatures.stepping);
75 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));
76 qDebug(" Number of CPU's : %d\n", cpuFeatures.count);
78 //Initialize the IPC handler class
79 bool firstInstance = false;
81 if(!ipc->initialize(firstInstance))
85 handleMultipleInstances(arguments, ipc);
92 qWarning("IPC initialization has failed!");
96 if(!x264_init_qt(argc, argv))
101 //Running in portable mode?
104 qDebug("Application is running in portable mode!\n");
108 WinSevenTaskbar::init();
111 if(!qApp->arguments().contains("--no-style", Qt::CaseInsensitive))
113 qApp->setStyle(new QPlastiqueStyle());
117 MainWindow *mainWin = new MainWindow(&cpuFeatures);
121 int ret = qApp->exec();
124 WinSevenTaskbar::init();
126 X264_DELETE(mainWin);
130 ///////////////////////////////////////////////////////////////////////////////
131 // Multi-instance handler
132 ///////////////////////////////////////////////////////////////////////////////
134 void handleMultipleInstances(QStringList args, IPC *ipc)
136 bool commandSent = false;
138 //Process all command-line arguments
139 while(!args.isEmpty())
141 const QString current = args.takeFirst();
142 if((current.compare("--add", Qt::CaseInsensitive) == 0) || (current.compare("--add-file", Qt::CaseInsensitive) == 0))
147 if(!ipc->sendAsync(IPC::IPC_OPCODE_ADD_FILE, QStringList() << args.takeFirst()))
154 qWarning("Argument for '--add-file' is missing!");
157 else if(current.compare("--add-job", Qt::CaseInsensitive) == 0)
162 if(!ipc->sendAsync(IPC::IPC_OPCODE_ADD_JOB, QStringList() << args.takeFirst() << args.takeFirst() << args.takeFirst()))
169 qWarning("Argument(s) for '--add-job' are missing!");
175 //If no argument has been sent yet, send a ping!
178 ipc->sendAsync(IPC::IPC_OPCODE_PING, QStringList());
182 ///////////////////////////////////////////////////////////////////////////////
183 // Applicaton entry point
184 ///////////////////////////////////////////////////////////////////////////////
186 LONG WINAPI x264_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionInfo);
187 void x264_invalid_param_handler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t);
189 static int _main(int argc, char* argv[])
194 qInstallMsgHandler(x264_message_handler);
195 X264_MEMORY_CHECK(x264_main, iResult, argc, argv);
204 qInstallMsgHandler(x264_message_handler);
205 iResult = x264_main(argc, argv);
212 fprintf(stderr, "\nGURU MEDITATION !!!\n\nException error message: %s\n", error);
213 x264_fatal_exit(L"Unhandeled C++ exception error, application will exit!");
219 fprintf(stderr, "\nGURU MEDITATION !!!\n\nException error code: 0x%X\n", error);
220 x264_fatal_exit(L"Unhandeled C++ exception error, application will exit!");
226 fprintf(stderr, "\nGURU MEDITATION !!!\n");
227 x264_fatal_exit(L"Unhandeled C++ exception error, application will exit!");
233 int main(int argc, char* argv[])
237 return _main(argc, argv);
243 SetUnhandledExceptionFilter(x264_exception_handler);
244 _set_invalid_parameter_handler(x264_invalid_param_handler);
245 return _main(argc, argv);
251 fprintf(stderr, "\nGURU MEDITATION !!!\n\nUnhandeled structured exception error! [code: 0x%X]\n", GetExceptionCode());
252 x264_fatal_exit(L"Unhandeled structured exception error, application will exit!");