当前位置: 首页>>代码示例>>C++>>正文


C++ Updater::checkForUpdates方法代码示例

本文整理汇总了C++中Updater::checkForUpdates方法的典型用法代码示例。如果您正苦于以下问题:C++ Updater::checkForUpdates方法的具体用法?C++ Updater::checkForUpdates怎么用?C++ Updater::checkForUpdates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Updater的用法示例。


在下文中一共展示了Updater::checkForUpdates方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: spy

void TestUpdater::updateToV2()
{
    Updater u;
    u.setLocalRepository(testOutputUpdate);
    QCOMPARE(u.localRevision(), QString("1"));
    u.setTmpDirectory(testOutputUpdateTmp);
    u.setRemoteRepository("file:///" + dataRepoToV2 + "/");
    {
        QSignalSpy spy(&u, SIGNAL(checkForUpdatesFinished(bool)));
        u.checkForUpdates();
        QVERIFY(spy.wait());
        QVERIFY2(u.state() == Updater::UpdateRequired, u.errorString().toLatin1());
    }
    {
        QSignalSpy spyWarnings(&u, SIGNAL(warning(Warning)));
        QSignalSpy spy(&u, SIGNAL(updateFinished(bool)));
        u.update();
        QVERIFY(spy.wait());
        QCOMPARE(spy.size(), 1);
        QCOMPARE(spy[0].size(), 1);
        QCOMPARE(spy[0][0].toBool(), true);
        QVERIFY2(u.state() == Updater::Uptodate, u.errorString().toLatin1());
        QCOMPARE(u.localRevision(), QString("2"));
        QCOMPARE(spyWarnings.size(), 0);
    }
    try{
        (TestUtils::assertFileEquals(testOutputUpdate + "/dir2/patch_same.txt", dataDir + "/rev2/dir2/patch_same.txt"));
        (TestUtils::assertFileEquals(testOutputUpdate + "/path_diff.txt", dataDir + "/rev2/path_diff.txt"));
        (TestUtils::assertFileEquals(testOutputUpdate + "/path_diff2.txt", dataDir + "/rev2/path_diff2.txt"));
        (TestUtils::assertFileEquals(testOutputUpdate + "/add.txt", dataDir + "/rev2/add.txt"));
        (TestUtils::assertFileEquals(testOutputUpdate + "/empty_dir", dataDir + "/rev2/empty_dir"));
    } catch(std::exception &msg) {
        QFAIL(msg.what());
    }
    QVERIFY(!QFile::exists(testOutputUpdate + "/rmfile.txt"));
    QVERIFY(!QFileInfo(testOutputUpdate + "/dirs/empty_dir2").isDir());
    QCOMPARE(QDir(testOutputUpdateTmp).entryList(QDir::NoDotAndDotDot).count(), 0);
}
开发者ID:Speedy37,项目名称:QtUpdateSystem,代码行数:38,代码来源:tst_updater.cpp

示例2: main

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

    QCommandLineParser parser;
    parser.setApplicationDescription(QCoreApplication::tr("manage a local repository (check for updates, update, check integrity)"));
    parser.addHelpOption();
    parser.addVersionOption();

    QCommandLineOption checkonly(QStringList() << "c" << "checkonly"
         , QCoreApplication::tr("Only check for updates."));

    QCommandLineOption verbose(QStringList() << "verbose"
         , QCoreApplication::tr("Run in verbose mode."));

    QCommandLineOption force(QStringList() << "f" << "force"
         , QCoreApplication::tr("Force integrity checks if the local repository is uptodate."));

    QCommandLineOption tmpDirectoryPath(QStringList() << "t" << "tmp"
         , QCoreApplication::tr("Path to use for temporary files.")
         , "tmp_directory");

    parser.addOption(checkonly);
    parser.addOption(force);
    parser.addOption(tmpDirectoryPath);
    parser.addOption(verbose);
    parser.addPositionalArgument("local_repository", QCoreApplication::tr("Path to the local repository."), "<local_repository>");
    parser.addPositionalArgument("remote_repository", QCoreApplication::tr("Path to the remote repository."), "<remote_repository>");
    parser.addPositionalArgument("username", QCoreApplication::tr("Username for the remote repository."), "[<username>");
    parser.addPositionalArgument("password", QCoreApplication::tr("Password for the remote repository."), "<password>]");
    parser.process(app);

    QLoggingCategory::setFilterRules(QStringLiteral("updatesystem.*.debug=%1").arg(parser.isSet(verbose) ? "true" : "false"));

    const QStringList args = parser.positionalArguments();
    if(args.size() < 1)
        qWarning() << "Error : local_repository argument is missing";
    else if(args.size() < 2)
        qWarning() << "Error : remote_repository argument is missing";
    else if(args.size() > 2 && args.size() < 4)
        qWarning() << "Error : password argument is missing";
    else if(args.size() > 4)
        qWarning() << "Error : too much arguments";
    else
    {
        Updater updater;
        updater.setLocalRepository(args[0]);
        updater.setRemoteRepository(args[1]);

        if(parser.isSet(tmpDirectoryPath))
            updater.setTmpDirectory(parser.value(tmpDirectoryPath));

        if(args.size() == 4)
            updater.setCredentials(args[2], args[3]);

        if(parser.isSet(checkonly))
        {
            updater.checkForUpdates();
            QEventLoop loop;
            QObject::connect(&updater, &Updater::checkForUpdatesFinished, &loop, &QEventLoop::quit);
            loop.exec();

            if(!updater.errorString().isEmpty())
            {
                fprintf(stderr, "Failure : %s\n", qPrintable(updater.errorString()));
                return 2;
            }

            if(updater.isUpdateAvailable())
            {
                printf("An update is available\n");
            }
            else
            {
                printf("Already up-to-date\n");
            }
        }
        else
        {
            updater.checkForUpdates();
            QEventLoop loop;
            QObject::connect(&updater, &Updater::checkForUpdatesFinished, &loop, &QEventLoop::quit);
            loop.exec();

            printf("Checking for updates...\n");
            if(!updater.errorString().isEmpty())
            {
                fprintf(stderr, "Failure : %s\n", qPrintable(updater.errorString()));
            }
            else if(updater.isUpdateAvailable() || parser.isSet(force))
            {
                printf("Updating...\n");
                printf("Download   0%%, Apply   0%%");
                fflush(stdout);
                updater.update();
                QObject::connect(&updater, &Updater::updateFinished, &loop, &QEventLoop::quit);
                qint64 downloaded = 0, applied = 0;
                QObject::connect(&updater, &Updater::updateDownloadProgress, [&downloaded, &applied](qint64 bytesReceived, qint64 bytesTotal) {
                    downloaded = (bytesReceived*100)/bytesTotal;
                    printf("\rDownload %3lld%%, Apply %3lld%%", downloaded, applied);
//.........这里部分代码省略.........
开发者ID:Speedy37,项目名称:QtUpdateSystem,代码行数:101,代码来源:main.cpp


注:本文中的Updater::checkForUpdates方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。