diff options
Diffstat (limited to 'api/logic/updater')
-rw-r--r-- | api/logic/updater/DownloadTask.cpp | 182 | ||||
-rw-r--r-- | api/logic/updater/DownloadTask.h | 110 | ||||
-rw-r--r-- | api/logic/updater/DownloadTask_test.cpp | 336 | ||||
-rw-r--r-- | api/logic/updater/GoUpdate.cpp | 382 | ||||
-rw-r--r-- | api/logic/updater/GoUpdate.h | 138 | ||||
-rw-r--r-- | api/logic/updater/UpdateChecker.cpp | 398 | ||||
-rw-r--r-- | api/logic/updater/UpdateChecker.h | 168 | ||||
-rw-r--r-- | api/logic/updater/UpdateChecker_test.cpp | 242 | ||||
-rw-r--r-- | api/logic/updater/testdata/1.json | 82 | ||||
-rw-r--r-- | api/logic/updater/testdata/2.json | 58 | ||||
-rw-r--r-- | api/logic/updater/testdata/channels.json | 42 | ||||
-rw-r--r-- | api/logic/updater/testdata/errorChannels.json | 42 | ||||
-rw-r--r-- | api/logic/updater/testdata/garbageChannels.json | 40 | ||||
-rw-r--r-- | api/logic/updater/testdata/index.json | 14 | ||||
-rw-r--r-- | api/logic/updater/testdata/noChannels.json | 6 | ||||
-rw-r--r-- | api/logic/updater/testdata/oneChannel.json | 18 |
16 files changed, 1129 insertions, 1129 deletions
diff --git a/api/logic/updater/DownloadTask.cpp b/api/logic/updater/DownloadTask.cpp index e0adf593..cb92018d 100644 --- a/api/logic/updater/DownloadTask.cpp +++ b/api/logic/updater/DownloadTask.cpp @@ -27,140 +27,140 @@ namespace GoUpdate { DownloadTask::DownloadTask(Status status, QString target, QObject *parent) - : Task(parent), m_updateFilesDir(target) + : Task(parent), m_updateFilesDir(target) { - m_status = status; + m_status = status; - m_updateFilesDir.setAutoRemove(false); + m_updateFilesDir.setAutoRemove(false); } void DownloadTask::executeTask() { - loadVersionInfo(); + loadVersionInfo(); } void DownloadTask::loadVersionInfo() { - setStatus(tr("Loading version information...")); + setStatus(tr("Loading version information...")); - NetJob *netJob = new NetJob("Version Info"); + NetJob *netJob = new NetJob("Version Info"); - // Find the index URL. - QUrl newIndexUrl = QUrl(m_status.newRepoUrl).resolved(QString::number(m_status.newVersionId) + ".json"); - qDebug() << m_status.newRepoUrl << " turns into " << newIndexUrl; + // Find the index URL. + QUrl newIndexUrl = QUrl(m_status.newRepoUrl).resolved(QString::number(m_status.newVersionId) + ".json"); + qDebug() << m_status.newRepoUrl << " turns into " << newIndexUrl; - netJob->addNetAction(m_newVersionFileListDownload = Net::Download::makeByteArray(newIndexUrl, &newVersionFileListData)); + netJob->addNetAction(m_newVersionFileListDownload = Net::Download::makeByteArray(newIndexUrl, &newVersionFileListData)); - // If we have a current version URL, get that one too. - if (!m_status.currentRepoUrl.isEmpty()) - { - QUrl cIndexUrl = QUrl(m_status.currentRepoUrl).resolved(QString::number(m_status.currentVersionId) + ".json"); - netJob->addNetAction(m_currentVersionFileListDownload = Net::Download::makeByteArray(cIndexUrl, ¤tVersionFileListData)); - qDebug() << m_status.currentRepoUrl << " turns into " << cIndexUrl; - } + // If we have a current version URL, get that one too. + if (!m_status.currentRepoUrl.isEmpty()) + { + QUrl cIndexUrl = QUrl(m_status.currentRepoUrl).resolved(QString::number(m_status.currentVersionId) + ".json"); + netJob->addNetAction(m_currentVersionFileListDownload = Net::Download::makeByteArray(cIndexUrl, ¤tVersionFileListData)); + qDebug() << m_status.currentRepoUrl << " turns into " << cIndexUrl; + } - // connect signals and start the job - connect(netJob, &NetJob::succeeded, this, &DownloadTask::processDownloadedVersionInfo); - connect(netJob, &NetJob::failed, this, &DownloadTask::vinfoDownloadFailed); - m_vinfoNetJob.reset(netJob); - netJob->start(); + // connect signals and start the job + connect(netJob, &NetJob::succeeded, this, &DownloadTask::processDownloadedVersionInfo); + connect(netJob, &NetJob::failed, this, &DownloadTask::vinfoDownloadFailed); + m_vinfoNetJob.reset(netJob); + netJob->start(); } void DownloadTask::vinfoDownloadFailed() { - // Something failed. We really need the second download (current version info), so parse - // downloads anyways as long as the first one succeeded. - if (m_newVersionFileListDownload->wasSuccessful()) - { - processDownloadedVersionInfo(); - return; - } - - // TODO: Give a more detailed error message. - qCritical() << "Failed to download version info files."; - emitFailed(tr("Failed to download version info files.")); + // Something failed. We really need the second download (current version info), so parse + // downloads anyways as long as the first one succeeded. + if (m_newVersionFileListDownload->wasSuccessful()) + { + processDownloadedVersionInfo(); + return; + } + + // TODO: Give a more detailed error message. + qCritical() << "Failed to download version info files."; + emitFailed(tr("Failed to download version info files.")); } void DownloadTask::processDownloadedVersionInfo() { - VersionFileList m_currentVersionFileList; - VersionFileList m_newVersionFileList; - - setStatus(tr("Reading file list for new version...")); - qDebug() << "Reading file list for new version..."; - QString error; - if (!parseVersionInfo(newVersionFileListData, m_newVersionFileList, error)) - { - qCritical() << error; - emitFailed(error); - return; - } - - // if we have the current version info, use it. - if (m_currentVersionFileListDownload && m_currentVersionFileListDownload->wasSuccessful()) - { - setStatus(tr("Reading file list for current version...")); - qDebug() << "Reading file list for current version..."; - // if this fails, it's not a complete loss. - QString error; - if(!parseVersionInfo( currentVersionFileListData, m_currentVersionFileList, error)) - { - qDebug() << error << "This is not a fatal error."; - } - } - - // We don't need this any more. - m_currentVersionFileListDownload.reset(); - m_newVersionFileListDownload.reset(); - m_vinfoNetJob.reset(); - - setStatus(tr("Processing file lists - figuring out how to install the update...")); - - // make a new netjob for the actual update files - NetJobPtr netJob (new NetJob("Update Files")); - - // fill netJob and operationList - if (!processFileLists(m_currentVersionFileList, m_newVersionFileList, m_status.rootPath, m_updateFilesDir.path(), netJob, m_operations)) - { - emitFailed(tr("Failed to process update lists...")); - return; - } - - // Now start the download. - QObject::connect(netJob.get(), &NetJob::succeeded, this, &DownloadTask::fileDownloadFinished); - QObject::connect(netJob.get(), &NetJob::progress, this, &DownloadTask::fileDownloadProgressChanged); - QObject::connect(netJob.get(), &NetJob::failed, this, &DownloadTask::fileDownloadFailed); - - setStatus(tr("Downloading %1 update files.").arg(QString::number(netJob->size()))); - qDebug() << "Begin downloading update files to" << m_updateFilesDir.path(); - m_filesNetJob = netJob; - m_filesNetJob->start(); + VersionFileList m_currentVersionFileList; + VersionFileList m_newVersionFileList; + + setStatus(tr("Reading file list for new version...")); + qDebug() << "Reading file list for new version..."; + QString error; + if (!parseVersionInfo(newVersionFileListData, m_newVersionFileList, error)) + { + qCritical() << error; + emitFailed(error); + return; + } + + // if we have the current version info, use it. + if (m_currentVersionFileListDownload && m_currentVersionFileListDownload->wasSuccessful()) + { + setStatus(tr("Reading file list for current version...")); + qDebug() << "Reading file list for current version..."; + // if this fails, it's not a complete loss. + QString error; + if(!parseVersionInfo( currentVersionFileListData, m_currentVersionFileList, error)) + { + qDebug() << error << "This is not a fatal error."; + } + } + + // We don't need this any more. + m_currentVersionFileListDownload.reset(); + m_newVersionFileListDownload.reset(); + m_vinfoNetJob.reset(); + + setStatus(tr("Processing file lists - figuring out how to install the update...")); + + // make a new netjob for the actual update files + NetJobPtr netJob (new NetJob("Update Files")); + + // fill netJob and operationList + if (!processFileLists(m_currentVersionFileList, m_newVersionFileList, m_status.rootPath, m_updateFilesDir.path(), netJob, m_operations)) + { + emitFailed(tr("Failed to process update lists...")); + return; + } + + // Now start the download. + QObject::connect(netJob.get(), &NetJob::succeeded, this, &DownloadTask::fileDownloadFinished); + QObject::connect(netJob.get(), &NetJob::progress, this, &DownloadTask::fileDownloadProgressChanged); + QObject::connect(netJob.get(), &NetJob::failed, this, &DownloadTask::fileDownloadFailed); + + setStatus(tr("Downloading %1 update files.").arg(QString::number(netJob->size()))); + qDebug() << "Begin downloading update files to" << m_updateFilesDir.path(); + m_filesNetJob = netJob; + m_filesNetJob->start(); } void DownloadTask::fileDownloadFinished() { - emitSucceeded(); + emitSucceeded(); } void DownloadTask::fileDownloadFailed(QString reason) { - qCritical() << "Failed to download update files:" << reason; - emitFailed(tr("Failed to download update files: %1").arg(reason)); + qCritical() << "Failed to download update files:" << reason; + emitFailed(tr("Failed to download update files: %1").arg(reason)); } void DownloadTask::fileDownloadProgressChanged(qint64 current, qint64 total) { - setProgress(current, total); + setProgress(current, total); } QString DownloadTask::updateFilesDir() { - return m_updateFilesDir.path(); + return m_updateFilesDir.path(); } OperationList DownloadTask::operations() { - return m_operations; + return m_operations; } }
\ No newline at end of file diff --git a/api/logic/updater/DownloadTask.h b/api/logic/updater/DownloadTask.h index 8330d3e8..30b4b9ec 100644 --- a/api/logic/updater/DownloadTask.h +++ b/api/logic/updater/DownloadTask.h @@ -29,70 +29,70 @@ namespace GoUpdate */ class MULTIMC_LOGIC_EXPORT DownloadTask : public Task { - Q_OBJECT + Q_OBJECT public: - /** - * Create a download task - * - * target is a template - XXXXXX at the end will be replaced with a random generated string, ensuring uniqueness - */ - explicit DownloadTask(Status status, QString target, QObject* parent = 0); - virtual ~DownloadTask() {}; + /** + * Create a download task + * + * target is a template - XXXXXX at the end will be replaced with a random generated string, ensuring uniqueness + */ + explicit DownloadTask(Status status, QString target, QObject* parent = 0); + virtual ~DownloadTask() {}; - /// Get the directory that will contain the update files. - QString updateFilesDir(); + /// Get the directory that will contain the update files. + QString updateFilesDir(); - /// Get the list of operations that should be done - OperationList operations(); + /// Get the list of operations that should be done + OperationList operations(); - /// set updater download behavior - void setUseLocalUpdater(bool useLocal); + /// set updater download behavior + void setUseLocalUpdater(bool useLocal); protected: - //! Entry point for tasks. - virtual void executeTask() override; - - /*! - * Downloads the version info files from the repository. - * The files for both the current build, and the build that we're updating to need to be downloaded. - * If the current version's info file can't be found, MultiMC will not delete files that - * were removed between versions. It will still replace files that have changed, however. - * Note that although the repository URL for the current version is not given to the update task, - * the task will attempt to look it up in the UpdateChecker's channel list. - * If an error occurs here, the function will call emitFailed and return false. - */ - void loadVersionInfo(); - - NetJobPtr m_vinfoNetJob; - QByteArray currentVersionFileListData; - QByteArray newVersionFileListData; - Net::Download::Ptr m_currentVersionFileListDownload; - Net::Download::Ptr m_newVersionFileListDownload; - - NetJobPtr m_filesNetJob; - - Status m_status; - - OperationList m_operations; - - /*! - * Temporary directory to store update files in. - * This will be set to not auto delete. Task will fail if this fails to be created. - */ - QTemporaryDir m_updateFilesDir; + //! Entry point for tasks. + virtual void executeTask() override; + + /*! + * Downloads the version info files from the repository. + * The files for both the current build, and the build that we're updating to need to be downloaded. + * If the current version's info file can't be found, MultiMC will not delete files that + * were removed between versions. It will still replace files that have changed, however. + * Note that although the repository URL for the current version is not given to the update task, + * the task will attempt to look it up in the UpdateChecker's channel list. + * If an error occurs here, the function will call emitFailed and return false. + */ + void loadVersionInfo(); + + NetJobPtr m_vinfoNetJob; + QByteArray currentVersionFileListData; + QByteArray newVersionFileListData; + Net::Download::Ptr m_currentVersionFileListDownload; + Net::Download::Ptr m_newVersionFileListDownload; + + NetJobPtr m_filesNetJob; + + Status m_status; + + OperationList m_operations; + + /*! + * Temporary directory to store update files in. + * This will be set to not auto delete. Task will fail if this fails to be created. + */ + QTemporaryDir m_updateFilesDir; protected slots: - /*! - * This function is called when version information is finished downloading - * and at least the new file list download succeeded - */ - void processDownloadedVersionInfo(); - void vinfoDownloadFailed(); - - void fileDownloadFinished(); - void fileDownloadFailed(QString reason); - void fileDownloadProgressChanged(qint64 current, qint64 total); + /*! + * This function is called when version information is finished downloading + * and at least the new file list download succeeded + */ + void processDownloadedVersionInfo(); + void vinfoDownloadFailed(); + + void fileDownloadFinished(); + void fileDownloadFailed(QString reason); + void fileDownloadProgressChanged(qint64 current, qint64 total); }; }
\ No newline at end of file diff --git a/api/logic/updater/DownloadTask_test.cpp b/api/logic/updater/DownloadTask_test.cpp index e75c3ffa..531b2527 100644 --- a/api/logic/updater/DownloadTask_test.cpp +++ b/api/logic/updater/DownloadTask_test.cpp @@ -12,11 +12,11 @@ using namespace GoUpdate; FileSourceList encodeBaseFile(const char *suffix) { - auto base = QDir::currentPath(); - QUrl localFile = QUrl::fromLocalFile(base + suffix); - QString localUrlString = localFile.toString(QUrl::FullyEncoded); - auto item = FileSource("http", localUrlString); - return FileSourceList({item}); + auto base = QDir::currentPath(); + QUrl localFile = QUrl::fromLocalFile(base + suffix); + QString localUrlString = localFile.toString(QUrl::FullyEncoded); + auto item = FileSource("http", localUrlString); + return FileSourceList({item}); } Q_DECLARE_METATYPE(VersionFileList) @@ -24,191 +24,191 @@ Q_DECLARE_METATYPE(Operation) QDebug operator<<(QDebug dbg, const FileSource &f) { - dbg.nospace() << "FileSource(type=" << f.type << " url=" << f.url - << " comp=" << f.compressionType << ")"; - return dbg.maybeSpace(); + dbg.nospace() << "FileSource(type=" << f.type << " url=" << f.url + << " comp=" << f.compressionType << ")"; + return dbg.maybeSpace(); } QDebug operator<<(QDebug dbg, const VersionFileEntry &v) { - dbg.nospace() << "VersionFileEntry(path=" << v.path << " mode=" << v.mode - << " md5=" << v.md5 << " sources=" << v.sources << ")"; - return dbg.maybeSpace(); + dbg.nospace() << "VersionFileEntry(path=" << v.path << " mode=" << v.mode + << " md5=" << v.md5 << " sources=" << v.sources << ")"; + return dbg.maybeSpace(); } QDebug operator<<(QDebug dbg, const Operation::Type &t) { - switch (t) - { - case Operation::OP_REPLACE: - dbg << "OP_COPY"; - break; - case Operation::OP_DELETE: - dbg << "OP_DELETE"; - break; - } - return dbg.maybeSpace(); + switch (t) + { + case Operation::OP_REPLACE: + dbg << "OP_COPY"; + break; + case Operation::OP_DELETE: + dbg << "OP_DELETE"; + break; + } + return dbg.maybeSpace(); } QDebug operator<<(QDebug dbg, const Operation &u) { - dbg.nospace() << "Operation(type=" << u.type << " file=" << u.source - << " dest=" << u.destination << " mode=" << u.destinationMode << ")"; - return dbg.maybeSpace(); + dbg.nospace() << "Operation(type=" << u.type << " file=" << u.source + << " dest=" << u.destination << " mode=" << u.destinationMode << ")"; + return dbg.maybeSpace(); } class DownloadTaskTest : public QObject { - Q_OBJECT + Q_OBJECT private slots: - void initTestCase() - { - } - void cleanupTestCase() - { - } - - void test_parseVersionInfo_data() - { - QTest::addColumn<QByteArray>("data"); - QTest::addColumn<VersionFileList>("list"); - QTest::addColumn<QString>("error"); - QTest::addColumn<bool>("ret"); - - QTest::newRow("one") - << MULTIMC_GET_TEST_FILE("data/1.json") - << (VersionFileList() - << VersionFileEntry{"fileOne", - 493, - encodeBaseFile("/data/fileOneA"), - "9eb84090956c484e32cb6c08455a667b"} - << VersionFileEntry{"fileTwo", - 644, - encodeBaseFile("/data/fileTwo"), - "38f94f54fa3eb72b0ea836538c10b043"} - << VersionFileEntry{"fileThree", - 750, - encodeBaseFile("/data/fileThree"), - "f12df554b21e320be6471d7154130e70"}) - << QString() << true; - QTest::newRow("two") - << MULTIMC_GET_TEST_FILE("data/2.json") - << (VersionFileList() - << VersionFileEntry{"fileOne", - 493, - encodeBaseFile("/data/fileOneB"), - "42915a71277c9016668cce7b82c6b577"} - << VersionFileEntry{"fileTwo", - 644, - encodeBaseFile("/data/fileTwo"), - "38f94f54fa3eb72b0ea836538c10b043"}) - << QString() << true; - } - void test_parseVersionInfo() - { - QFETCH(QByteArray, data); - QFETCH(VersionFileList, list); - QFETCH(QString, error); - QFETCH(bool, ret); - - VersionFileList outList; - QString outError; - bool outRet = parseVersionInfo(data, outList, outError); - QCOMPARE(outRet, ret); - QCOMPARE(outList, list); - QCOMPARE(outError, error); - } - - void test_processFileLists_data() - { - QTest::addColumn<QString>("tempFolder"); - QTest::addColumn<VersionFileList>("currentVersion"); - QTest::addColumn<VersionFileList>("newVersion"); - QTest::addColumn<OperationList>("expectedOperations"); - - QTemporaryDir tempFolderObj; - QString tempFolder = tempFolderObj.path(); - // update fileOne, keep fileTwo, remove fileThree - QTest::newRow("test 1") - << tempFolder << (VersionFileList() - << VersionFileEntry{ - "data/fileOne", 493, - FileSourceList() - << FileSource( - "http", "http://host/path/fileOne-1"), - "9eb84090956c484e32cb6c08455a667b"} - << VersionFileEntry{ - "data/fileTwo", 644, - FileSourceList() - << FileSource( - "http", "http://host/path/fileTwo-1"), - "38f94f54fa3eb72b0ea836538c10b043"} - << VersionFileEntry{ - "data/fileThree", 420, - FileSourceList() - << FileSource( - "http", "http://host/path/fileThree-1"), - "f12df554b21e320be6471d7154130e70"}) - << (VersionFileList() - << VersionFileEntry{ - "data/fileOne", 493, - FileSourceList() - << FileSource("http", - "http://host/path/fileOne-2"), - "42915a71277c9016668cce7b82c6b577"} - << VersionFileEntry{ - "data/fileTwo", 644, - FileSourceList() - << FileSource("http", - "http://host/path/fileTwo-2"), - "38f94f54fa3eb72b0ea836538c10b043"}) - << (OperationList() - << Operation::DeleteOp("data/fileThree") - << Operation::CopyOp( - FS::PathCombine(tempFolder, - QString("data/fileOne").replace("/", "_")), - "data/fileOne", 493)); - } - void test_processFileLists() - { - QFETCH(QString, tempFolder); - QFETCH(VersionFileList, currentVersion); - QFETCH(VersionFileList, newVersion); - QFETCH(OperationList, expectedOperations); - - OperationList operations; - - processFileLists(currentVersion, newVersion, QDir::currentPath(), tempFolder, new NetJob("Dummy"), operations); - qDebug() << (operations == expectedOperations); - qDebug() << operations; - qDebug() << expectedOperations; - QCOMPARE(operations, expectedOperations); - } - - void test_OSXPathFixup() - { - QString path, pathOrig; - bool result; - // Proper OSX path - pathOrig = path = "MultiMC.app/Foo/Bar/Baz"; - qDebug() << "Proper OSX path: " << path; - result = fixPathForOSX(path); - QCOMPARE(path, QString("Foo/Bar/Baz")); - QCOMPARE(result, true); - - // Bad OSX path - pathOrig = path = "translations/klingon.lol"; - qDebug() << "Bad OSX path: " << path; - result = fixPathForOSX(path); - QCOMPARE(path, pathOrig); - QCOMPARE(result, false); - } + void initTestCase() + { + } + void cleanupTestCase() + { + } + + void test_parseVersionInfo_data() + { + QTest::addColumn<QByteArray>("data"); + QTest::addColumn<VersionFileList>("list"); + QTest::addColumn<QString>("error"); + QTest::addColumn<bool>("ret"); + + QTest::newRow("one") + << MULTIMC_GET_TEST_FILE("data/1.json") + << (VersionFileList() + << VersionFileEntry{"fileOne", + 493, + encodeBaseFile("/data/fileOneA"), + "9eb84090956c484e32cb6c08455a667b"} + << VersionFileEntry{"fileTwo", + 644, + encodeBaseFile("/data/fileTwo"), + "38f94f54fa3eb72b0ea836538c10b043"} + << VersionFileEntry{"fileThree", + 750, + encodeBaseFile("/data/fileThree"), + "f12df554b21e320be6471d7154130e70"}) + << QString() << true; + QTest::newRow("two") + << MULTIMC_GET_TEST_FILE("data/2.json") + << (VersionFileList() + << VersionFileEntry{"fileOne", + 493, + encodeBaseFile("/data/fileOneB"), + "42915a71277c9016668cce7b82c6b577"} + << VersionFileEntry{"fileTwo", + 644, + encodeBaseFile("/data/fileTwo"), + "38f94f54fa3eb72b0ea836538c10b043"}) + << QString() << true; + } + void test_parseVersionInfo() + { + QFETCH(QByteArray, data); + QFETCH(VersionFileList, list); + QFETCH(QString, error); + QFETCH(bool, ret); + + VersionFileList outList; + QString outError; + bool outRet = parseVersionInfo(data, outList, outError); + QCOMPARE(outRet, ret); + QCOMPARE(outList, list); + QCOMPARE(outError, error); + } + + void test_processFileLists_data() + { + QTest::addColumn<QString>("tempFolder"); + QTest::addColumn<VersionFileList>("currentVersion"); + QTest::addColumn<VersionFileList>("newVersion"); + QTest::addColumn<OperationList>("expectedOperations"); + + QTemporaryDir tempFolderObj; + QString tempFolder = tempFolderObj.path(); + // update fileOne, keep fileTwo, remove fileThree + QTest::newRow("test 1") + << tempFolder << (VersionFileList() + << VersionFileEntry{ + "data/fileOne", 493, + FileSourceList() + << FileSource( + "http", "http://host/path/fileOne-1"), + "9eb84090956c484e32cb6c08455a667b"} + << VersionFileEntry{ + "data/fileTwo", 644, + FileSourceList() + << FileSource( + "http", "http://host/path/fileTwo-1"), + "38f94f54fa3eb72b0ea836538c10b043"} + << VersionFileEntry{ + "data/fileThree", 420, + FileSourceList() + << FileSource( + "http", "http://host/path/fileThree-1"), + "f12df554b21e320be6471d7154130e70"}) + << (VersionFileList() + << VersionFileEntry{ + "data/fileOne", 493, + FileSourceList() + << FileSource("http", + "http://host/path/fileOne-2"), + "42915a71277c9016668cce7b82c6b577"} + << VersionFileEntry{ + "data/fileTwo", 644, + FileSourceList() + << FileSource("http", + "http://host/path/fileTwo-2"), + "38f94f54fa3eb72b0ea836538c10b043"}) + << (OperationList() + << Operation::DeleteOp("data/fileThree") + << Operation::CopyOp( + FS::PathCombine(tempFolder, + QString("data/fileOne").replace("/", "_")), + "data/fileOne", 493)); + } + void test_processFileLists() + { + QFETCH(QString, tempFolder); + QFETCH(VersionFileList, currentVersion); + QFETCH(VersionFileList, newVersion); + QFETCH(OperationList, expectedOperations); + + OperationList operations; + + processFileLists(currentVersion, newVersion, QDir::currentPath(), tempFolder, new NetJob("Dummy"), operations); + qDebug() << (operations == expectedOperations); + qDebug() << operations; + qDebug() << expectedOperations; + QCOMPARE(operations, expectedOperations); + } + + void test_OSXPathFixup() + { + QString path, pathOrig; + bool result; + // Proper OSX path + pathOrig = path = "MultiMC.app/Foo/Bar/Baz"; + qDebug() << "Proper OSX path: " << path; + result = fixPathForOSX(path); + QCOMPARE(path, QString("Foo/Bar/Baz")); + QCOMPARE(result, true); + + // Bad OSX path + pathOrig = path = "translations/klingon.lol"; + qDebug() << "Bad OSX path: " << path; + result = fixPathForOSX(path); + QCOMPARE(path, pathOrig); + QCOMPARE(result, false); + } }; extern "C" { - QTEST_GUILESS_MAIN(DownloadTaskTest) + QTEST_GUILESS_MAIN(DownloadTaskTest) } #include "DownloadTask_test.moc" diff --git a/api/logic/updater/GoUpdate.cpp b/api/logic/updater/GoUpdate.cpp index 716048a0..ef040db6 100644 --- a/api/logic/updater/GoUpdate.cpp +++ b/api/logic/updater/GoUpdate.cpp @@ -12,208 +12,208 @@ namespace GoUpdate bool parseVersionInfo(const QByteArray &data, VersionFileList &list, QString &error) { - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); - if (jsonError.error != QJsonParseError::NoError) - { - error = QString("Failed to parse version info JSON: %1 at %2") - .arg(jsonError.errorString()) - .arg(jsonError.offset); - qCritical() << error; - return false; - } - - QJsonObject json = jsonDoc.object(); - - qDebug() << data; - qDebug() << "Loading version info from JSON."; - QJsonArray filesArray = json.value("Files").toArray(); - for (QJsonValue fileValue : filesArray) - { - QJsonObject fileObj = fileValue.toObject(); - - QString file_path = fileObj.value("Path").toString(); + QJsonParseError jsonError; + QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); + if (jsonError.error != QJsonParseError::NoError) + { + error = QString("Failed to parse version info JSON: %1 at %2") + .arg(jsonError.errorString()) + .arg(jsonError.offset); + qCritical() << error; + return false; + } + + QJsonObject json = jsonDoc.object(); + + qDebug() << data; + qDebug() << "Loading version info from JSON."; + QJsonArray filesArray = json.value("Files").toArray(); + for (QJsonValue fileValue : filesArray) + { + QJsonObject fileObj = fileValue.toObject(); + + QString file_path = fileObj.value("Path").toString(); #ifdef Q_OS_MAC - // On OSX, the paths for the updater need to be fixed. - // basically, anything that isn't in the .app folder is ignored. - // everything else is changed so the code that processes the files actually finds - // them and puts the replacements in the right spots. - fixPathForOSX(file_path); + // On OSX, the paths for the updater need to be fixed. + // basically, anything that isn't in the .app folder is ignored. + // everything else is changed so the code that processes the files actually finds + // them and puts the replacements in the right spots. + fixPathForOSX(file_path); #endif - VersionFileEntry file{file_path, fileObj.value("Perms").toVariant().toInt(), - FileSourceList(), fileObj.value("MD5").toString(), }; - qDebug() << "File" << file.path << "with perms" << file.mode; - - QJsonArray sourceArray = fileObj.value("Sources").toArray(); - for (QJsonValue val : sourceArray) - { - QJsonObject sourceObj = val.toObject(); - - QString type = sourceObj.value("SourceType").toString(); - if (type == "http") - { - file.sources.append(FileSource("http", sourceObj.value("Url").toString())); - } - else - { - qWarning() << "Unknown source type" << type << "ignored."; - } - } - - qDebug() << "Loaded info for" << file.path; - - list.append(file); - } - - return true; + VersionFileEntry file{file_path, fileObj.value("Perms").toVariant().toInt(), + FileSourceList(), fileObj.value("MD5").toString(), }; + qDebug() << "File" << file.path << "with perms" << file.mode; + + QJsonArray sourceArray = fileObj.value("Sources").toArray(); + for (QJsonValue val : sourceArray) + { + QJsonObject sourceObj = val.toObject(); + + QString type = sourceObj.value("SourceType").toString(); + if (type == "http") + { + file.sources.append(FileSource("http", sourceObj.value("Url").toString())); + } + else + { + qWarning() << "Unknown source type" << type << "ignored."; + } + } + + qDebug() << "Loaded info for" << file.path; + + list.append(file); + } + + return true; } bool processFileLists ( - const VersionFileList ¤tVersion, - const VersionFileList &newVersion, - const QString &rootPath, - const QString &tempPath, - NetJobPtr job, - OperationList &ops + const VersionFileList ¤tVersion, + const VersionFileList &newVersion, + const QString &rootPath, + const QString &tempPath, + NetJobPtr job, + OperationList &ops ) { - // First, if we've loaded the current version's file list, we need to iterate through it and - // delete anything in the current one version's list that isn't in the new version's list. - for (VersionFileEntry entry : currentVersion) - { - QFileInfo toDelete(FS::PathCombine(rootPath, entry.path)); - if (!toDelete.exists()) - { - qCritical() << "Expected file " << toDelete.absoluteFilePath() - << " doesn't exist!"; - } - bool keep = false; - - // - for (VersionFileEntry newEntry : newVersion) - { - if (newEntry.path == entry.path) - { - qDebug() << "Not deleting" << entry.path - << "because it is still present in the new version."; - keep = true; - break; - } - } - - // If the loop reaches the end and we didn't find a match, delete the file. - if (!keep) - { - if (toDelete.exists()) - ops.append(Operation::DeleteOp(entry.path)); - } - } - - // Next, check each file in MultiMC's folder and see if we need to update them. - for (VersionFileEntry entry : newVersion) - { - // TODO: Let's not MD5sum a ton of files on the GUI thread. We should probably find a - // way to do this in the background. - QString fileMD5; - QString realEntryPath = FS::PathCombine(rootPath, entry.path); - QFile entryFile(realEntryPath); - QFileInfo entryInfo(realEntryPath); - - bool needs_upgrade = false; - if (!entryFile.exists()) - { - needs_upgrade = true; - } - else - { - bool pass = true; - if (!entryInfo.isReadable()) - { - qCritical() << "File " << realEntryPath << " is not readable."; - pass = false; - } - if (!entryInfo.isWritable()) - { - qCritical() << "File " << realEntryPath << " is not writable."; - pass = false; - } - if (!entryFile.open(QFile::ReadOnly)) - { - qCritical() << "File " << realEntryPath << " cannot be opened for reading."; - pass = false; - } - if (!pass) - { - ops.clear(); - return false; - } - } - - if(!needs_upgrade) - { - QCryptographicHash hash(QCryptographicHash::Md5); - auto foo = entryFile.readAll(); - - hash.addData(foo); - fileMD5 = hash.result().toHex(); - if ((fileMD5 != entry.md5)) - { - qDebug() << "MD5Sum does not match!"; - qDebug() << "Expected:'" << entry.md5 << "'"; - qDebug() << "Got: '" << fileMD5 << "'"; - needs_upgrade = true; - } - } - - // skip file. it doesn't need an upgrade. - if (!needs_upgrade) - { - qDebug() << "File" << realEntryPath << " does not need updating."; - continue; - } - - // yep. this file actually needs an upgrade. PROCEED. - qDebug() << "Found file" << realEntryPath << " that needs updating."; - - // Go through the sources list and find one to use. - // TODO: Make a NetAction that takes a source list and tries each of them until one - // works. For now, we'll just use the first http one. - for (FileSource source : entry.sources) - { - if (source.type != "http") - continue; - - qDebug() << "Will download" << entry.path << "from" << source.url; - - // Download it to updatedir/<filepath>-<md5> where filepath is the file's - // path with slashes replaced by underscores. - QString dlPath = FS::PathCombine(tempPath, QString(entry.path).replace("/", "_")); - - // We need to download the file to the updatefiles folder and add a task - // to copy it to its install path. - auto download = Net::Download::makeFile(source.url, dlPath); - auto rawMd5 = QByteArray::fromHex(entry.md5.toLatin1()); - download->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5)); - job->addNetAction(download); - ops.append(Operation::CopyOp(dlPath, entry.path, entry.mode)); - } - } - return true; + // First, if we've loaded the current version's file list, we need to iterate through it and + // delete anything in the current one version's list that isn't in the new version's list. + for (VersionFileEntry entry : currentVersion) + { + QFileInfo toDelete(FS::PathCombine(rootPath, entry.path)); + if (!toDelete.exists()) + { + qCritical() << "Expected file " << toDelete.absoluteFilePath() + << " doesn't exist!"; + } + bool keep = false; + + // + for (VersionFileEntry newEntry : newVersion) + { + if (newEntry.path == entry.path) + { + qDebug() << "Not deleting" << entry.path + << "because it is still present in the new version."; + keep = true; + break; + } + } + + // If the loop reaches the end and we didn't find a match, delete the file. + if (!keep) + { + if (toDelete.exists()) + ops.append(Operation::DeleteOp(entry.path)); + } + } + + // Next, check each file in MultiMC's folder and see if we need to update them. + for (VersionFileEntry entry : newVersion) + { + // TODO: Let's not MD5sum a ton of files on the GUI thread. We should probably find a + // way to do this in the background. + QString fileMD5; + QString realEntryPath = FS::PathCombine(rootPath, entry.path); + QFile entryFile(realEntryPath); + QFileInfo entryInfo(realEntryPath); + + bool needs_upgrade = false; + if (!entryFile.exists()) + { + needs_upgrade = true; + } + else + { + bool pass = true; + if (!entryInfo.isReadable()) + { + qCritical() << "File " << realEntryPath << " is not readable."; + pass = false; + } + if (!entryInfo.isWritable()) + { + qCritical() << "File " << realEntryPath << " is not writable."; + pass = false; + } + if (!entryFile.open(QFile::ReadOnly)) + { + qCritical() << "File " << realEntryPath << " cannot be opened for reading."; + pass = false; + } + if (!pass) + { + ops.clear(); + return false; + } + } + + if(!needs_upgrade) + { + QCryptographicHash hash(QCryptographicHash::Md5); + auto foo = entryFile.readAll(); + + hash.addData(foo); + fileMD5 = hash.result().toHex(); + if ((fileMD5 != entry.md5)) + { + qDebug() << "MD5Sum does not match!"; + qDebug() << "Expected:'" << entry.md5 << "'"; + qDebug() << "Got: '" << fileMD5 << "'"; + needs_upgrade = true; + } + } + + // skip file. it doesn't need an upgrade. + if (!needs_upgrade) + { + qDebug() << "File" << realEntryPath << " does not need updating."; + continue; + } + + // yep. this file actually needs an upgrade. PROCEED. + qDebug() << "Found file" << realEntryPath << " that needs updating."; + + // Go through the sources list and find one to use. + // TODO: Make a NetAction that takes a source list and tries each of them until one + // works. For now, we'll just use the first http one. + for (FileSource source : entry.sources) + { + if (source.type != "http") + continue; + + qDebug() << "Will download" << entry.path << "from" << source.url; + + // Download it to updatedir/<filepath>-<md5> where filepath is the file's + // path with slashes replaced by underscores. + QString dlPath = FS::PathCombine(tempPath, QString(entry.path).replace("/", "_")); + + // We need to download the file to the updatefiles folder and add a task + // to copy it to its install path. + auto download = Net::Download::makeFile(source.url, dlPath); + auto rawMd5 = QByteArray::fromHex(entry.md5.toLatin1()); + download->addValidator(new Net::ChecksumValidator(QCryptographicHash::Md5, rawMd5)); + job->addNetAction(download); + ops.append(Operation::CopyOp(dlPath, entry.path, entry.mode)); + } + } + return true; } bool fixPathForOSX(QString &path) { - if (path.startsWith("MultiMC.app/")) - { - // remove the prefix and add a new, more appropriate one. - path.remove(0, 12); - return true; - } - else - { - qCritical() << "Update path not within .app: " << path; - return false; - } + if (path.startsWith("MultiMC.app/")) + { + // remove the prefix and add a new, more appropriate one. + path.remove(0, 12); + return true; + } + else + { + qCritical() << "Update path not within .app: " << path; + return false; + } } }
\ No newline at end of file diff --git a/api/logic/updater/GoUpdate.h b/api/logic/updater/GoUpdate.h index 0e183b9f..54559a3c 100644 --- a/api/logic/updater/GoUpdate.h +++ b/api/logic/updater/GoUpdate.h @@ -12,16 +12,16 @@ namespace GoUpdate */ struct MULTIMC_LOGIC_EXPORT Status { - bool updateAvailable = false; + bool updateAvailable = false; - int newVersionId = -1; - QString newRepoUrl; + int newVersionId = -1; + QString newRepoUrl; - int currentVersionId = -1; - QString currentRepoUrl; + int currentVersionId = -1; + QString currentRepoUrl; - // path to the root of the application - QString rootPath; + // path to the root of the application + QString rootPath; }; /** @@ -29,21 +29,21 @@ struct MULTIMC_LOGIC_EXPORT Status */ struct MULTIMC_LOGIC_EXPORT FileSource { - FileSource(QString type, QString url, QString compression="") - { - this->type = type; - this->url = url; - this->compressionType = compression; - } - - bool operator==(const FileSource &f2) const - { - return type == f2.type && url == f2.url && compressionType == f2.compressionType; - } - - QString type; - QString url; - QString compressionType; + FileSource(QString type, QString url, QString compression="") + { + this->type = type; + this->url = url; + this->compressionType = compression; + } + + bool operator==(const FileSource &f2) const + { + return type == f2.type && url == f2.url && compressionType == f2.compressionType; + } + + QString type; + QString url; + QString compressionType; }; typedef QList<FileSource> FileSourceList; @@ -52,14 +52,14 @@ typedef QList<FileSource> FileSourceList; */ struct MULTIMC_LOGIC_EXPORT VersionFileEntry { - QString path; - int mode; - FileSourceList sources; - QString md5; - bool operator==(const VersionFileEntry &v2) const - { - return path == v2.path && mode == v2.mode && sources == v2.sources && md5 == v2.md5; - } + QString path; + int mode; + FileSourceList sources; + QString md5; + bool operator==(const VersionFileEntry &v2) const + { + return path == v2.path && mode == v2.mode && sources == v2.sources && md5 == v2.md5; + } }; typedef QList<VersionFileEntry> VersionFileList; @@ -68,39 +68,39 @@ typedef QList<VersionFileEntry> VersionFileList; */ struct MULTIMC_LOGIC_EXPORT Operation { - static Operation CopyOp(QString from, QString to, int fmode=0644) - { - return Operation{OP_REPLACE, from, to, fmode}; - } - static Operation DeleteOp(QString file) - { - return Operation{OP_DELETE, QString(), file, 0644}; - } - - // FIXME: for some types, some of the other fields are irrelevant! - bool operator==(const Operation &u2) const - { - return type == u2.type && - source == u2.source && - destination == u2.destination && - destinationMode == u2.destinationMode; - } - - //! Specifies the type of operation that this is. - enum Type - { - OP_REPLACE, - OP_DELETE, - } type; - - //! The source file, if any - QString source; - - //! The destination file. - QString destination; - - //! The mode to change the destination file to. - int destinationMode; + static Operation CopyOp(QString from, QString to, int fmode=0644) + { + return Operation{OP_REPLACE, from, to, fmode}; + } + static Operation DeleteOp(QString file) + { + return Operation{OP_DELETE, QString(), file, 0644}; + } + + // FIXME: for some types, some of the other fields are irrelevant! + bool operator==(const Operation &u2) const + { + return type == u2.type && + source == u2.source && + destination == u2.destination && + destinationMode == u2.destinationMode; + } + + //! Specifies the type of operation that this is. + enum Type + { + OP_REPLACE, + OP_DELETE, + } type; + + //! The source file, if any + QString source; + + //! The destination file. + QString destination; + + //! The mode to change the destination file to. + int destinationMode; }; typedef QList<Operation> OperationList; @@ -115,12 +115,12 @@ bool MULTIMC_LOGIC_EXPORT parseVersionInfo(const QByteArray &data, VersionFileLi */ bool MULTIMC_LOGIC_EXPORT processFileLists ( - const VersionFileList ¤tVersion, - const VersionFileList &newVersion, - const QString &rootPath, - const QString &tempPath, - NetJobPtr job, - OperationList &ops + const VersionFileList ¤tVersion, + const VersionFileList &newVersion, + const QString &rootPath, + const QString &tempPath, + NetJobPtr job, + OperationList &ops ); /*! diff --git a/api/logic/updater/UpdateChecker.cpp b/api/logic/updater/UpdateChecker.cpp index d8be2c1a..9e610d52 100644 --- a/api/logic/updater/UpdateChecker.cpp +++ b/api/logic/updater/UpdateChecker.cpp @@ -25,236 +25,236 @@ UpdateChecker::UpdateChecker(QString channelListUrl, QString currentChannel, int currentBuild) { - m_channelListUrl = channelListUrl; - m_currentChannel = currentChannel; - m_currentBuild = currentBuild; + m_channelListUrl = channelListUrl; + m_currentChannel = currentChannel; + m_currentBuild = currentBuild; } QList<UpdateChecker::ChannelListEntry> UpdateChecker::getChannelList() const { - return m_channels; + return m_channels; } bool UpdateChecker::hasChannels() const { - return !m_channels.isEmpty(); + return !m_channels.isEmpty(); } void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate) { - qDebug() << "Checking for updates."; - - // If the channel list hasn't loaded yet, load it and defer checking for updates until - // later. - if (!m_chanListLoaded) - { - qDebug() << "Channel list isn't loaded yet. Loading channel list and deferring " - "update check."; - m_checkUpdateWaiting = true; - m_deferredUpdateChannel = updateChannel; - updateChanList(notifyNoUpdate); - return; - } - - if (m_updateChecking) - { - qDebug() << "Ignoring update check request. Already checking for updates."; - return; - } - - m_updateChecking = true; - - // Find the desired channel within the channel list and get its repo URL. If if cannot be - // found, error. - m_newRepoUrl = ""; - for (ChannelListEntry entry : m_channels) - { - if (entry.id == updateChannel) - m_newRepoUrl = entry.url; - if (entry.id == m_currentChannel) - m_currentRepoUrl = entry.url; - } - - qDebug() << "m_repoUrl = " << m_newRepoUrl; - - // If we didn't find our channel, error. - if (m_newRepoUrl.isEmpty()) - { - qCritical() << "m_repoUrl is empty!"; - emit updateCheckFailed(); - return; - } - - QUrl indexUrl = QUrl(m_newRepoUrl).resolved(QUrl("index.json")); - - auto job = new NetJob("GoUpdate Repository Index"); - job->addNetAction(Net::Download::makeByteArray(indexUrl, &indexData)); - connect(job, &NetJob::succeeded, [this, notifyNoUpdate](){ updateCheckFinished(notifyNoUpdate); }); - connect(job, &NetJob::failed, this, &UpdateChecker::updateCheckFailed); - indexJob.reset(job); - job->start(); + qDebug() << "Checking for updates."; + + // If the channel list hasn't loaded yet, load it and defer checking for updates until + // later. + if (!m_chanListLoaded) + { + qDebug() << "Channel list isn't loaded yet. Loading channel list and deferring " + "update check."; + m_checkUpdateWaiting = true; + m_deferredUpdateChannel = updateChannel; + updateChanList(notifyNoUpdate); + return; + } + + if (m_updateChecking) + { + qDebug() << "Ignoring update check request. Already checking for updates."; + return; + } + + m_updateChecking = true; + + // Find the desired channel within the channel list and get its repo URL. If if cannot be + // found, error. + m_newRepoUrl = ""; + for (ChannelListEntry entry : m_channels) + { + if (entry.id == updateChannel) + m_newRepoUrl = entry.url; + if (entry.id == m_currentChannel) + m_currentRepoUrl = entry.url; + } + + qDebug() << "m_repoUrl = " << m_newRepoUrl; + + // If we didn't find our channel, error. + if (m_newRepoUrl.isEmpty()) + { + qCritical() << "m_repoUrl is empty!"; + emit updateCheckFailed(); + return; + } + + QUrl indexUrl = QUrl(m_newRepoUrl).resolved(QUrl("index.json")); + + auto job = new NetJob("GoUpdate Repository Index"); + job->addNetAction(Net::Download::makeByteArray(indexUrl, &indexData)); + connect(job, &NetJob::succeeded, [this, notifyNoUpdate](){ updateCheckFinished(notifyNoUpdate); }); + connect(job, &NetJob::failed, this, &UpdateChecker::updateCheckFailed); + indexJob.reset(job); + job->start(); } void UpdateChecker::updateCheckFinished(bool notifyNoUpdate) { - qDebug() << "Finished downloading repo index. Checking for new versions."; - - QJsonParseError jsonError; - indexJob.reset(); - - QJsonDocument jsonDoc = QJsonDocument::fromJson(indexData, &jsonError); - indexData.clear(); - if (jsonError.error != QJsonParseError::NoError || !jsonDoc.isObject()) - { - qCritical() << "Failed to parse GoUpdate repository index. JSON error" - << jsonError.errorString() << "at offset" << jsonError.offset; - m_updateChecking = false; - return; - } - - QJsonObject object = jsonDoc.object(); - - bool success = false; - int apiVersion = object.value("ApiVersion").toVariant().toInt(&success); - if (apiVersion != API_VERSION || !success) - { - qCritical() << "Failed to check for updates. API version mismatch. We're using" - << API_VERSION << "server has" << apiVersion; - m_updateChecking = false; - return; - } - - qDebug() << "Processing repository version list."; - QJsonObject newestVersion; - QJsonArray versions = object.value("Versions").toArray(); - for (QJsonValue versionVal : versions) - { - QJsonObject version = versionVal.toObject(); - if (newestVersion.value("Id").toVariant().toInt() < - version.value("Id").toVariant().toInt()) - { - newestVersion = version; - } - } - - // We've got the version with the greatest ID number. Now compare it to our current build - // number and update if they're different. - int newBuildNumber = newestVersion.value("Id").toVariant().toInt(); - if (newBuildNumber != m_currentBuild) - { - qDebug() << "Found newer version with ID" << newBuildNumber; - // Update! - GoUpdate::Status updateStatus; - updateStatus.updateAvailable = true; - updateStatus.currentVersionId = m_currentBuild; - updateStatus.currentRepoUrl = m_currentRepoUrl; - updateStatus.newVersionId = newBuildNumber; - updateStatus.newRepoUrl = m_newRepoUrl; - emit updateAvailable(updateStatus); - } - else if (notifyNoUpdate) - { - emit noUpdateFound(); - } - m_updateChecking = false; + qDebug() << "Finished downloading repo index. Checking for new versions."; + + QJsonParseError jsonError; + indexJob.reset(); + + QJsonDocument jsonDoc = QJsonDocument::fromJson(indexData, &jsonError); + indexData.clear(); + if (jsonError.error != QJsonParseError::NoError || !jsonDoc.isObject()) + { + qCritical() << "Failed to parse GoUpdate repository index. JSON error" + << jsonError.errorString() << "at offset" << jsonError.offset; + m_updateChecking = false; + return; + } + + QJsonObject object = jsonDoc.object(); + + bool success = false; + int apiVersion = object.value("ApiVersion").toVariant().toInt(&success); + if (apiVersion != API_VERSION || !success) + { + qCritical() << "Failed to check for updates. API version mismatch. We're using" + << API_VERSION << "server has" << apiVersion; + m_updateChecking = false; + return; + } + + qDebug() << "Processing repository version list."; + QJsonObject newestVersion; + QJsonArray versions = object.value("Versions").toArray(); + for (QJsonValue versionVal : versions) + { + QJsonObject version = versionVal.toObject(); + if (newestVersion.value("Id").toVariant().toInt() < + version.value("Id").toVariant().toInt()) + { + newestVersion = version; + } + } + + // We've got the version with the greatest ID number. Now compare it to our current build + // number and update if they're different. + int newBuildNumber = newestVersion.value("Id").toVariant().toInt(); + if (newBuildNumber != m_currentBuild) + { + qDebug() << "Found newer version with ID" << newBuildNumber; + // Update! + GoUpdate::Status updateStatus; + updateStatus.updateAvailable = true; + updateStatus.currentVersionId = m_currentBuild; + updateStatus.currentRepoUrl = m_currentRepoUrl; + updateStatus.newVersionId = newBuildNumber; + updateStatus.newRepoUrl = m_newRepoUrl; + emit updateAvailable(updateStatus); + } + else if (notifyNoUpdate) + { + emit noUpdateFound(); + } + m_updateChecking = false; } void UpdateChecker::updateCheckFailed() { - qCritical() << "Update check failed for reasons unknown."; + qCritical() << "Update check failed for reasons unknown."; } void UpdateChecker::updateChanList(bool notifyNoUpdate) { - qDebug() << "Loading the channel list."; - - if (m_chanListLoading) - { - qDebug() << "Ignoring channel list update request. Already grabbing channel list."; - return; - } - - if (m_channelListUrl.isEmpty()) - { - qCritical() << "Failed to update channel list. No channel list URL set." - << "If you'd like to use MultiMC's update system, please pass the channel " - "list URL to CMake at compile time."; - return; - } - - m_chanListLoading = true; - NetJob *job = new NetJob("Update System Channel List"); - job->addNetAction(Net::Download::makeByteArray(QUrl(m_channelListUrl), &chanlistData)); - connect(job, &NetJob::succeeded, [this, notifyNoUpdate]() { chanListDownloadFinished(notifyNoUpdate); }); - QObject::connect(job, &NetJob::failed, this, &UpdateChecker::chanListDownloadFailed); - chanListJob.reset(job); - job->start(); + qDebug() << "Loading the channel list."; + + if (m_chanListLoading) + { + qDebug() << "Ignoring channel list update request. Already grabbing channel list."; + return; + } + + if (m_channelListUrl.isEmpty()) + { + qCritical() << "Failed to update channel list. No channel list URL set." + << "If you'd like to use MultiMC's update system, please pass the channel " + "list URL to CMake at compile time."; + return; + } + + m_chanListLoading = true; + NetJob *job = new NetJob("Update System Channel List"); + job->addNetAction(Net::Download::makeByteArray(QUrl(m_channelListUrl), &chanlistData)); + connect(job, &NetJob::succeeded, [this, notifyNoUpdate]() { chanListDownloadFinished(notifyNoUpdate); }); + QObject::connect(job, &NetJob::failed, this, &UpdateChecker::chanListDownloadFailed); + chanListJob.reset(job); + job->start(); } void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate) { - chanListJob.reset(); - - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(chanlistData, &jsonError); - chanlistData.clear(); - if (jsonError.error != QJsonParseError::NoError) - { - // TODO: Report errors to the user. - qCritical() << "Failed to parse channel list JSON:" << jsonError.errorString() << "at" << jsonError.offset; - m_chanListLoading = false; - return; - } - - QJsonObject object = jsonDoc.object(); - - bool success = false; - int formatVersion = object.value("format_version").toVariant().toInt(&success); - if (formatVersion != CHANLIST_FORMAT || !success) - { - qCritical() - << "Failed to check for updates. Channel list format version mismatch. We're using" - << CHANLIST_FORMAT << "server has" << formatVersion; - m_chanListLoading = false; - return; - } - - // Load channels into a temporary array. - QList<ChannelListEntry> loadedChannels; - QJsonArray channelArray = object.value("channels").toArray(); - for (QJsonValue chanVal : channelArray) - { - QJsonObject channelObj = chanVal.toObject(); - ChannelListEntry entry{channelObj.value("id").toVariant().toString(), - channelObj.value("name").toVariant().toString(), - channelObj.value("description").toVariant().toString(), - channelObj.value("url").toVariant().toString()}; - if (entry.id.isEmpty() || entry.name.isEmpty() || entry.url.isEmpty()) - { - qCritical() << "Channel list entry with empty ID, name, or URL. Skipping."; - continue; - } - loadedChannels.append(entry); - } - - // Swap the channel list we just loaded into the object's channel list. - m_channels.swap(loadedChannels); - - m_chanListLoading = false; - m_chanListLoaded = true; - qDebug() << "Successfully loaded UpdateChecker channel list."; - - // If we're waiting to check for updates, do that now. - if (m_checkUpdateWaiting) - checkForUpdate(m_deferredUpdateChannel, notifyNoUpdate); - - emit channelListLoaded(); + chanListJob.reset(); + + QJsonParseError jsonError; + QJsonDocument jsonDoc = QJsonDocument::fromJson(chanlistData, &jsonError); + chanlistData.clear(); + if (jsonError.error != QJsonParseError::NoError) + { + // TODO: Report errors to the user. + qCritical() << "Failed to parse channel list JSON:" << jsonError.errorString() << "at" << jsonError.offset; + m_chanListLoading = false; + return; + } + + QJsonObject object = jsonDoc.object(); + + bool success = false; + int formatVersion = object.value("format_version").toVariant().toInt(&success); + if (formatVersion != CHANLIST_FORMAT || !success) + { + qCritical() + << "Failed to check for updates. Channel list format version mismatch. We're using" + << CHANLIST_FORMAT << "server has" << formatVersion; + m_chanListLoading = false; + return; + } + + // Load channels into a temporary array. + QList<ChannelListEntry> loadedChannels; + QJsonArray channelArray = object.value("channels").toArray(); + for (QJsonValue chanVal : channelArray) + { + QJsonObject channelObj = chanVal.toObject(); + ChannelListEntry entry{channelObj.value("id").toVariant().toString(), + channelObj.value("name").toVariant().toString(), + channelObj.value("description").toVariant().toString(), + channelObj.value("url").toVariant().toString()}; + if (entry.id.isEmpty() || entry.name.isEmpty() || entry.url.isEmpty()) + { + qCritical() << "Channel list entry with empty ID, name, or URL. Skipping."; + continue; + } + loadedChannels.append(entry); + } + + // Swap the channel list we just loaded into the object's channel list. + m_channels.swap(loadedChannels); + + m_chanListLoading = false; + m_chanListLoaded = true; + qDebug() << "Successfully loaded UpdateChecker channel list."; + + // If we're waiting to check for updates, do that now. + if (m_checkUpdateWaiting) + checkForUpdate(m_deferredUpdateChannel, notifyNoUpdate); + + emit channelListLoaded(); } void UpdateChecker::chanListDownloadFailed(QString reason) { - m_chanListLoading = false; - qCritical() << QString("Failed to download channel list: %1").arg(reason); - emit channelListLoaded(); + m_chanListLoading = false; + qCritical() << QString("Failed to download channel list: %1").arg(reason); + emit channelListLoaded(); } diff --git a/api/logic/updater/UpdateChecker.h b/api/logic/updater/UpdateChecker.h index 4996da26..bb5013de 100644 --- a/api/logic/updater/UpdateChecker.h +++ b/api/logic/updater/UpdateChecker.h @@ -22,100 +22,100 @@ class MULTIMC_LOGIC_EXPORT UpdateChecker : public QObject { - Q_OBJECT + Q_OBJECT public: - UpdateChecker(QString channelListUrl, QString currentChannel, int currentBuild); - void checkForUpdate(QString updateChannel, bool notifyNoUpdate); - - /*! - * Causes the update checker to download the channel list from the URL specified in config.h (generated by CMake). - * If this isn't called before checkForUpdate(), it will automatically be called. - */ - void updateChanList(bool notifyNoUpdate); - - /*! - * An entry in the channel list. - */ - struct ChannelListEntry - { - QString id; - QString name; - QString description; - QString url; - }; - - /*! - * Returns a the current channel list. - * If the channel list hasn't been loaded, this list will be empty. - */ - QList<ChannelListEntry> getChannelList() const; - - /*! - * Returns false if the channel list is empty. - */ - bool hasChannels() const; + UpdateChecker(QString channelListUrl, QString currentChannel, int currentBuild); + void checkForUpdate(QString updateChannel, bool notifyNoUpdate); + + /*! + * Causes the update checker to download the channel list from the URL specified in config.h (generated by CMake). + * If this isn't called before checkForUpdate(), it will automatically be called. + */ + void updateChanList(bool notifyNoUpdate); + + /*! + * An entry in the channel list. + */ + struct ChannelListEntry + { + QString id; + QString name; + QString description; + QString url; + }; + + /*! + * Returns a the current channel list. + * If the channel list hasn't been loaded, this list will be empty. + */ + QList<ChannelListEntry> getChannelList() const; + + /*! + * Returns false if the channel list is empty. + */ + bool hasChannels() const; signals: - //! Signal emitted when an update is available. Passes the URL for the repo and the ID and name for the version. - void updateAvailable(GoUpdate::Status status); + //! Signal emitted when an update is available. Passes the URL for the repo and the ID and name for the version. + void updateAvailable(GoUpdate::Status status); - //! Signal emitted when the channel list finishes loading or fails to load. - void channelListLoaded(); + //! Signal emitted when the channel list finishes loading or fails to load. + void channelListLoaded(); - void noUpdateFound(); + void noUpdateFound(); private slots: - void updateCheckFinished(bool notifyNoUpdate); - void updateCheckFailed(); + void updateCheckFinished(bool notifyNoUpdate); + void updateCheckFailed(); - void chanListDownloadFinished(bool notifyNoUpdate); - void chanListDownloadFailed(QString reason); + void chanListDownloadFinished(bool notifyNoUpdate); + void chanListDownloadFailed(QString reason); private: - friend class UpdateCheckerTest; - - NetJobPtr indexJob; - QByteArray indexData; - NetJobPtr chanListJob; - QByteArray chanlistData; - - QString m_channelListUrl; - - QList<ChannelListEntry> m_channels; - - /*! - * True while the system is checking for updates. - * If checkForUpdate is called while this is true, it will be ignored. - */ - bool m_updateChecking = false; - - /*! - * True if the channel list has loaded. - * If this is false, trying to check for updates will call updateChanList first. - */ - bool m_chanListLoaded = false; - - /*! - * Set to true while the channel list is currently loading. - */ - bool m_chanListLoading = false; - - /*! - * Set to true when checkForUpdate is called while the channel list isn't loaded. - * When the channel list finishes loading, if this is true, the update checker will check for updates. - */ - bool m_checkUpdateWaiting = false; - - /*! - * if m_checkUpdateWaiting, this is the last used update channel - */ - QString m_deferredUpdateChannel; - - int m_currentBuild = -1; - QString m_currentChannel; - QString m_currentRepoUrl; - - QString m_newRepoUrl; + friend class UpdateCheckerTest; + + NetJobPtr indexJob; + QByteArray indexData; + NetJobPtr chanListJob; + QByteArray chanlistData; + + QString m_channelListUrl; + + QList<ChannelListEntry> m_channels; + + /*! + * True while the system is checking for updates. + * If checkForUpdate is called while this is true, it will be ignored. + */ + bool m_updateChecking = false; + + /*! + * True if the channel list has loaded. + * If this is false, trying to check for updates will call updateChanList first. + */ + bool m_chanListLoaded = false; + + /*! + * Set to true while the channel list is currently loading. + */ + bool m_chanListLoading = false; + + /*! + * Set to true when checkForUpdate is called while the channel list isn't loaded. + * When the channel list finishes loading, if this is true, the update checker will check for updates. + */ + bool m_checkUpdateWaiting = false; + + /*! + * if m_checkUpdateWaiting, this is the last used update channel + */ + QString m_deferredUpdateChannel; + + int m_currentBuild = -1; + QString m_currentChannel; + QString m_currentRepoUrl; + + QString m_newRepoUrl; }; diff --git a/api/logic/updater/UpdateChecker_test.cpp b/api/logic/updater/UpdateChecker_test.cpp index 16b21614..59f2a5a1 100644 --- a/api/logic/updater/UpdateChecker_test.cpp +++ b/api/logic/updater/UpdateChecker_test.cpp @@ -8,137 +8,137 @@ Q_DECLARE_METATYPE(UpdateChecker::ChannelListEntry) bool operator==(const UpdateChecker::ChannelListEntry &e1, const UpdateChecker::ChannelListEntry &e2) { - qDebug() << e1.url << "vs" << e2.url; - return e1.id == e2.id && - e1.name == e2.name && - e1.description == e2.description && - e1.url == e2.url; + qDebug() << e1.url << "vs" << e2.url; + return e1.id == e2.id && + e1.name == e2.name && + e1.description == e2.description && + e1.url == e2.url; } QDebug operator<<(QDebug dbg, const UpdateChecker::ChannelListEntry &c) { - dbg.nospace() << "ChannelListEntry(id=" << c.id << " name=" << c.name << " description=" << c.description << " url=" << c.url << ")"; - return dbg.maybeSpace(); + dbg.nospace() << "ChannelListEntry(id=" << c.id << " name=" << c.name << " description=" << c.description << " url=" << c.url << ")"; + return dbg.maybeSpace(); } class UpdateCheckerTest : public QObject { - Q_OBJECT + Q_OBJECT private slots: - void initTestCase() - { - - } - void cleanupTestCase() - { - - } - - static QString findTestDataUrl(const char *file) - { - return QUrl::fromLocalFile(QFINDTESTDATA(file)).toString(); - } - void tst_ChannelListParsing_data() - { - QTest::addColumn<QString>("channel"); - QTest::addColumn<QString>("channelUrl"); - QTest::addColumn<bool>("hasChannels"); - QTest::addColumn<bool>("valid"); - QTest::addColumn<QList<UpdateChecker::ChannelListEntry> >("result"); - - QTest::newRow("garbage") - << QString() - << findTestDataUrl("data/garbageChannels.json") - << false - << false - << QList<UpdateChecker::ChannelListEntry>(); - QTest::newRow("errors") - << QString() - << findTestDataUrl("data/errorChannels.json") - << false - << true - << QList<UpdateChecker::ChannelListEntry>(); - QTest::newRow("no channels") - << QString() - << findTestDataUrl("data/noChannels.json") - << false - << true - << QList<UpdateChecker::ChannelListEntry>(); - QTest::newRow("one channel") - << QString("develop") - << findTestDataUrl("data/oneChannel.json") - << true - << true - << (QList<UpdateChecker::ChannelListEntry>() << UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", "http://example.org/stuff"}); - QTest::newRow("several channels") - << QString("develop") - << findTestDataUrl("data/channels.json") - << true - << true - << (QList<UpdateChecker::ChannelListEntry>() - << UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", findTestDataUrl("data")} - << UpdateChecker::ChannelListEntry{"stable", "Stable", "It's stable at least", findTestDataUrl("data")} - << UpdateChecker::ChannelListEntry{"42", "The Channel", "This is the channel that is going to answer all of your questions", "https://dent.me/tea"}); - } - void tst_ChannelListParsing() - { - - QFETCH(QString, channel); - QFETCH(QString, channelUrl); - QFETCH(bool, hasChannels); - QFETCH(bool, valid); - QFETCH(QList<UpdateChecker::ChannelListEntry>, result); - - UpdateChecker checker(channelUrl, channel, 0); - - QSignalSpy channelListLoadedSpy(&checker, SIGNAL(channelListLoaded())); - QVERIFY(channelListLoadedSpy.isValid()); - - checker.updateChanList(false); - - if (valid) - { - QVERIFY(channelListLoadedSpy.wait()); - QCOMPARE(channelListLoadedSpy.size(), 1); - } - else - { - channelListLoadedSpy.wait(); - QCOMPARE(channelListLoadedSpy.size(), 0); - } - - QCOMPARE(checker.hasChannels(), hasChannels); - QCOMPARE(checker.getChannelList(), result); - } - - void tst_UpdateChecking() - { - QString channel = "develop"; - QString channelUrl = findTestDataUrl("data/channels.json"); - int currentBuild = 2; - - UpdateChecker checker(channelUrl, channel, currentBuild); - - QSignalSpy updateAvailableSpy(&checker, SIGNAL(updateAvailable(GoUpdate::Status))); - QVERIFY(updateAvailableSpy.isValid()); - QSignalSpy channelListLoadedSpy(&checker, SIGNAL(channelListLoaded())); - QVERIFY(channelListLoadedSpy.isValid()); - - checker.updateChanList(false); - QVERIFY(channelListLoadedSpy.wait()); - - qDebug() << "CWD:" << QDir::current().absolutePath(); - checker.m_channels[0].url = findTestDataUrl("data/"); - checker.checkForUpdate(channel, false); - - QVERIFY(updateAvailableSpy.wait()); - - auto status = updateAvailableSpy.first().first().value<GoUpdate::Status>(); - QCOMPARE(checker.m_channels[0].url, status.newRepoUrl); - QCOMPARE(3, status.newVersionId); - QCOMPARE(currentBuild, status.currentVersionId); - } + void initTestCase() + { + + } + void cleanupTestCase() + { + + } + + static QString findTestDataUrl(const char *file) + { + return QUrl::fromLocalFile(QFINDTESTDATA(file)).toString(); + } + void tst_ChannelListParsing_data() + { + QTest::addColumn<QString>("channel"); + QTest::addColumn<QString>("channelUrl"); + QTest::addColumn<bool>("hasChannels"); + QTest::addColumn<bool>("valid"); + QTest::addColumn<QList<UpdateChecker::ChannelListEntry> >("result"); + + QTest::newRow("garbage") + << QString() + << findTestDataUrl("data/garbageChannels.json") + << false + << false + << QList<UpdateChecker::ChannelListEntry>(); + QTest::newRow("errors") + << QString() + << findTestDataUrl("data/errorChannels.json") + << false + << true + << QList<UpdateChecker::ChannelListEntry>(); + QTest::newRow("no channels") + << QString() + << findTestDataUrl("data/noChannels.json") + << false + << true + << QList<UpdateChecker::ChannelListEntry>(); + QTest::newRow("one channel") + << QString("develop") + << findTestDataUrl("data/oneChannel.json") + << true + << true + << (QList<UpdateChecker::ChannelListEntry>() << UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", "http://example.org/stuff"}); + QTest::newRow("several channels") + << QString("develop") + << findTestDataUrl("data/channels.json") + << true + << true + << (QList<UpdateChecker::ChannelListEntry>() + << UpdateChecker::ChannelListEntry{"develop", "Develop", "The channel called \"develop\"", findTestDataUrl("data")} + << UpdateChecker::ChannelListEntry{"stable", "Stable", "It's stable at least", findTestDataUrl("data")} + << UpdateChecker::ChannelListEntry{"42", "The Channel", "This is the channel that is going to answer all of your questions", "https://dent.me/tea"}); + } + void tst_ChannelListParsing() + { + + QFETCH(QString, channel); + QFETCH(QString, channelUrl); + QFETCH(bool, hasChannels); + QFETCH(bool, valid); + QFETCH(QList<UpdateChecker::ChannelListEntry>, result); + + UpdateChecker checker(channelUrl, channel, 0); + + QSignalSpy channelListLoadedSpy(&checker, SIGNAL(channelListLoaded())); + QVERIFY(channelListLoadedSpy.isValid()); + + checker.updateChanList(false); + + if (valid) + { + QVERIFY(channelListLoadedSpy.wait()); + QCOMPARE(channelListLoadedSpy.size(), 1); + } + else + { + channelListLoadedSpy.wait(); + QCOMPARE(channelListLoadedSpy.size(), 0); + } + + QCOMPARE(checker.hasChannels(), hasChannels); + QCOMPARE(checker.getChannelList(), result); + } + + void tst_UpdateChecking() + { + QString channel = "develop"; + QString channelUrl = findTestDataUrl("data/channels.json"); + int currentBuild = 2; + + UpdateChecker checker(channelUrl, channel, currentBuild); + + QSignalSpy updateAvailableSpy(&checker, SIGNAL(updateAvailable(GoUpdate::Status))); + QVERIFY(updateAvailableSpy.isValid()); + QSignalSpy channelListLoadedSpy(&checker, SIGNAL(channelListLoaded())); + QVERIFY(channelListLoadedSpy.isValid()); + + checker.updateChanList(false); + QVERIFY(channelListLoadedSpy.wait()); + + qDebug() << "CWD:" << QDir::current().absolutePath(); + checker.m_channels[0].url = findTestDataUrl("data/"); + checker.checkForUpdate(channel, false); + + QVERIFY(updateAvailableSpy.wait()); + + auto status = updateAvailableSpy.first().first().value<GoUpdate::Status>(); + QCOMPARE(checker.m_channels[0].url, status.newRepoUrl); + QCOMPARE(3, status.newVersionId); + QCOMPARE(currentBuild, status.currentVersionId); + } }; QTEST_GUILESS_MAIN(UpdateCheckerTest) diff --git a/api/logic/updater/testdata/1.json b/api/logic/updater/testdata/1.json index 3dd189e5..7af7e52d 100644 --- a/api/logic/updater/testdata/1.json +++ b/api/logic/updater/testdata/1.json @@ -1,43 +1,43 @@ { - "ApiVersion": 0, - "Id": 1, - "Name": "1.0.1", - "Files": [ - { - "Path": "fileOne", - "Sources": [ - { - "SourceType": "http", - "Url": "@TEST_DATA_URL@/fileOneA" - } - ], - "Executable": true, - "Perms": 493, - "MD5": "9eb84090956c484e32cb6c08455a667b" - }, - { - "Path": "fileTwo", - "Sources": [ - { - "SourceType": "http", - "Url": "@TEST_DATA_URL@/fileTwo" - } - ], - "Executable": false, - "Perms": 644, - "MD5": "38f94f54fa3eb72b0ea836538c10b043" - }, - { - "Path": "fileThree", - "Sources": [ - { - "SourceType": "http", - "Url": "@TEST_DATA_URL@/fileThree" - } - ], - "Executable": false, - "Perms": "750", - "MD5": "f12df554b21e320be6471d7154130e70" - } - ] + "ApiVersion": 0, + "Id": 1, + "Name": "1.0.1", + "Files": [ + { + "Path": "fileOne", + "Sources": [ + { + "SourceType": "http", + "Url": "@TEST_DATA_URL@/fileOneA" + } + ], + "Executable": true, + "Perms": 493, + "MD5": "9eb84090956c484e32cb6c08455a667b" + }, + { + "Path": "fileTwo", + "Sources": [ + { + "SourceType": "http", + "Url": "@TEST_DATA_URL@/fileTwo" + } + ], + "Executable": false, + "Perms": 644, + "MD5": "38f94f54fa3eb72b0ea836538c10b043" + }, + { + "Path": "fileThree", + "Sources": [ + { + "SourceType": "http", + "Url": "@TEST_DATA_URL@/fileThree" + } + ], + "Executable": false, + "Perms": "750", + "MD5": "f12df554b21e320be6471d7154130e70" + } + ] } diff --git a/api/logic/updater/testdata/2.json b/api/logic/updater/testdata/2.json index a7ba7029..96d430d5 100644 --- a/api/logic/updater/testdata/2.json +++ b/api/logic/updater/testdata/2.json @@ -1,31 +1,31 @@ { - "ApiVersion": 0, - "Id": 1, - "Name": "1.0.1", - "Files": [ - { - "Path": "fileOne", - "Sources": [ - { - "SourceType": "http", - "Url": "@TEST_DATA_URL@/fileOneB" - } - ], - "Executable": true, - "Perms": 493, - "MD5": "42915a71277c9016668cce7b82c6b577" - }, - { - "Path": "fileTwo", - "Sources": [ - { - "SourceType": "http", - "Url": "@TEST_DATA_URL@/fileTwo" - } - ], - "Executable": false, - "Perms": 644, - "MD5": "38f94f54fa3eb72b0ea836538c10b043" - } - ] + "ApiVersion": 0, + "Id": 1, + "Name": "1.0.1", + "Files": [ + { + "Path": "fileOne", + "Sources": [ + { + "SourceType": "http", + "Url": "@TEST_DATA_URL@/fileOneB" + } + ], + "Executable": true, + "Perms": 493, + "MD5": "42915a71277c9016668cce7b82c6b577" + }, + { + "Path": "fileTwo", + "Sources": [ + { + "SourceType": "http", + "Url": "@TEST_DATA_URL@/fileTwo" + } + ], + "Executable": false, + "Perms": 644, + "MD5": "38f94f54fa3eb72b0ea836538c10b043" + } + ] } diff --git a/api/logic/updater/testdata/channels.json b/api/logic/updater/testdata/channels.json index b46c64c8..5c6e42cb 100644 --- a/api/logic/updater/testdata/channels.json +++ b/api/logic/updater/testdata/channels.json @@ -1,23 +1,23 @@ { - "format_version": 0, - "channels": [ - { - "id": "develop", - "name": "Develop", - "description": "The channel called \"develop\"", - "url": "@TEST_DATA_URL@" - }, - { - "id": "stable", - "name": "Stable", - "description": "It's stable at least", - "url": "@TEST_DATA_URL@" - }, - { - "id": "42", - "name": "The Channel", - "description": "This is the channel that is going to answer all of your questions", - "url": "https://dent.me/tea" - } - ] + "format_version": 0, + "channels": [ + { + "id": "develop", + "name": "Develop", + "description": "The channel called \"develop\"", + "url": "@TEST_DATA_URL@" + }, + { + "id": "stable", + "name": "Stable", + "description": "It's stable at least", + "url": "@TEST_DATA_URL@" + }, + { + "id": "42", + "name": "The Channel", + "description": "This is the channel that is going to answer all of your questions", + "url": "https://dent.me/tea" + } + ] } diff --git a/api/logic/updater/testdata/errorChannels.json b/api/logic/updater/testdata/errorChannels.json index 333cd445..a2cb2165 100644 --- a/api/logic/updater/testdata/errorChannels.json +++ b/api/logic/updater/testdata/errorChannels.json @@ -1,23 +1,23 @@ { - "format_version": 0, - "channels": [ - { - "id": "", - "name": "Develop", - "description": "The channel called \"develop\"", - "url": "http://example.org/stuff" - }, - { - "id": "stable", - "name": "", - "description": "It's stable at least", - "url": "ftp://username@host/path/to/stuff" - }, - { - "id": "42", - "name": "The Channel", - "description": "This is the channel that is going to answer all of your questions", - "url": "" - } - ] + "format_version": 0, + "channels": [ + { + "id": "", + "name": "Develop", + "description": "The channel called \"develop\"", + "url": "http://example.org/stuff" + }, + { + "id": "stable", + "name": "", + "description": "It's stable at least", + "url": "ftp://username@host/path/to/stuff" + }, + { + "id": "42", + "name": "The Channel", + "description": "This is the channel that is going to answer all of your questions", + "url": "" + } + ] } diff --git a/api/logic/updater/testdata/garbageChannels.json b/api/logic/updater/testdata/garbageChannels.json index 1450fb9c..34437451 100644 --- a/api/logic/updater/testdata/garbageChannels.json +++ b/api/logic/updater/testdata/garbageChannels.json @@ -1,22 +1,22 @@ { - "format_version": 0, - "channels": [ - { - "id": "develop", - "name": "Develop", - "description": "The channel called \"develop\"", -aa "url": "http://example.org/stuff" - }, -a "id": "stable", - "name": "Stable", - "description": "It's stable at least", - "url": "ftp://username@host/path/to/stuff" - }, - { - "id": "42"f - "name": "The Channel", - "description": "This is the channel that is going to answer all of your questions", - "url": "https://dent.me/tea" - } - ] + "format_version": 0, + "channels": [ + { + "id": "develop", + "name": "Develop", + "description": "The channel called \"develop\"", +aa "url": "http://example.org/stuff" + }, +a "id": "stable", + "name": "Stable", + "description": "It's stable at least", + "url": "ftp://username@host/path/to/stuff" + }, + { + "id": "42"f + "name": "The Channel", + "description": "This is the channel that is going to answer all of your questions", + "url": "https://dent.me/tea" + } + ] } diff --git a/api/logic/updater/testdata/index.json b/api/logic/updater/testdata/index.json index 20ceb9f4..867bdcfb 100644 --- a/api/logic/updater/testdata/index.json +++ b/api/logic/updater/testdata/index.json @@ -1,9 +1,9 @@ { - "ApiVersion": 0, - "Versions": [ - { "Id": 0, "Name": "1.0.0" }, - { "Id": 1, "Name": "1.0.1" }, - { "Id": 2, "Name": "1.0.2" }, - { "Id": 3, "Name": "1.0.3" } - ] + "ApiVersion": 0, + "Versions": [ + { "Id": 0, "Name": "1.0.0" }, + { "Id": 1, "Name": "1.0.1" }, + { "Id": 2, "Name": "1.0.2" }, + { "Id": 3, "Name": "1.0.3" } + ] } diff --git a/api/logic/updater/testdata/noChannels.json b/api/logic/updater/testdata/noChannels.json index bbb2cb70..76988982 100644 --- a/api/logic/updater/testdata/noChannels.json +++ b/api/logic/updater/testdata/noChannels.json @@ -1,5 +1,5 @@ { - "format_version": 0, - "channels": [ - ] + "format_version": 0, + "channels": [ + ] } diff --git a/api/logic/updater/testdata/oneChannel.json b/api/logic/updater/testdata/oneChannel.json index 84727ac7..cc8ed255 100644 --- a/api/logic/updater/testdata/oneChannel.json +++ b/api/logic/updater/testdata/oneChannel.json @@ -1,11 +1,11 @@ { - "format_version": 0, - "channels": [ - { - "id": "develop", - "name": "Develop", - "description": "The channel called \"develop\"", - "url": "http://example.org/stuff" - } - ] + "format_version": 0, + "channels": [ + { + "id": "develop", + "name": "Develop", + "description": "The channel called \"develop\"", + "url": "http://example.org/stuff" + } + ] } |