Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 285 lines (254 sloc) 9.495 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
// Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////

//LameXP includes
#include "Global.h"
#include "Dialog_SplashScreen.h"
#include "Dialog_MainWindow.h"
#include "Dialog_Processing.h"
#include "Thread_Initialization.h"
#include "Thread_MessageProducer.h"
#include "Model_Settings.h"
#include "Model_FileList.h"
#include "Model_AudioFile.h"
#include "Encoder_Abstract.h"
#include "WinSevenTaskbar.h"

//Qt includes
#include <QApplication>
#include <QMessageBox>
#include <QDate>
#include <QMutex>
#include <QDir>
#include <QInputDialog>

///////////////////////////////////////////////////////////////////////////////
// Main function
///////////////////////////////////////////////////////////////////////////////

static int lamexp_main(int argc, char* argv[])
{
int iResult = -1;
int iShutdown = shutdownFlag_None;
bool bAccepted = true;

//Get CLI arguments
const QStringList &arguments = lamexp_arguments();

//Init console
lamexp_init_console(arguments);

//Print version info
qDebug("LameXP - Audio Encoder Front-End v%d.%02d %s (Build #%03d)", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build());
qDebug("Copyright (c) 2004-%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.", qMax(lamexp_version_date().year(),QDate::currentDate().year()));
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());

//print license info
qDebug("This program is free software: you can redistribute it and/or modify");
qDebug("it under the terms of the GNU General Public License <http://www.gnu.org/>.");
qDebug("Note that this program is distributed with ABSOLUTELY NO WARRANTY.\n");

//Print warning, if this is a "debug" build
if(LAMEXP_DEBUG)
{
qWarning("---------------------------------------------------------");
qWarning("DEBUG BUILD: DO NOT RELEASE THIS BINARY TO THE PUBLIC !!!");
qWarning("---------------------------------------------------------\n");
}

//Enumerate CLI arguments
qDebug("Command-Line Arguments:");
for(int i = 0; i < arguments.count(); i++)
{
qDebug("argv[%d]=%s", i, arguments.at(i).toUtf8().constData());
}
qDebug("");

//Detect CPU capabilities
lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features(arguments);
qDebug(" CPU vendor id : %s (Intel: %s)", cpuFeatures.vendor, LAMEXP_BOOL2STR(cpuFeatures.intel));
qDebug("CPU brand string : %s", cpuFeatures.brand);
qDebug(" CPU signature : Family: %d, Model: %d, Stepping: %d", cpuFeatures.family, cpuFeatures.model, cpuFeatures.stepping);
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));
qDebug(" Number of CPU's : %d\n", cpuFeatures.count);

//Initialize Qt
if(!lamexp_init_qt(argc, argv))
{
return -1;
}

//Check for expiration
if(lamexp_version_demo())
{
if(QDate::currentDate().addDays(1) < lamexp_version_date())
{
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());
}
qWarning(QString("Note: This demo (pre-release) version of LameXP will expire at %1.\n").arg(lamexp_version_expires().toString(Qt::ISODate)).toLatin1().constData());
}

//Check for multiple instances of LameXP
if((iResult = lamexp_init_ipc()) != 0)
{
qDebug("LameXP is already running, connecting to running instance...");
if(iResult == 1)
{
MessageProducerThread *messageProducerThread = new MessageProducerThread();
messageProducerThread->start();
if(!messageProducerThread->wait(30000))
{
messageProducerThread->terminate();
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);
messageBox.exec();
messageProducerThread->wait();
LAMEXP_DELETE(messageProducerThread);
return -1;
}
LAMEXP_DELETE(messageProducerThread);
}
return 0;
}

//Kill application?
for(int i = 0; i < argc; i++)
{
if(!arguments[i].compare("--kill", Qt::CaseInsensitive) || !arguments[i].compare("--force-kill", Qt::CaseInsensitive))
{
return 0;
}
}

//Self-test
if(LAMEXP_DEBUG)
{
InitializationThread::selfTest();
}

//Taskbar init
WinSevenTaskbar::init();

//Create models
FileListModel *fileListModel = new FileListModel();
AudioFileModel *metaInfo = new AudioFileModel();
SettingsModel *settingsModel = new SettingsModel();

//Show splash screen
InitializationThread *poInitializationThread = new InitializationThread(&cpuFeatures);
SplashScreen::showSplash(poInitializationThread);
settingsModel->slowStartup(poInitializationThread->getSlowIndicator());
LAMEXP_DELETE(poInitializationThread);

//Validate settings
settingsModel->validate();

//Create main window
MainWindow *poMainWindow = new MainWindow(fileListModel, metaInfo, settingsModel);

//Main application loop
while(bAccepted && (iShutdown <= shutdownFlag_None))
{
//Show main window
poMainWindow->show();
iResult = QApplication::instance()->exec();
bAccepted = poMainWindow->isAccepted();

//Show processing dialog
if(bAccepted && (fileListModel->rowCount() > 0))
{
ProcessingDialog *processingDialog = new ProcessingDialog(fileListModel, metaInfo, settingsModel);
processingDialog->exec();
iShutdown = processingDialog->getShutdownFlag();
LAMEXP_DELETE(processingDialog);
}
}

//Free models
LAMEXP_DELETE(poMainWindow);
LAMEXP_DELETE(fileListModel);
LAMEXP_DELETE(metaInfo);
LAMEXP_DELETE(settingsModel);

//Taskbar un-init
WinSevenTaskbar::uninit();

//Final clean-up
qDebug("Shutting down, please wait...\n");

//Shotdown computer
if(iShutdown > shutdownFlag_None)
{
if(!lamexp_shutdown_computer(QApplication::applicationFilePath(), 12, true, (iShutdown == shutdownFlag_Hibernate)))
{
QMessageBox messageBox(QMessageBox::Critical, "LameXP", "Sorry, LameXP was unable to shutdown your computer!", QMessageBox::NoButton, NULL, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint);
}
}

//Terminate
return iResult;
}

///////////////////////////////////////////////////////////////////////////////
// Applicaton entry point
///////////////////////////////////////////////////////////////////////////////

static int _main(int argc, char* argv[])
{
if(LAMEXP_DEBUG)
{
int iResult = -1;
qInstallMsgHandler(lamexp_message_handler);
iResult = lamexp_main(argc, argv);
lamexp_finalization();
return iResult;
}
else
{
int iResult = -1;
try
{
qInstallMsgHandler(lamexp_message_handler);
iResult = lamexp_main(argc, argv);
lamexp_finalization();
}
catch(char *error)
{
fflush(stdout);
fflush(stderr);
fprintf(stderr, "\nGURU MEDITATION !!!\n\nException error message: %s\n", error);
FatalAppExit(0, L"Unhandeled C++ exception error, application will exit!");
TerminateProcess(GetCurrentProcess(), -1);
}
catch(int error)
{
fflush(stdout);
fflush(stderr);
fprintf(stderr, "\nGURU MEDITATION !!!\n\nException error code: 0x%X\n", error);
FatalAppExit(0, L"Unhandeled C++ exception error, application will exit!");
TerminateProcess(GetCurrentProcess(), -1);
}
catch(...)
{
fflush(stdout);
fflush(stderr);
fprintf(stderr, "\nGURU MEDITATION !!!\n");
FatalAppExit(0, L"Unhandeled C++ exception error, application will exit!");
TerminateProcess(GetCurrentProcess(), -1);
}
return iResult;
}
}

int main(int argc, char* argv[])
{
if(LAMEXP_DEBUG)
{
int exit_code = -1;
LAMEXP_MEMORY_CHECK(_main, exit_code, argc, argv);
return exit_code;
}
else
{
__try
{
SetUnhandledExceptionFilter(lamexp_exception_handler);
_set_invalid_parameter_handler(lamexp_invalid_param_handler);
return _main(argc, argv);
}
__except(1)
{
fflush(stdout);
fflush(stderr);
fprintf(stderr, "\nGURU MEDITATION !!!\n\nUnhandeled structured exception error! [code: 0x%X]\n", GetExceptionCode());
FatalAppExit(0, L"Unhandeled structured exception error, application will exit!");
TerminateProcess(GetCurrentProcess(), -1);
}
}
}
Something went wrong with that request. Please try again.