1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2010 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"
35 #include <QApplication>
36 #include <QMessageBox>
41 ///////////////////////////////////////////////////////////////////////////////
43 ///////////////////////////////////////////////////////////////////////////////
45 int lamexp_main(int argc, char* argv[])
48 bool bAccepted = true;
51 lamexp_init_console(argc, argv);
54 qDebug("LameXP - Audio Encoder Front-End");
55 qDebug("Version %d.%02d %s, Build %d [%s], MSVC compiler v%02d.%02d", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build(), lamexp_version_date().toString(Qt::ISODate).toLatin1().constData(), _MSC_VER / 100, _MSC_VER % 100);
56 qDebug("Copyright (C) 2004-%04d LoRd_MuldeR <MuldeR2@GMX.de>\n", max(lamexp_version_date().year(),QDate::currentDate().year()));
59 qDebug("This program is free software: you can redistribute it and/or modify");
60 qDebug("it under the terms of the GNU General Public License <http://www.gnu.org/>.");
61 qDebug("This program comes with ABSOLUTELY NO WARRANTY.\n");
63 //Print warning, if this is a "debug" build
64 LAMEXP_CHECK_DEBUG_BUILD;
66 //Detect CPU capabilities
67 lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features();
68 qDebug("CPU brand string: %s", cpuFeatures.brand);
69 qDebug("CPU signature: Family: %d, Model: %d, Stepping: %d", cpuFeatures.family, cpuFeatures.model, cpuFeatures.stepping);
70 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));
71 qDebug("CPU no. of cores: %d\n", cpuFeatures.count);
74 lamexp_init_qt(argc, argv);
76 //Check for expiration
77 if(lamexp_version_demo())
79 QDate expireDate = lamexp_version_date().addDays(14);
80 qWarning(QString("Note: This demo (pre-release) version of LameXP will expire at %1.\n").arg(expireDate.toString(Qt::ISODate)).toLatin1().constData());
81 if(QDate::currentDate() >= expireDate)
83 qWarning("Binary has expired !!!");
84 QMessageBox::warning(NULL, "LameXP - Expired", QString("This demo (pre-release) version of LameXP has expired at %1.\nLameXP is free software and release versions won't expire.").arg(expireDate.toString()), "Exit Program");
89 //Check for multiple instances of LameXP
90 if((iResult = lamexp_init_ipc()) != 0)
92 qDebug("LameXP is already running, connecting to running instance...");
95 MessageProducerThread *messageProducerThread = new MessageProducerThread();
96 messageProducerThread->start();
97 if(!messageProducerThread->wait(30000))
99 messageProducerThread->terminate();
100 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);
102 messageProducerThread->wait();
103 LAMEXP_DELETE(messageProducerThread);
106 LAMEXP_DELETE(messageProducerThread);
112 for(int i = 0; i < argc; i++)
114 if(!_stricmp("--kill", argv[i]) || !_stricmp("--force-kill", argv[i]))
121 FileListModel *fileListModel = new FileListModel();
122 AudioFileModel *metaInfo = new AudioFileModel();
123 SettingsModel *settingsModel = new SettingsModel();
124 settingsModel->validate();
127 InitializationThread *poInitializationThread = new InitializationThread();
128 SplashScreen::showSplash(poInitializationThread);
129 LAMEXP_DELETE(poInitializationThread);
134 MainWindow *poMainWindow = new MainWindow(fileListModel, metaInfo, settingsModel);
135 poMainWindow->show();
136 iResult = QApplication::instance()->exec();
137 bAccepted = poMainWindow->isAccepted();
138 LAMEXP_DELETE(poMainWindow);
140 //Show processing dialog
141 if(bAccepted && fileListModel->rowCount() > 0)
143 ProcessingDialog *processingDialog = new ProcessingDialog(fileListModel, settingsModel);
144 processingDialog->exec();
145 LAMEXP_DELETE(processingDialog);
150 LAMEXP_DELETE(fileListModel);
151 LAMEXP_DELETE(metaInfo);
152 LAMEXP_DELETE(settingsModel);
155 qDebug("Shutting down, please wait...\n");
161 ///////////////////////////////////////////////////////////////////////////////
162 // Applicaton entry point
163 ///////////////////////////////////////////////////////////////////////////////
165 int main(int argc, char* argv[])
170 qInstallMsgHandler(lamexp_message_handler);
171 LAMEXP_MEMORY_CHECK(iResult = lamexp_main(argc, argv));
172 lamexp_finalization();
179 fprintf(stderr, "\nEXCEPTION ERROR: %s\n", error);
180 FatalAppExit(0, L"Unhandeled exception error, application will exit!");
181 TerminateProcess(GetCurrentProcess(), -1);
187 fprintf(stderr, "\nEXCEPTION ERROR: Error code 0x%X\n", error);
188 FatalAppExit(0, L"Unhandeled exception error, application will exit!");
189 TerminateProcess(GetCurrentProcess(), -1);
195 fprintf(stderr, "\nEXCEPTION ERROR !!!\n");
196 FatalAppExit(0, L"Unhandeled exception error, application will exit!");
197 TerminateProcess(GetCurrentProcess(), -1);