all repos — mgba @ 322828737f4334f20d1596b3006fa2619996e91d

mGBA Game Boy Advance Emulator

src/platform/qt/BattleChipUpdater.cpp (view raw)

 1/* Copyright (c) 2013-2019 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "BattleChipUpdater.h"
 7
 8#include "ConfigController.h"
 9#include "GBAApp.h"
10
11#include <QFileInfo>
12#include <QJsonArray>
13#include <QJsonDocument>
14#include <QJsonObject>
15
16using namespace QGBA;
17
18BattleChipUpdater::BattleChipUpdater(QObject* parent)
19	: AbstractUpdater(parent)
20{
21}
22
23QUrl BattleChipUpdater::manifestLocation() const {
24	return {"https://api.github.com/repos/mgba-emu/chip-assets/releases/latest"};
25}
26
27QUrl BattleChipUpdater::parseManifest(const QByteArray& manifest) const {
28	QJsonDocument manifestDoc(QJsonDocument::fromJson(manifest));
29	if (manifestDoc.isNull()) {
30		return QUrl();
31	}
32	for (const auto& assetv : manifestDoc.object()["assets"].toArray()) {
33		QJsonObject asset = assetv.toObject();
34		if (asset["name"].toString() == "chips.rcc") {
35			return asset["browser_download_url"].toString();
36		}
37	}
38	return QUrl();
39}
40
41QString BattleChipUpdater::destination() const {
42	QFileInfo info(GBAApp::dataDir() + "/chips.rcc");
43	if (info.isWritable()) {
44		return info.filePath();
45	}
46	return ConfigController::configDir() + "/chips.rcc";
47}