本文整理汇总了C++中Updater::state方法的典型用法代码示例。如果您正苦于以下问题:C++ Updater::state方法的具体用法?C++ Updater::state怎么用?C++ Updater::state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Updater
的用法示例。
在下文中一共展示了Updater::state方法的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);
}
示例2: main
//.........这里部分代码省略.........
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);
fflush(stdout);
});
QObject::connect(&updater, &Updater::updateApplyProgress, [&downloaded, &applied](qint64 bytesReceived, qint64 bytesTotal) {
applied = (bytesReceived*100)/bytesTotal;
printf("\rDownload %3lld%%, Apply %3lld%%", downloaded, applied);
fflush(stdout);
});
loop.exec();
if(updater.state() != Updater::Uptodate)
{
fprintf(stderr, "Failure : %s\n", qPrintable(updater.errorString()));
return 2;
}
printf("\nUpdated\n");
}
else
{
printf("Already up-to-date\n");
}
}
return 0;
}
parser.showHelp(1);
return 1;
}