Updated SoX binary to v14.4.2-Git (2014-10-06), compiled with ICL 15.0 and MSVC 12.0.
[LameXP.git] / src / Main.cpp
blob3305b5702cf84d4f7dc90405c14761b854ca4338
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
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 ///////////////////////////////////////////////////////////////////////////////
23 //LameXP includes
24 #include "Global.h"
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"
36 //Qt includes
37 #include <QApplication>
38 #include <QMessageBox>
39 #include <QDate>
40 #include <QMutex>
41 #include <QDir>
43 ///////////////////////////////////////////////////////////////////////////////
44 // Main function
45 ///////////////////////////////////////////////////////////////////////////////
47 static int lamexp_main(int argc, char* argv[])
49 int iResult = -1;
50 int iShutdown = shutdownFlag_None;
51 bool bAccepted = true;
53 //Get CLI arguments
54 const QStringList &arguments = lamexp_arguments();
56 //Init console
57 lamexp_init_console(arguments);
59 //Print version info
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());
64 //print license info
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
70 if(LAMEXP_DEBUG)
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)));
83 qDebug("");
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);
93 //Initialize Qt
94 if(!lamexp_init_qt(argc, argv))
96 return -1;
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...");
114 if(iResult == 1)
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);
122 messageBox.exec();
123 messageProducerThread->wait();
124 LAMEXP_DELETE(messageProducerThread);
125 return -1;
127 LAMEXP_DELETE(messageProducerThread);
129 return 0;
132 //Kill application?
133 for(int i = 0; i < argc; i++)
135 if(!arguments[i].compare("--kill", Qt::CaseInsensitive) || !arguments[i].compare("--force-kill", Qt::CaseInsensitive))
137 return 0;
141 //Self-test
142 if(LAMEXP_DEBUG)
144 InitializationThread::selfTest();
147 //Taskbar init
148 WinSevenTaskbar::init();
150 //Create models
151 FileListModel *fileListModel = new FileListModel();
152 AudioFileModel_MetaInfo *metaInfo = new AudioFileModel_MetaInfo();
153 SettingsModel *settingsModel = new SettingsModel();
155 //Show splash screen
156 InitializationThread *poInitializationThread = new InitializationThread(&cpuFeatures);
157 SplashScreen::showSplash(poInitializationThread);
158 settingsModel->slowStartup(poInitializationThread->getSlowIndicator());
159 LAMEXP_DELETE(poInitializationThread);
161 //Validate settings
162 settingsModel->validate();
164 //Create main window
165 MainWindow *poMainWindow = new MainWindow(fileListModel, metaInfo, settingsModel);
167 //Main application loop
168 while(bAccepted && (iShutdown <= shutdownFlag_None))
170 //Show main window
171 poMainWindow->show();
172 iResult = QApplication::instance()->exec();
173 bAccepted = poMainWindow->isAccepted();
175 //Sync settings
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);
188 //Free models
189 LAMEXP_DELETE(poMainWindow);
190 LAMEXP_DELETE(fileListModel);
191 LAMEXP_DELETE(metaInfo);
192 LAMEXP_DELETE(settingsModel);
194 //Taskbar un-init
195 WinSevenTaskbar::uninit();
197 //Final clean-up
198 qDebug("Shutting down, please wait...\n");
200 //Shotdown computer
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);
209 //Terminate
210 return iResult;
213 ///////////////////////////////////////////////////////////////////////////////
214 // Applicaton entry point
215 ///////////////////////////////////////////////////////////////////////////////
217 static int _main(int argc, char* argv[])
219 if(LAMEXP_DEBUG)
221 int iResult = -1;
222 qInstallMsgHandler(lamexp_message_handler);
223 iResult = lamexp_main(argc, argv);
224 lamexp_finalization();
225 return iResult;
227 else
229 int iResult = -1;
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!");
241 catch(...)
243 PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n");
244 lamexp_fatal_exit("Unhandeled C++ exception error, application will exit!");
246 return iResult;
250 int main(int argc, char* argv[])
252 if(LAMEXP_DEBUG)
254 int exit_code = -1;
255 LAMEXP_MEMORY_CHECK(_main, exit_code, argc, argv);
256 return exit_code;
258 else
260 __try
262 lamexp_init_error_handlers();
263 return _main(argc, argv);
265 __except(1)
267 PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnhandeled structured exception error!\n");
268 lamexp_fatal_exit("Unhandeled structured exception error, application will exit!");