#include <QCoreApplication>

#include <QDebug>
#include <regex>
#include <QProcess>

void testCase1()
{
    QString line = "LICENSE STATUS:  ---LICENSED--- ";
    auto statusKey = QStringLiteral("LICENSE STATUS:");
    if (line.startsWith(statusKey)) {
        auto status = line.remove(statusKey).trimmed();
        qDebug() << status;
        if (status == QStringLiteral("---LICENSED---")) {
            qDebug() << "active";
        } else {
            qDebug() << "no";
        }
    }
}

void testCase2() {
    QProcess assoc;
    assoc.setProgram("cmd");
    assoc.setArguments({"/c","assoc", "/?"});
    assoc.start();
    assoc.waitForFinished(30*1000);
    auto rawData = assoc.readAll();
    qDebug() <<"---------";
    qDebug() << rawData;
    qDebug() << QString(rawData);
    qDebug() << QString::fromLocal8Bit(rawData);
    qDebug() <<"---------";
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    testCase2();
    testCase1();
    QStringList installList;
    installList << "Microsoft Office Std Plus 2013";
//    installList << "WPS Office 2016 专业版 (10.8.0.6206)";
//    installList << "C:\\Program Files (x86)\\Kingsoft\\WPS Office\\10.8.0.6206\\office6\\wps.exe";
//    installList << "Microsoft Office 专业增强版 2016  - zh-cn";
//    installList << "Microsoft Office  2016  - zh-cn";
    installList << "Microsoft Office 2003 Web Components";
//    std::regex windowsUpdateRegEx(("WPS Office .+ (.+)"));
//    std::regex windowsUpdateRegEx(("Microsoft Office .+ Plus 2013"));
    std::regex windowsUpdateRegEx(("Microsoft Office .+ 2003"));

    for (auto app : installList) {
        qDebug() << std::regex_match(app.toStdString(), windowsUpdateRegEx) << app;
    }

    return 0;
}
