OSDN Git Service

Update MediaInfo binaries to v0.7.53 (2012-01-24), compiled with ICL 12.1.6 and MSVC...
[lamexp/LameXP.git] / src / Main.cpp
index 7c933f0..4ebddab 100644 (file)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 // LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2010 LoRd_MuldeR <MuldeR2@GMX.de>
+// 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
@@ -30,6 +30,7 @@
 #include "Model_FileList.h"
 #include "Model_AudioFile.h"
 #include "Encoder_Abstract.h"
+#include "WinSevenTaskbar.h"
 
 //Qt includes
 #include <QApplication>
 // Main function
 ///////////////////////////////////////////////////////////////////////////////
 
-int lamexp_main(int argc, char* argv[])
+static int lamexp_main(int argc, char* argv[])
 {
        int iResult = -1;
+       int iShutdown = shutdownFlag_None;
        bool bAccepted = true;
        
        //Init console
        lamexp_init_console(argc, argv);
 
        //Print version info
-       qDebug("LameXP - Audio Encoder Front-End");
-       qDebug("Version %d.%02d %s, Build %d [%s], compiled with %s", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build(), lamexp_version_date().toString(Qt::ISODate).toLatin1().constData(), lamexp_version_compiler());
-       qDebug("Copyright (C) 2004-%04d LoRd_MuldeR <MuldeR2@GMX.de>\n", max(lamexp_version_date().year(),QDate::currentDate().year()));
+       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("This program comes with ABSOLUTELY NO WARRANTY.\n");
+       qDebug("Note that this program is distributed with ABSOLUTELY NO WARRANTY.\n");
 
        //Print warning, if this is a "debug" build
-       LAMEXP_CHECK_DEBUG_BUILD;
+       if(LAMEXP_DEBUG)
+       {
+               qWarning("---------------------------------------------------------");
+               qWarning("DEBUG BUILD: DO NOT RELEASE THIS BINARY TO THE PUBLIC !!!");
+               qWarning("---------------------------------------------------------\n"); 
+       }
        
        //Detect CPU capabilities
-       lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features();
+       lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features(argc, argv);
+       qDebug("   CPU vendor id  :  %s (Intel: %s)", cpuFeatures.vendor, LAMEXP_BOOL(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_BOOL(cpuFeatures.mmx), LAMEXP_BOOL(cpuFeatures.sse), LAMEXP_BOOL(cpuFeatures.sse2), LAMEXP_BOOL(cpuFeatures.sse3), LAMEXP_BOOL(cpuFeatures.ssse3), LAMEXP_BOOL(cpuFeatures.x64));
        qDebug(" Number of CPU's  :  %d\n", cpuFeatures.count);
        
        //Initialize Qt
-       lamexp_init_qt(argc, argv);
+       if(!lamexp_init_qt(argc, argv))
+       {
+               return -1;
+       }
 
        //Check for expiration
        if(lamexp_version_demo())
        {
-               QDate expireDate = lamexp_version_date().addDays(14);
-               qWarning(QString("Note: This demo (pre-release) version of LameXP will expire at %1.\n").arg(expireDate.toString(Qt::ISODate)).toLatin1().constData());
-               if(QDate::currentDate() >= expireDate)
+               if(QDate::currentDate().addDays(1) < lamexp_version_date())
                {
-                       qWarning("Binary has expired !!!");
-                       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");
-                       return 0;
+                       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
@@ -118,22 +126,34 @@ int lamexp_main(int argc, char* argv[])
                }
        }
        
+       //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();
-       settingsModel->validate();
        
        //Show splash screen
-       InitializationThread *poInitializationThread = new InitializationThread();
+       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)
+       while(bAccepted && (iShutdown <= shutdownFlag_None))
        {
                //Show main window
                poMainWindow->show();
@@ -141,10 +161,11 @@ int lamexp_main(int argc, char* argv[])
                bAccepted = poMainWindow->isAccepted();
 
                //Show processing dialog
-               if(bAccepted && fileListModel->rowCount() > 0)
+               if(bAccepted && (fileListModel->rowCount() > 0))
                {
                        ProcessingDialog *processingDialog = new ProcessingDialog(fileListModel, metaInfo, settingsModel);
                        processingDialog->exec();
+                       iShutdown = processingDialog->getShutdownFlag();
                        LAMEXP_DELETE(processingDialog);
                }
        }
@@ -154,10 +175,22 @@ int lamexp_main(int argc, char* argv[])
        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;
 }
@@ -166,38 +199,88 @@ int lamexp_main(int argc, char* argv[])
 // Applicaton entry point
 ///////////////////////////////////////////////////////////////////////////////
 
-int main(int argc, char* argv[])
+static int _main(int argc, char* argv[])
 {
-       try
+       if(LAMEXP_DEBUG)
        {
-               int iResult;
+               int iResult = -1;
                qInstallMsgHandler(lamexp_message_handler);
                LAMEXP_MEMORY_CHECK(iResult = lamexp_main(argc, argv));
                lamexp_finalization();
                return iResult;
        }
-       catch(char *error)
+       else
        {
-               fflush(stdout);
-               fflush(stderr);
-               fprintf(stderr, "\nEXCEPTION ERROR: %s\n", error);
-               FatalAppExit(0, L"Unhandeled exception error, application will exit!");
-               TerminateProcess(GetCurrentProcess(), -1);
+               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;
        }
-       catch(int error)
+}
+
+int main(int argc, char* argv[])
+{
+       if(LAMEXP_DEBUG)
        {
-               fflush(stdout);
-               fflush(stderr);
-               fprintf(stderr, "\nEXCEPTION ERROR: Error code 0x%X\n", error);
-               FatalAppExit(0, L"Unhandeled exception error, application will exit!");
-               TerminateProcess(GetCurrentProcess(), -1);
+               return _main(argc, argv);
        }
-       catch(...)
+       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);
+               }
+       }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// CRT initialization
+///////////////////////////////////////////////////////////////////////////////
+
+extern "C"
+{
+       int WinMainCRTStartup(void);
+
+       int lamexp_crt_startup(void)
        {
-               fflush(stdout);
-               fflush(stderr);
-               fprintf(stderr, "\nEXCEPTION ERROR !!!\n");
-               FatalAppExit(0, L"Unhandeled exception error, application will exit!");
-               TerminateProcess(GetCurrentProcess(), -1);
+               return WinMainCRTStartup();
        }
 }