1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 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>
42 ///////////////////////////////////////////////////////////////////////////////
44 ///////////////////////////////////////////////////////////////////////////////
46 static int lamexp_main(int argc
, char* argv
[])
49 int iShutdown
= shutdownFlag_None
;
50 bool bAccepted
= true;
53 const QStringList
&arguments
= lamexp_arguments();
56 lamexp_init_console(arguments
);
59 qDebug("LameXP - Audio Encoder Front-End v%d.%02d %s (Build #%03d)", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build());
60 qDebug("Copyright (c) 2004-%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.", qMax(lamexp_version_date().year(),QDate::currentDate().year()));
61 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());
64 qDebug("This program is free software: you can redistribute it and/or modify");
65 qDebug("it under the terms of the GNU General Public License <http://www.gnu.org/>.");
66 qDebug("Note that this program is distributed with ABSOLUTELY NO WARRANTY.\n");
68 //Print warning, if this is a "debug" build
71 qWarning("---------------------------------------------------------");
72 qWarning("DEBUG BUILD: DO NOT RELEASE THIS BINARY TO THE PUBLIC !!!");
73 qWarning("---------------------------------------------------------\n");
76 //Enumerate CLI arguments
77 qDebug("Command-Line Arguments:");
78 for(int i
= 0; i
< arguments
.count(); i
++)
80 qDebug("argv[%d]=%s", i
, arguments
.at(i
).toUtf8().constData());
84 //Detect CPU capabilities
85 lamexp_cpu_t cpuFeatures
= lamexp_detect_cpu_features(arguments
);
86 qDebug(" CPU vendor id : %s (Intel: %s)", cpuFeatures
.vendor
, LAMEXP_BOOL2STR(cpuFeatures
.intel
));
87 qDebug("CPU brand string : %s", cpuFeatures
.brand
);
88 qDebug(" CPU signature : Family: %d, Model: %d, Stepping: %d", cpuFeatures
.family
, cpuFeatures
.model
, cpuFeatures
.stepping
);
89 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
));
90 qDebug(" Number of CPU's : %d\n", cpuFeatures
.count
);
93 if(!lamexp_init_qt(argc
, argv
))
98 //Check for expiration
99 if(lamexp_version_demo())
101 if(QDate::currentDate().addDays(1) < lamexp_version_date())
103 qFatal("System's date (%s) is before LameXP build date (%s). Huh?", QDate::currentDate().toString(Qt::ISODate
).toLatin1().constData(), lamexp_version_date().toString(Qt::ISODate
).toLatin1().constData());
105 qWarning(QString("Note: This demo (pre-release) version of LameXP will expire at %1.\n").arg(lamexp_version_expires().toString(Qt::ISODate
)).toLatin1().constData());
108 //Check for multiple instances of LameXP
109 if((iResult
= lamexp_init_ipc()) != 0)
111 qDebug("LameXP is already running, connecting to running instance...");
114 MessageProducerThread
*messageProducerThread
= new MessageProducerThread();
115 messageProducerThread
->start();
116 if(!messageProducerThread
->wait(30000))
118 messageProducerThread
->terminate();
119 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
);
121 messageProducerThread
->wait();
122 LAMEXP_DELETE(messageProducerThread
);
125 LAMEXP_DELETE(messageProducerThread
);
131 for(int i
= 0; i
< argc
; i
++)
133 if(!arguments
[i
].compare("--kill", Qt::CaseInsensitive
) || !arguments
[i
].compare("--force-kill", Qt::CaseInsensitive
))
142 InitializationThread::selfTest();
146 WinSevenTaskbar::init();
149 FileListModel
*fileListModel
= new FileListModel();
150 AudioFileModel
*metaInfo
= new AudioFileModel();
151 SettingsModel
*settingsModel
= new SettingsModel();
154 InitializationThread
*poInitializationThread
= new InitializationThread(&cpuFeatures
);
155 SplashScreen::showSplash(poInitializationThread
);
156 settingsModel
->slowStartup(poInitializationThread
->getSlowIndicator());
157 LAMEXP_DELETE(poInitializationThread
);
160 settingsModel
->validate();
163 MainWindow
*poMainWindow
= new MainWindow(fileListModel
, metaInfo
, settingsModel
);
165 //Main application loop
166 while(bAccepted
&& (iShutdown
<= shutdownFlag_None
))
169 poMainWindow
->show();
170 iResult
= QApplication::instance()->exec();
171 bAccepted
= poMainWindow
->isAccepted();
173 //Show processing dialog
174 if(bAccepted
&& (fileListModel
->rowCount() > 0))
176 ProcessingDialog
*processingDialog
= new ProcessingDialog(fileListModel
, metaInfo
, settingsModel
);
177 processingDialog
->exec();
178 iShutdown
= processingDialog
->getShutdownFlag();
179 LAMEXP_DELETE(processingDialog
);
184 LAMEXP_DELETE(poMainWindow
);
185 LAMEXP_DELETE(fileListModel
);
186 LAMEXP_DELETE(metaInfo
);
187 LAMEXP_DELETE(settingsModel
);
190 WinSevenTaskbar::uninit();
193 qDebug("Shutting down, please wait...\n");
196 if(iShutdown
> shutdownFlag_None
)
198 if(!lamexp_shutdown_computer(QApplication::applicationFilePath(), 12, true, (iShutdown
== shutdownFlag_Hibernate
)))
200 QMessageBox
messageBox(QMessageBox::Critical
, "LameXP", "Sorry, LameXP was unable to shutdown your computer!", QMessageBox::NoButton
, NULL
, Qt::Dialog
| Qt::MSWindowsFixedSizeDialogHint
| Qt::WindowStaysOnTopHint
);
208 ///////////////////////////////////////////////////////////////////////////////
209 // Applicaton entry point
210 ///////////////////////////////////////////////////////////////////////////////
212 static int _main(int argc
, char* argv
[])
217 qInstallMsgHandler(lamexp_message_handler
);
218 iResult
= lamexp_main(argc
, argv
);
219 lamexp_finalization();
227 qInstallMsgHandler(lamexp_message_handler
);
228 iResult
= lamexp_main(argc
, argv
);
229 lamexp_finalization();
235 fprintf(stderr
, "\nGURU MEDITATION !!!\n\nException error message: %s\n", error
);
236 lamexp_fatal_exit(L
"Unhandeled C++ exception error, application will exit!");
242 fprintf(stderr
, "\nGURU MEDITATION !!!\n\nException error code: 0x%X\n", error
);
243 lamexp_fatal_exit(L
"Unhandeled C++ exception error, application will exit!");
249 fprintf(stderr
, "\nGURU MEDITATION !!!\n");
250 lamexp_fatal_exit(L
"Unhandeled C++ exception error, application will exit!");
256 int main(int argc
, char* argv
[])
261 LAMEXP_MEMORY_CHECK(_main
, exit_code
, argc
, argv
);
268 SetUnhandledExceptionFilter(lamexp_exception_handler
);
269 _set_invalid_parameter_handler(lamexp_invalid_param_handler
);
270 return _main(argc
, argv
);
276 fprintf(stderr
, "\nGURU MEDITATION !!!\n\nUnhandeled structured exception error! [code: 0x%X]\n", GetExceptionCode());
277 lamexp_fatal_exit(L
"Unhandeled structured exception error, application will exit!");