1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2013 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 ///////////////////////////////////////////////////////////////////////////////
24 #include "Dialog_SplashScreen.h"
25 #include "Dialog_MainWindow.h"
26 #include "Dialog_Processing.h"
27 #include "Thread_Initialization.h"
28 #include "Thread_MessageProducer.h"
29 #include "Model_Settings.h"
30 #include "Model_FileList.h"
31 #include "Model_AudioFile.h"
32 #include "Encoder_Abstract.h"
33 #include "WinSevenTaskbar.h"
36 #include <QApplication>
37 #include <QMessageBox>
44 #define WIN32_LEAN_AND_MEAN
48 LONG WINAPI
lamexp_exception_handler(__in
struct _EXCEPTION_POINTERS
*ExceptionInfo
);
50 ///////////////////////////////////////////////////////////////////////////////
52 ///////////////////////////////////////////////////////////////////////////////
54 static int lamexp_main(int argc
, char* argv
[])
57 int iShutdown
= shutdownFlag_None
;
58 bool bAccepted
= true;
60 //Increase "main" thread priority
61 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST
);
64 const QStringList
&arguments
= lamexp_arguments();
67 lamexp_init_console(arguments
);
70 qDebug("LameXP - Audio Encoder Front-End v%d.%02d %s (Build #%03d)", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build());
71 qDebug("Copyright (c) 2004-%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.", qMax(lamexp_version_date().year(), lamexp_current_date_safe().year()));
72 qDebug("Built on %s at %s with %s for Win-%s.\n", lamexp_version_date().toString(Qt::ISODate
).toLatin1().constData(), lamexp_version_time(), lamexp_version_compiler(), lamexp_version_arch());
75 qDebug("This program is free software: you can redistribute it and/or modify");
76 qDebug("it under the terms of the GNU General Public License <http://www.gnu.org/>.");
77 qDebug("Note that this program is distributed with ABSOLUTELY NO WARRANTY.\n");
79 //Print warning, if this is a "debug" build
82 qWarning("---------------------------------------------------------");
83 qWarning("DEBUG BUILD: DO NOT RELEASE THIS BINARY TO THE PUBLIC !!!");
84 qWarning("---------------------------------------------------------\n");
87 //Enumerate CLI arguments
88 qDebug("Command-Line Arguments:");
89 for(int i
= 0; i
< arguments
.count(); i
++)
91 qDebug("argv[%d]=%s", i
, arguments
.at(i
).toUtf8().constData());
95 //Detect CPU capabilities
96 lamexp_cpu_t cpuFeatures
= lamexp_detect_cpu_features(arguments
);
97 qDebug(" CPU vendor id : %s (Intel: %s)", cpuFeatures
.vendor
, LAMEXP_BOOL2STR(cpuFeatures
.intel
));
98 qDebug("CPU brand string : %s", cpuFeatures
.brand
);
99 qDebug(" CPU signature : Family: %d, Model: %d, Stepping: %d", cpuFeatures
.family
, cpuFeatures
.model
, cpuFeatures
.stepping
);
100 qDebug("CPU capabilities : MMX: %s, SSE: %s, SSE2: %s, SSE3: %s, SSSE3: %s, x64: %s", LAMEXP_BOOL2STR(cpuFeatures
.mmx
), LAMEXP_BOOL2STR(cpuFeatures
.sse
), LAMEXP_BOOL2STR(cpuFeatures
.sse2
), LAMEXP_BOOL2STR(cpuFeatures
.sse3
), LAMEXP_BOOL2STR(cpuFeatures
.ssse3
), LAMEXP_BOOL2STR(cpuFeatures
.x64
));
101 qDebug(" Number of CPU's : %d\n", cpuFeatures
.count
);
104 if(!lamexp_init_qt(argc
, argv
))
109 //Check for expiration
110 if(lamexp_version_demo())
112 const QDate currentDate
= lamexp_current_date_safe();
113 if(currentDate
.addDays(1) < lamexp_version_date())
115 qFatal("System's date (%s) is before LameXP build date (%s). Huh?", currentDate
.toString(Qt::ISODate
).toLatin1().constData(), lamexp_version_date().toString(Qt::ISODate
).toLatin1().constData());
117 qWarning(QString("Note: This demo (pre-release) version of LameXP will expire at %1.\n").arg(lamexp_version_expires().toString(Qt::ISODate
)).toLatin1().constData());
120 //Check for multiple instances of LameXP
121 if((iResult
= lamexp_init_ipc()) != 0)
123 qDebug("LameXP is already running, connecting to running instance...");
126 MessageProducerThread
*messageProducerThread
= new MessageProducerThread();
127 messageProducerThread
->start();
128 if(!messageProducerThread
->wait(30000))
130 messageProducerThread
->terminate();
131 QMessageBox
messageBox(QMessageBox::Critical
, "LameXP", "LameXP is already running, but the running instance doesn't respond!", QMessageBox::NoButton
, NULL
, Qt::Dialog
| Qt::MSWindowsFixedSizeDialogHint
| Qt::WindowStaysOnTopHint
);
133 messageProducerThread
->wait();
134 LAMEXP_DELETE(messageProducerThread
);
137 LAMEXP_DELETE(messageProducerThread
);
143 for(int i
= 0; i
< argc
; i
++)
145 if(!arguments
[i
].compare("--kill", Qt::CaseInsensitive
) || !arguments
[i
].compare("--force-kill", Qt::CaseInsensitive
))
154 InitializationThread::selfTest();
158 WinSevenTaskbar::init();
161 FileListModel
*fileListModel
= new FileListModel();
162 AudioFileModel
*metaInfo
= new AudioFileModel();
163 SettingsModel
*settingsModel
= new SettingsModel();
166 InitializationThread
*poInitializationThread
= new InitializationThread(&cpuFeatures
);
167 SplashScreen::showSplash(poInitializationThread
);
168 settingsModel
->slowStartup(poInitializationThread
->getSlowIndicator());
169 LAMEXP_DELETE(poInitializationThread
);
172 settingsModel
->validate();
175 MainWindow
*poMainWindow
= new MainWindow(fileListModel
, metaInfo
, settingsModel
);
177 //Main application loop
178 while(bAccepted
&& (iShutdown
<= shutdownFlag_None
))
181 poMainWindow
->show();
182 iResult
= QApplication::instance()->exec();
183 bAccepted
= poMainWindow
->isAccepted();
186 settingsModel
->syncNow();
188 //Show processing dialog
189 if(bAccepted
&& (fileListModel
->rowCount() > 0))
191 ProcessingDialog
*processingDialog
= new ProcessingDialog(fileListModel
, metaInfo
, settingsModel
);
192 processingDialog
->exec();
193 iShutdown
= processingDialog
->getShutdownFlag();
194 LAMEXP_DELETE(processingDialog
);
199 LAMEXP_DELETE(poMainWindow
);
200 LAMEXP_DELETE(fileListModel
);
201 LAMEXP_DELETE(metaInfo
);
202 LAMEXP_DELETE(settingsModel
);
205 WinSevenTaskbar::uninit();
208 qDebug("Shutting down, please wait...\n");
211 if(iShutdown
> shutdownFlag_None
)
213 if(!lamexp_shutdown_computer(QApplication::applicationFilePath(), 12, true, (iShutdown
== shutdownFlag_Hibernate
)))
215 QMessageBox
messageBox(QMessageBox::Critical
, "LameXP", "Sorry, LameXP was unable to shutdown your computer!", QMessageBox::NoButton
, NULL
, Qt::Dialog
| Qt::MSWindowsFixedSizeDialogHint
| Qt::WindowStaysOnTopHint
);
223 ///////////////////////////////////////////////////////////////////////////////
224 // Applicaton entry point
225 ///////////////////////////////////////////////////////////////////////////////
227 static int _main(int argc
, char* argv
[])
232 qInstallMsgHandler(lamexp_message_handler
);
233 iResult
= lamexp_main(argc
, argv
);
234 lamexp_finalization();
242 qInstallMsgHandler(lamexp_message_handler
);
243 iResult
= lamexp_main(argc
, argv
);
244 lamexp_finalization();
250 fprintf(stderr
, "\nGURU MEDITATION !!!\n\nException error message: %s\n", error
);
251 lamexp_fatal_exit(L
"Unhandeled C++ exception error, application will exit!");
257 fprintf(stderr
, "\nGURU MEDITATION !!!\n\nException error code: 0x%X\n", error
);
258 lamexp_fatal_exit(L
"Unhandeled C++ exception error, application will exit!");
264 fprintf(stderr
, "\nGURU MEDITATION !!!\n");
265 lamexp_fatal_exit(L
"Unhandeled C++ exception error, application will exit!");
271 int main(int argc
, char* argv
[])
276 LAMEXP_MEMORY_CHECK(_main
, exit_code
, argc
, argv
);
283 SetUnhandledExceptionFilter(lamexp_exception_handler
);
284 _set_invalid_parameter_handler(lamexp_invalid_param_handler
);
285 return _main(argc
, argv
);
291 fprintf(stderr
, "\nGURU MEDITATION !!!\n\nUnhandeled structured exception error! [code: 0x%X]\n", GetExceptionCode());
292 lamexp_fatal_exit(L
"Unhandeled structured exception error, application will exit!");