1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 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>
41 #include <QInputDialog>
43 ///////////////////////////////////////////////////////////////////////////////
45 ///////////////////////////////////////////////////////////////////////////////
47 static int lamexp_main(int argc, char* argv[])
50 int iShutdown = shutdownFlag_None;
51 bool bAccepted = true;
54 lamexp_init_console(argc, argv);
57 qDebug("LameXP - Audio Encoder Front-End v%d.%02d %s (Build #%03d)", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build());
58 qDebug("Copyright (c) 2004-%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.", qMax(lamexp_version_date().year(),QDate::currentDate().year()));
59 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());
62 qDebug("This program is free software: you can redistribute it and/or modify");
63 qDebug("it under the terms of the GNU General Public License <http://www.gnu.org/>.");
64 qDebug("Note that this program is distributed with ABSOLUTELY NO WARRANTY.\n");
66 //Print warning, if this is a "debug" build
69 qWarning("---------------------------------------------------------");
70 qWarning("DEBUG BUILD: DO NOT RELEASE THIS BINARY TO THE PUBLIC !!!");
71 qWarning("---------------------------------------------------------\n");
74 //Detect CPU capabilities
75 lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features(argc, argv);
76 qDebug(" CPU vendor id : %s (Intel: %s)", cpuFeatures.vendor, LAMEXP_BOOL(cpuFeatures.intel));
77 qDebug("CPU brand string : %s", cpuFeatures.brand);
78 qDebug(" CPU signature : Family: %d, Model: %d, Stepping: %d", cpuFeatures.family, cpuFeatures.model, cpuFeatures.stepping);
79 qDebug("CPU capabilities : MMX: %s, SSE: %s, SSE2: %s, SSE3: %s, SSSE3: %s, x64: %s", LAMEXP_BOOL(cpuFeatures.mmx), LAMEXP_BOOL(cpuFeatures.sse), LAMEXP_BOOL(cpuFeatures.sse2), LAMEXP_BOOL(cpuFeatures.sse3), LAMEXP_BOOL(cpuFeatures.ssse3), LAMEXP_BOOL(cpuFeatures.x64));
80 qDebug(" Number of CPU's : %d\n", cpuFeatures.count);
83 if(!lamexp_init_qt(argc, argv))
88 //Check for expiration
89 if(lamexp_version_demo())
91 qWarning(QString("Note: This demo (pre-release) version of LameXP will expire at %1.\n").arg(lamexp_version_expires().toString(Qt::ISODate)).toLatin1().constData());
94 //Check for multiple instances of LameXP
95 if((iResult = lamexp_init_ipc()) != 0)
97 qDebug("LameXP is already running, connecting to running instance...");
100 MessageProducerThread *messageProducerThread = new MessageProducerThread();
101 messageProducerThread->start();
102 if(!messageProducerThread->wait(30000))
104 messageProducerThread->terminate();
105 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);
107 messageProducerThread->wait();
108 LAMEXP_DELETE(messageProducerThread);
111 LAMEXP_DELETE(messageProducerThread);
117 for(int i = 0; i < argc; i++)
119 if(!_stricmp("--kill", argv[i]) || !_stricmp("--force-kill", argv[i]))
128 InitializationThread::selfTest();
132 WinSevenTaskbar::init();
135 FileListModel *fileListModel = new FileListModel();
136 AudioFileModel *metaInfo = new AudioFileModel();
137 SettingsModel *settingsModel = new SettingsModel();
140 InitializationThread *poInitializationThread = new InitializationThread(&cpuFeatures);
141 SplashScreen::showSplash(poInitializationThread);
142 settingsModel->slowStartup(poInitializationThread->getSlowIndicator());
143 LAMEXP_DELETE(poInitializationThread);
146 settingsModel->validate();
149 MainWindow *poMainWindow = new MainWindow(fileListModel, metaInfo, settingsModel);
151 //Main application loop
152 while(bAccepted && (iShutdown <= shutdownFlag_None))
155 poMainWindow->show();
156 iResult = QApplication::instance()->exec();
157 bAccepted = poMainWindow->isAccepted();
159 //Show processing dialog
160 if(bAccepted && fileListModel->rowCount() > 0)
162 ProcessingDialog *processingDialog = new ProcessingDialog(fileListModel, metaInfo, settingsModel);
163 processingDialog->exec();
164 iShutdown = processingDialog->getShutdownFlag();
165 LAMEXP_DELETE(processingDialog);
170 LAMEXP_DELETE(poMainWindow);
171 LAMEXP_DELETE(fileListModel);
172 LAMEXP_DELETE(metaInfo);
173 LAMEXP_DELETE(settingsModel);
176 WinSevenTaskbar::uninit();
179 qDebug("Shutting down, please wait...\n");
182 if(iShutdown > shutdownFlag_None)
184 if(!lamexp_shutdown_computer(QApplication::applicationFilePath(), 12, true, (iShutdown == shutdownFlag_Hibernate)))
186 QMessageBox messageBox(QMessageBox::Critical, "LameXP", "Sorry, LameXP was unable to shutdown your computer!", QMessageBox::NoButton, NULL, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint);
194 ///////////////////////////////////////////////////////////////////////////////
195 // Applicaton entry point
196 ///////////////////////////////////////////////////////////////////////////////
198 static int _main(int argc, char* argv[])
203 qInstallMsgHandler(lamexp_message_handler);
204 LAMEXP_MEMORY_CHECK(iResult = lamexp_main(argc, argv));
205 lamexp_finalization();
213 qInstallMsgHandler(lamexp_message_handler);
214 iResult = lamexp_main(argc, argv);
215 lamexp_finalization();
221 fprintf(stderr, "\nGURU MEDITATION !!!\n\nException error message: %s\n", error);
222 FatalAppExit(0, L"Unhandeled C++ exception error, application will exit!");
223 TerminateProcess(GetCurrentProcess(), -1);
229 fprintf(stderr, "\nGURU MEDITATION !!!\n\nException error code: 0x%X\n", error);
230 FatalAppExit(0, L"Unhandeled C++ exception error, application will exit!");
231 TerminateProcess(GetCurrentProcess(), -1);
237 fprintf(stderr, "\nGURU MEDITATION !!!\n");
238 FatalAppExit(0, L"Unhandeled C++ exception error, application will exit!");
239 TerminateProcess(GetCurrentProcess(), -1);
245 int main(int argc, char* argv[])
249 return _main(argc, argv);
255 SetUnhandledExceptionFilter(lamexp_exception_handler);
256 _set_invalid_parameter_handler(lamexp_invalid_param_handler);
257 return _main(argc, argv);
263 fprintf(stderr, "\nGURU MEDITATION !!!\n\nUnhandeled structured exception error! [code: 0x%X]\n", GetExceptionCode());
264 FatalAppExit(0, L"Unhandeled structured exception error, application will exit!");
265 TerminateProcess(GetCurrentProcess(), -1);
270 ///////////////////////////////////////////////////////////////////////////////
271 // CRT initialization
272 ///////////////////////////////////////////////////////////////////////////////
276 int WinMainCRTStartup(void);
278 int lamexp_crt_startup(void)
280 return WinMainCRTStartup();