#include <QCoreApplication>

#include "legalizationagent.h"

#include <DLog>
#include <QDBusConnection>
#include <QDBusError>
#include <QtConcurrent>

#include "tool.h"
#include "util/config.h"

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    app.setOrganizationName("deepin");
    app.setApplicationName("deepin-legalization-agent");

    Dtk::Core::DLogManager::setlogFilePath(Config::LogPath());
    Dtk::Core::DLogManager::registerConsoleAppender();
    Dtk::Core::DLogManager::registerFileAppender();

    qDebug() << "save log to" << Dtk::Core::DLogManager::getlogFilePath();

    app.setApplicationVersion(Tool::getVersion());

    LegalizationAgent agent;
    agent.startServer();
#ifndef QT_DEBUG
    if (!Tool::setSingleInstance(app.applicationName())) {
        qWarning() << "anthorer instance is running!";
        return 0;
    }
#endif
#ifdef Q_OS_LINUX
#ifndef QT_DEBUG
    QtConcurrent::run(Tool::cleanOldVersion);
#endif
#endif
    int ret = app.exec();
    return ret;
}
