1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
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, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
25 #include "Dialog_SplashScreen.h"
26 #include "Dialog_MainWindow.h"
27 #include "Dialog_Processing.h"
28 #include "Thread_Initialization.h"
29 #include "Thread_MessageProducer.h"
30 #include "Model_Settings.h"
31 #include "Model_FileList.h"
32 #include "Model_AudioFile.h"
33 #include "Encoder_Abstract.h"
34 #include "WinSevenTaskbar.h"
37 #include <QApplication>
38 #include <QMessageBox>
43 ///////////////////////////////////////////////////////////////////////////////
45 ///////////////////////////////////////////////////////////////////////////////
47 static int lamexp_main(int argc
, char* argv
[])
50 int iShutdown
= shutdownFlag_None
;
51 bool bAccepted
= true;
54 const QStringList
&arguments
= lamexp_arguments();
57 lamexp_init_console(arguments
);
60 qDebug("LameXP - Audio Encoder Front-End v%d.%02d %s (Build #%03d)", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build());
61 qDebug("Copyright (c) 2004-%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.", qMax(lamexp_version_date().year(), lamexp_current_date_safe().year()));
62 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());
65 qDebug("This program is free software: you can redistribute it and/or modify");
66 qDebug("it under the terms of the GNU General Public License <http://www.gnu.org/>.");
67 qDebug("Note that this program is distributed with ABSOLUTELY NO WARRANTY.\n");
69 //Print warning, if this is a "debug" build
72 qWarning("---------------------------------------------------------");
73 qWarning("DEBUG BUILD: DO NOT RELEASE THIS BINARY TO THE PUBLIC !!!");
74 qWarning("---------------------------------------------------------\n");
77 //Enumerate CLI arguments
78 qDebug("Command-Line Arguments:");
79 for(int i
= 0; i
< arguments
.count(); i
++)
81 qDebug("argv[%d]=%s", i
, QUTF8(arguments
.at(i
)));
85 //Detect CPU capabilities
86 lamexp_cpu_t cpuFeatures
= lamexp_detect_cpu_features(arguments
);
87 qDebug(" CPU vendor id : %s (Intel: %s)", cpuFeatures
.vendor
, LAMEXP_BOOL2STR(cpuFeatures
.intel
));
88 qDebug("CPU brand string : %s", cpuFeatures
.brand
);
89 qDebug(" CPU signature : Family: %d, Model: %d, Stepping: %d", cpuFeatures
.family
, cpuFeatures
.model
, cpuFeatures
.stepping
);
90 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
));
91 qDebug(" Number of CPU's : %d\n", cpuFeatures
.count
);
94 if(!lamexp_init_qt(argc
, argv
))
99 //Check for expiration
100 if(lamexp_version_demo())
102 const QDate currentDate
= lamexp_current_date_safe();
103 if(currentDate
.addDays(1) < lamexp_version_date())
105 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());
107 qWarning(QString("Note: This demo (pre-release) version of LameXP will expire at %1.\n").arg(lamexp_version_expires().toString(Qt::ISODate
)).toLatin1().constData());
110 //Check for multiple instances of LameXP
111 if((iResult
= lamexp_init_ipc()) != 0)
113 qDebug("LameXP is already running, connecting to running instance...");
116 MessageProducerThread
*messageProducerThread
= new MessageProducerThread();
117 messageProducerThread
->start();
118 if(!messageProducerThread
->wait(30000))
120 messageProducerThread
->terminate();
121 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
);
123 messageProducerThread
->wait();
124 LAMEXP_DELETE(messageProducerThread
);
127 LAMEXP_DELETE(messageProducerThread
);
133 for(int i
= 0; i
< argc
; i
++)
135 if(!arguments
[i
].compare("--kill", Qt::CaseInsensitive
) || !arguments
[i
].compare("--force-kill", Qt::CaseInsensitive
))
144 InitializationThread::selfTest();
148 WinSevenTaskbar::init();
151 FileListModel
*fileListModel
= new FileListModel();
152 AudioFileModel_MetaInfo
*metaInfo
= new AudioFileModel_MetaInfo();
153 SettingsModel
*settingsModel
= new SettingsModel();
156 InitializationThread
*poInitializationThread
= new InitializationThread(&cpuFeatures
);
157 SplashScreen::showSplash(poInitializationThread
);
158 settingsModel
->slowStartup(poInitializationThread
->getSlowIndicator());
159 LAMEXP_DELETE(poInitializationThread
);
162 settingsModel
->validate();
165 MainWindow
*poMainWindow
= new MainWindow(fileListModel
, metaInfo
, settingsModel
);
167 //Main application loop
168 while(bAccepted
&& (iShutdown
<= shutdownFlag_None
))
171 poMainWindow
->show();
172 iResult
= QApplication::instance()->exec();
173 bAccepted
= poMainWindow
->isAccepted();
176 settingsModel
->syncNow();
178 //Show processing dialog
179 if(bAccepted
&& (fileListModel
->rowCount() > 0))
181 ProcessingDialog
*processingDialog
= new ProcessingDialog(fileListModel
, metaInfo
, settingsModel
);
182 processingDialog
->exec();
183 iShutdown
= processingDialog
->getShutdownFlag();
184 LAMEXP_DELETE(processingDialog
);
189 LAMEXP_DELETE(poMainWindow
);
190 LAMEXP_DELETE(fileListModel
);
191 LAMEXP_DELETE(metaInfo
);
192 LAMEXP_DELETE(settingsModel
);
195 WinSevenTaskbar::uninit();
198 qDebug("Shutting down, please wait...\n");
201 if(iShutdown
> shutdownFlag_None
)
203 if(!lamexp_shutdown_computer(QApplication::applicationFilePath(), 12, true, (iShutdown
== shutdownFlag_Hibernate
)))
205 QMessageBox
messageBox(QMessageBox::Critical
, "LameXP", "Sorry, LameXP was unable to shutdown your computer!", QMessageBox::NoButton
, NULL
, Qt::Dialog
| Qt::MSWindowsFixedSizeDialogHint
| Qt::WindowStaysOnTopHint
);
213 ///////////////////////////////////////////////////////////////////////////////
214 // Applicaton entry point
215 ///////////////////////////////////////////////////////////////////////////////
217 static int _main(int argc
, char* argv
[])
222 qInstallMsgHandler(lamexp_message_handler
);
223 iResult
= lamexp_main(argc
, argv
);
224 lamexp_finalization();
232 qInstallMsgHandler(lamexp_message_handler
);
233 iResult
= lamexp_main(argc
, argv
);
234 lamexp_finalization();
236 catch(const std::exception
&error
)
238 PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error
.what());
239 lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!");
243 PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n");
244 lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!");
250 int main(int argc
, char* argv
[])
255 LAMEXP_MEMORY_CHECK(_main
, exit_code
, argc
, argv
);
262 lamexp_init_error_handlers();
263 return _main(argc
, argv
);
267 PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnhandeled structured exception error!\n");
268 lamexp_fatal_exit("Unhandeled structured exception error, application will exit!");