#include "cigarette.h"
#include <QtWidgets/QApplication>
#include <QPixmap>
#include <QSplashScreen>
#include <Windows.h>
#include <qmessagebox.h>
#if defined LICENSE_VERIFY
#pragma comment(lib,"CryptoToolLib.lib")
#include "CryptoToolLib.h"
#endif

int main(int argc, char* argv[])
{
    QApplication a(argc, argv);
    HANDLE hMutex = NULL;

    hMutex = CreateMutex(nullptr, TRUE, L"CigratteShanghai");
    if ((GetLastError() == ERROR_ALREADY_EXISTS) || (hMutex == NULL)) {
        QMessageBox::warning(nullptr, "Error", "An instance of the application is already running.");
        CloseHandle(hMutex);
        hMutex = NULL;
        a.closeAllWindows();
        return 0;
    }

#if defined LICENSE_VERIFY
    if (!VerifyLicense())
    {
        exit(0);
    }
#endif
    qRegisterMetaType<cv::Mat>("cv::Mat");
    QPixmap pixmap("splash.jpg");
    QSplashScreen splash(pixmap);
    splash.show();
    a.processEvents();
    Cigarette w;
    w.show();
    //w.showFullScreen();
    splash.finish(&w);
    a.exec();

    if (hMutex != NULL) {
        CloseHandle (hMutex);
        hMutex = NULL;
    }

    return 0;
}
