<commit_before>/*
 * This file is a part of Xpiks - cross platform application for
 * keywording and uploading images for microstocks
 * Copyright (C) 2014-2017 <NAME> <<EMAIL>>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include "updatehelpers.h"
#include <QProcess>
#include <QStringList>
#include <QDir>
#include <QCoreApplication>
#include <QFileInfo>
#include "../Common/defines.h"

#ifdef Q_OS_OSX

void launchOSXdmg(const QString &dmgPath) {
    QStringList arguments;
    arguments << dmgPath;

    QProcess::startDetached("open", arguments);
}

#endif

#ifdef Q_OS_WIN

QString getLogFilenameForMinistaller() {
    QString appDataPath = XPIKS_USERDATA_PATH;
    if (appDataPath.isEmpty()) {
        appDataPath = QDir::currentPath();
    }

    const QString &logFileDir = QDir::cleanPath(appDataPath + QDir::separator() + "logs");
    QDir logsDir(logFileDir);
    Q_ASSERT(logsDir.exists());

    QString time = QDateTime::currentDateTimeUtc().toString("ddMMyyyy-hhmmss-zzz");
    QString logFilename = QString("ministaller-%1.log").arg(time);

    QString logFilePath = logsDir.filePath(logFilename);
    return logFilePath;
}

void launchWindowsInstaller(const QString &pathToUpdate) {
    LOG_DEBUG << "#";

    const QString appDirPath = QCoreApplication::applicationDirPath();
    QDir appDir(appDirPath);
    QString ministallerPath = appDir.filePath("ministaller.exe");

    if (!QFileInfo(ministallerPath).exists()) {
        LOG_WARNING << "Updater not found!" << ministallerPath;
        return;
    }

    QString installerLogPath = getLogFilenameForMinistaller();
    QStringList arguments;
    arguments << "-force-update" << "-gui" <<
                 "-install-path" << appDirPath <<
                 "-l" << installerLogPath <<
                 "-launch-exe" << "xpiks-qt.exe" <<
                 "-package-path" << pathToUpdate <<
                 "-stdout";

    QProcess::startDetached(ministallerPath, arguments);
}

#endif

namespace Helpers {
    void installUpdate(const QString &updatePath) {
#if defined(Q_OS_OSX)
        launchOSXdmg(updatePath);
#elif defined(Q_OS_WIN)
        launchWindowsInstaller(updatePath);
#endif
    }
}
<commit_msg>Fix for upgrade flow for Windows [ci skip]<commit_after>/*
 * This file is a part of Xpiks - cross platform application for
 * keywording and uploading images for microstocks
 * Copyright (C) 2014-2017 <NAME> <<EMAIL>>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include "updatehelpers.h"
#include <QProcess>
#include <QStringList>
#include <QDir>
#include <QCoreApplication>
#include <QFileInfo>
#include "../Common/defines.h"

#ifdef Q_OS_OSX

void launchOSXdmg(const QString &dmgPath) {
    QStringList arguments;
    arguments << dmgPath;

    QProcess::startDetached("open", arguments);
}

#endif

#ifdef Q_OS_WIN

QString getLogFilenameForMinistaller() {
    QString appDataPath = XPIKS_USERDATA_PATH;
    if (appDataPath.isEmpty()) {
        appDataPath = QDir::currentPath();
    }

    const QString &logFileDir = QDir::cleanPath(appDataPath + QDir::separator() + "logs");
    QDir logsDir(logFileDir);
    Q_ASSERT(logsDir.exists());

    QString time = QDateTime::currentDateTimeUtc().toString("ddMMyyyy-hhmmss-zzz");
    QString logFilename = QString("ministaller-%1.log").arg(time);

    QString logFilePath = logsDir.filePath(logFilename);
    return logFilePath;
}

void launchWindowsInstaller(const QString &pathToUpdate) {
    LOG_DEBUG << "#";

    const QString appDirPath = QCoreApplication::applicationDirPath();
    QDir appDir(appDirPath);
    QString ministallerPath = appDir.filePath("ministaller.exe");

    if (!QFileInfo(ministallerPath).exists()) {
        LOG_WARNING << "Updater not found!" << ministallerPath;
        return;
    }

    QString installerLogPath = getLogFilenameForMinistaller();
    QStringList arguments;
    arguments << "-force-update" << "-gui" <<
                 "-install-path" << appDirPath <<
                 "-l" << installerLogPath <<
                 "-launch-exe" << "Xpiks.exe" <<
                 "-package-path" << pathToUpdate <<
                 "-stdout";

    QProcess::startDetached(ministallerPath, arguments);
}

#endif

namespace Helpers {
    void installUpdate(const QString &updatePath) {
#if defined(Q_OS_OSX)
        launchOSXdmg(updatePath);
#elif defined(Q_OS_WIN)
        launchWindowsInstaller(updatePath);
#endif
    }
}

{'fraction_non_alphanumeric': 0.12314540059347182, 'fraction_numerical': 0.005510809665112336, 'mean_word_length': 3.5418671799807506, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '960921', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1464, 'n_words': 347}