GH-1453 separate out Mojang version reading, use version file URLs
This commit is contained in:
parent
a20e2590da
commit
163a3095b1
@ -77,6 +77,15 @@ QJsonDocument MinecraftVersion::toJson(bool saveOrder)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString MinecraftVersion::getUrl() const
|
||||||
|
{
|
||||||
|
if(m_versionFileURL.isEmpty())
|
||||||
|
{
|
||||||
|
return QString("http://") + URLConstants::AWS_DOWNLOAD_VERSIONS + m_descriptor + "/" + m_descriptor + ".json";
|
||||||
|
}
|
||||||
|
return m_versionFileURL;
|
||||||
|
}
|
||||||
|
|
||||||
VersionFilePtr MinecraftVersion::getVersionFile()
|
VersionFilePtr MinecraftVersion::getVersionFile()
|
||||||
{
|
{
|
||||||
QFileInfo versionFile(QString("versions/%1/%1.dat").arg(m_descriptor));
|
QFileInfo versionFile(QString("versions/%1/%1.dat").arg(m_descriptor));
|
||||||
|
@ -76,15 +76,17 @@ public: /* methods */
|
|||||||
|
|
||||||
virtual QJsonDocument toJson(bool saveOrder) override;
|
virtual QJsonDocument toJson(bool saveOrder) override;
|
||||||
|
|
||||||
|
QString getUrl() const;
|
||||||
|
|
||||||
private: /* methods */
|
private: /* methods */
|
||||||
void applyFileTo(MinecraftProfile *version);
|
void applyFileTo(MinecraftProfile *version);
|
||||||
|
|
||||||
public: /* data */
|
public: /* data */
|
||||||
/// The URL that this version will be downloaded from. maybe.
|
|
||||||
QString download_url;
|
|
||||||
|
|
||||||
VersionSource m_versionSource = Builtin;
|
VersionSource m_versionSource = Builtin;
|
||||||
|
|
||||||
|
/// The URL that this version will be downloaded from.
|
||||||
|
QString m_versionFileURL;
|
||||||
|
|
||||||
/// the human readable version name
|
/// the human readable version name
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ class MCVListVersionUpdateTask : public Task
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MCVListVersionUpdateTask(MinecraftVersionList *vlist, QString updatedVersion);
|
explicit MCVListVersionUpdateTask(MinecraftVersionList *vlist, std::shared_ptr<MinecraftVersion> updatedVersion);
|
||||||
virtual ~MCVListVersionUpdateTask() override{};
|
virtual ~MCVListVersionUpdateTask() override{};
|
||||||
virtual void executeTask() override;
|
virtual void executeTask() override;
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ slots:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
NetJobPtr specificVersionDownloadJob;
|
NetJobPtr specificVersionDownloadJob;
|
||||||
QString versionToUpdate;
|
std::shared_ptr<MinecraftVersion> updatedVersion;
|
||||||
MinecraftVersionList *m_list;
|
MinecraftVersionList *m_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -190,10 +190,7 @@ void MinecraftVersionList::loadBuiltinList()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the download URL.
|
mcVersion->m_versionFileURL = QString();
|
||||||
mcVersion->download_url =
|
|
||||||
"http://" + URLConstants::AWS_DOWNLOAD_VERSIONS + versionID + "/";
|
|
||||||
|
|
||||||
mcVersion->m_versionSource = Builtin;
|
mcVersion->m_versionSource = Builtin;
|
||||||
mcVersion->m_type = versionTypeStr;
|
mcVersion->m_type = versionTypeStr;
|
||||||
mcVersion->m_appletClass = versionObj.value("appletClass").toString("");
|
mcVersion->m_appletClass = versionObj.value("appletClass").toString("");
|
||||||
@ -293,9 +290,7 @@ void MinecraftVersionList::loadMojangList(QJsonDocument jsonDoc, VersionSource s
|
|||||||
|
|
||||||
// depends on where we load the version from -- network request or local file?
|
// depends on where we load the version from -- network request or local file?
|
||||||
mcVersion->m_versionSource = source;
|
mcVersion->m_versionSource = source;
|
||||||
|
mcVersion->m_versionFileURL = versionObj.value("url").toString("");
|
||||||
QString dlUrl = "http://" + URLConstants::AWS_DOWNLOAD_VERSIONS + versionID + "/";
|
|
||||||
mcVersion->download_url = dlUrl;
|
|
||||||
QString versionTypeStr = versionObj.value("type").toString("");
|
QString versionTypeStr = versionObj.value("type").toString("");
|
||||||
if (versionTypeStr.isEmpty())
|
if (versionTypeStr.isEmpty())
|
||||||
{
|
{
|
||||||
@ -479,20 +474,17 @@ void MCVListLoadTask::list_downloaded()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MCVListVersionUpdateTask::MCVListVersionUpdateTask(MinecraftVersionList *vlist,
|
MCVListVersionUpdateTask::MCVListVersionUpdateTask(MinecraftVersionList *vlist, std::shared_ptr<MinecraftVersion> updatedVersion)
|
||||||
QString updatedVersion)
|
|
||||||
: Task()
|
: Task()
|
||||||
{
|
{
|
||||||
m_list = vlist;
|
m_list = vlist;
|
||||||
versionToUpdate = updatedVersion;
|
this->updatedVersion = updatedVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCVListVersionUpdateTask::executeTask()
|
void MCVListVersionUpdateTask::executeTask()
|
||||||
{
|
{
|
||||||
QString urlstr = "http://" + URLConstants::AWS_DOWNLOAD_VERSIONS + versionToUpdate + "/" +
|
|
||||||
versionToUpdate + ".json";
|
|
||||||
auto job = new NetJob("Version index");
|
auto job = new NetJob("Version index");
|
||||||
job->addNetAction(ByteArrayDownload::make(QUrl(urlstr)));
|
job->addNetAction(ByteArrayDownload::make(QUrl(updatedVersion->getUrl())));
|
||||||
specificVersionDownloadJob.reset(job);
|
specificVersionDownloadJob.reset(job);
|
||||||
connect(specificVersionDownloadJob.get(), SIGNAL(succeeded()), SLOT(json_downloaded()));
|
connect(specificVersionDownloadJob.get(), SIGNAL(succeeded()), SLOT(json_downloaded()));
|
||||||
connect(specificVersionDownloadJob.get(), SIGNAL(failed(QString)), SIGNAL(failed(QString)));
|
connect(specificVersionDownloadJob.get(), SIGNAL(failed(QString)), SIGNAL(failed(QString)));
|
||||||
@ -518,7 +510,7 @@ void MCVListVersionUpdateTask::json_downloaded()
|
|||||||
VersionFilePtr file;
|
VersionFilePtr file;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
file = VersionFile::fromJson(jsonDoc, "net.minecraft.json", false);
|
file = VersionFile::fromMojangJson(jsonDoc, "net.minecraft.json");
|
||||||
}
|
}
|
||||||
catch (Exception &e)
|
catch (Exception &e)
|
||||||
{
|
{
|
||||||
@ -536,7 +528,8 @@ void MCVListVersionUpdateTask::json_downloaded()
|
|||||||
// now dump the file to disk
|
// now dump the file to disk
|
||||||
auto doc = file->toJson(false);
|
auto doc = file->toJson(false);
|
||||||
auto newdata = doc.toBinaryData();
|
auto newdata = doc.toBinaryData();
|
||||||
QString targetPath = "versions/" + versionToUpdate + "/" + versionToUpdate + ".dat";
|
auto id = updatedVersion->descriptor();
|
||||||
|
QString targetPath = "versions/" + id + "/" + id + ".dat";
|
||||||
FS::ensureFilePathExists(targetPath);
|
FS::ensureFilePathExists(targetPath);
|
||||||
QSaveFile vfile1(targetPath);
|
QSaveFile vfile1(targetPath);
|
||||||
if (!vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly))
|
if (!vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly))
|
||||||
@ -559,13 +552,23 @@ void MCVListVersionUpdateTask::json_downloaded()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_list->finalizeUpdate(versionToUpdate);
|
m_list->finalizeUpdate(id);
|
||||||
emitSucceeded();
|
emitSucceeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Task> MinecraftVersionList::createUpdateTask(QString version)
|
std::shared_ptr<Task> MinecraftVersionList::createUpdateTask(QString version)
|
||||||
{
|
{
|
||||||
return std::shared_ptr<Task>(new MCVListVersionUpdateTask(this, version));
|
auto iter = m_lookup.find(version);
|
||||||
|
if(iter == m_lookup.end())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto mcversion = std::dynamic_pointer_cast<MinecraftVersion>(*iter);
|
||||||
|
if(!mcversion)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::shared_ptr<Task>(new MCVListVersionUpdateTask(this, mcversion));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MinecraftVersionList::saveCachedList()
|
void MinecraftVersionList::saveCachedList()
|
||||||
@ -590,6 +593,7 @@ void MinecraftVersionList::saveCachedList()
|
|||||||
entryObj.insert("version", mcversion->descriptor());
|
entryObj.insert("version", mcversion->descriptor());
|
||||||
entryObj.insert("time", mcversion->m_updateTimeString);
|
entryObj.insert("time", mcversion->m_updateTimeString);
|
||||||
entryObj.insert("releaseTime", mcversion->m_releaseTimeString);
|
entryObj.insert("releaseTime", mcversion->m_releaseTimeString);
|
||||||
|
entryObj.insert("url", mcversion->m_versionFileURL);
|
||||||
entryObj.insert("type", mcversion->m_type);
|
entryObj.insert("type", mcversion->m_type);
|
||||||
entriesArr.append(entryObj);
|
entriesArr.append(entryObj);
|
||||||
}
|
}
|
||||||
|
@ -74,8 +74,7 @@ void OneSixUpdate::executeTask()
|
|||||||
}
|
}
|
||||||
connect(versionUpdateTask.get(), SIGNAL(succeeded()), SLOT(jarlibStart()));
|
connect(versionUpdateTask.get(), SIGNAL(succeeded()), SLOT(jarlibStart()));
|
||||||
connect(versionUpdateTask.get(), &NetJob::failed, this, &OneSixUpdate::versionUpdateFailed);
|
connect(versionUpdateTask.get(), &NetJob::failed, this, &OneSixUpdate::versionUpdateFailed);
|
||||||
connect(versionUpdateTask.get(), SIGNAL(progress(qint64, qint64)),
|
connect(versionUpdateTask.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64)));
|
||||||
SIGNAL(progress(qint64, qint64)));
|
|
||||||
setStatus(tr("Getting the version files from Mojang..."));
|
setStatus(tr("Getting the version files from Mojang..."));
|
||||||
versionUpdateTask->start();
|
versionUpdateTask->start();
|
||||||
}
|
}
|
||||||
@ -103,8 +102,7 @@ void OneSixUpdate::assetIndexStart()
|
|||||||
|
|
||||||
connect(jarlibDownloadJob.get(), SIGNAL(succeeded()), SLOT(assetIndexFinished()));
|
connect(jarlibDownloadJob.get(), SIGNAL(succeeded()), SLOT(assetIndexFinished()));
|
||||||
connect(jarlibDownloadJob.get(), &NetJob::failed, this, &OneSixUpdate::assetIndexFailed);
|
connect(jarlibDownloadJob.get(), &NetJob::failed, this, &OneSixUpdate::assetIndexFailed);
|
||||||
connect(jarlibDownloadJob.get(), SIGNAL(progress(qint64, qint64)),
|
connect(jarlibDownloadJob.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64)));
|
||||||
SIGNAL(progress(qint64, qint64)));
|
|
||||||
|
|
||||||
qDebug() << m_inst->name() << ": Starting asset index download";
|
qDebug() << m_inst->name() << ": Starting asset index download";
|
||||||
jarlibDownloadJob->start();
|
jarlibDownloadJob->start();
|
||||||
@ -135,9 +133,7 @@ void OneSixUpdate::assetIndexFinished()
|
|||||||
QFileInfo objectFile("assets/objects/" + objectName);
|
QFileInfo objectFile("assets/objects/" + objectName);
|
||||||
if ((!objectFile.isFile()) || (objectFile.size() != object.size))
|
if ((!objectFile.isFile()) || (objectFile.size() != object.size))
|
||||||
{
|
{
|
||||||
auto objectDL = MD5EtagDownload::make(
|
auto objectDL = MD5EtagDownload::make(QUrl("http://" + URLConstants::RESOURCE_BASE + objectName), objectFile.filePath());
|
||||||
QUrl("http://" + URLConstants::RESOURCE_BASE + objectName),
|
|
||||||
objectFile.filePath());
|
|
||||||
objectDL->m_total_progress = object.size;
|
objectDL->m_total_progress = object.size;
|
||||||
dls.append(objectDL);
|
dls.append(objectDL);
|
||||||
}
|
}
|
||||||
@ -151,8 +147,7 @@ void OneSixUpdate::assetIndexFinished()
|
|||||||
jarlibDownloadJob.reset(job);
|
jarlibDownloadJob.reset(job);
|
||||||
connect(jarlibDownloadJob.get(), SIGNAL(succeeded()), SLOT(assetsFinished()));
|
connect(jarlibDownloadJob.get(), SIGNAL(succeeded()), SLOT(assetsFinished()));
|
||||||
connect(jarlibDownloadJob.get(), &NetJob::failed, this, &OneSixUpdate::assetsFailed);
|
connect(jarlibDownloadJob.get(), &NetJob::failed, this, &OneSixUpdate::assetsFailed);
|
||||||
connect(jarlibDownloadJob.get(), SIGNAL(progress(qint64, qint64)),
|
connect(jarlibDownloadJob.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64)));
|
||||||
SIGNAL(progress(qint64, qint64)));
|
|
||||||
jarlibDownloadJob->start();
|
jarlibDownloadJob->start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,23 @@ using namespace Json;
|
|||||||
|
|
||||||
#define CURRENT_MINIMUM_LAUNCHER_VERSION 18
|
#define CURRENT_MINIMUM_LAUNCHER_VERSION 18
|
||||||
|
|
||||||
|
static void readString(const QJsonObject &root, const QString &key, QString &variable)
|
||||||
|
{
|
||||||
|
if (root.contains(key))
|
||||||
|
{
|
||||||
|
variable = requireString(root.value(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString readStringRet(const QJsonObject &root, const QString &key)
|
||||||
|
{
|
||||||
|
if (root.contains(key))
|
||||||
|
{
|
||||||
|
return requireString(root.value(key));
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
int findLibraryByName(QList<OneSixLibraryPtr> haystack, const GradleSpecifier &needle)
|
int findLibraryByName(QList<OneSixLibraryPtr> haystack, const GradleSpecifier &needle)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
@ -33,8 +50,55 @@ int findLibraryByName(QList<OneSixLibraryPtr> haystack, const GradleSpecifier &n
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &filename,
|
VersionFilePtr VersionFile::fromMojangJson(const QJsonDocument &doc, const QString &filename)
|
||||||
const bool requireOrder)
|
{
|
||||||
|
VersionFilePtr out(new VersionFile());
|
||||||
|
if (doc.isEmpty() || doc.isNull())
|
||||||
|
{
|
||||||
|
throw JSONValidationError(filename + " is empty or null");
|
||||||
|
}
|
||||||
|
if (!doc.isObject())
|
||||||
|
{
|
||||||
|
throw JSONValidationError(filename + " is not an object");
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject root = doc.object();
|
||||||
|
|
||||||
|
out->name = root.value("name").toString();
|
||||||
|
out->fileId = root.value("fileId").toString();
|
||||||
|
out->version = root.value("version").toString();
|
||||||
|
out->mcVersion = root.value("mcVersion").toString();
|
||||||
|
out->filename = filename;
|
||||||
|
|
||||||
|
readString(root, "id", out->id);
|
||||||
|
|
||||||
|
readString(root, "mainClass", out->mainClass);
|
||||||
|
readString(root, "appletClass", out->appletClass);
|
||||||
|
readString(root, "minecraftArguments", out->overwriteMinecraftArguments);
|
||||||
|
readString(root, "type", out->type);
|
||||||
|
|
||||||
|
readString(root, "assets", out->assets);
|
||||||
|
|
||||||
|
if (root.contains("minimumLauncherVersion"))
|
||||||
|
{
|
||||||
|
out->minimumLauncherVersion = requireInteger(root.value("minimumLauncherVersion"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root.contains("libraries"))
|
||||||
|
{
|
||||||
|
out->shouldOverwriteLibs = true;
|
||||||
|
for (auto libVal : requireArray(root.value("libraries")))
|
||||||
|
{
|
||||||
|
auto libObj = requireObject(libVal);
|
||||||
|
|
||||||
|
auto lib = RawLibrary::fromJson(libObj, filename);
|
||||||
|
out->overwriteLibs.append(lib);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &filename, const bool requireOrder)
|
||||||
{
|
{
|
||||||
VersionFilePtr out(new VersionFile());
|
VersionFilePtr out(new VersionFile());
|
||||||
if (doc.isEmpty() || doc.isNull())
|
if (doc.isEmpty() || doc.isNull())
|
||||||
@ -67,37 +131,20 @@ VersionFilePtr VersionFile::fromJson(const QJsonDocument &doc, const QString &fi
|
|||||||
out->mcVersion = root.value("mcVersion").toString();
|
out->mcVersion = root.value("mcVersion").toString();
|
||||||
out->filename = filename;
|
out->filename = filename;
|
||||||
|
|
||||||
auto readString = [root](const QString &key, QString &variable)
|
readString(root, "id", out->id);
|
||||||
{
|
|
||||||
if (root.contains(key))
|
|
||||||
{
|
|
||||||
variable = requireString(root.value(key));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
auto readStringRet = [root](const QString &key) -> QString
|
readString(root, "mainClass", out->mainClass);
|
||||||
{
|
readString(root, "appletClass", out->appletClass);
|
||||||
if (root.contains(key))
|
readString(root, "processArguments", out->processArguments);
|
||||||
{
|
readString(root, "minecraftArguments", out->overwriteMinecraftArguments);
|
||||||
return requireString(root.value(key));
|
readString(root, "+minecraftArguments", out->addMinecraftArguments);
|
||||||
}
|
readString(root, "-minecraftArguments", out->removeMinecraftArguments);
|
||||||
return QString();
|
readString(root, "type", out->type);
|
||||||
};
|
|
||||||
|
|
||||||
readString("id", out->id);
|
parse_timestamp(readStringRet(root, "releaseTime"), out->m_releaseTimeString, out->m_releaseTime);
|
||||||
|
parse_timestamp(readStringRet(root, "time"), out->m_updateTimeString, out->m_updateTime);
|
||||||
|
|
||||||
readString("mainClass", out->mainClass);
|
readString(root, "assets", out->assets);
|
||||||
readString("appletClass", out->appletClass);
|
|
||||||
readString("processArguments", out->processArguments);
|
|
||||||
readString("minecraftArguments", out->overwriteMinecraftArguments);
|
|
||||||
readString("+minecraftArguments", out->addMinecraftArguments);
|
|
||||||
readString("-minecraftArguments", out->removeMinecraftArguments);
|
|
||||||
readString("type", out->type);
|
|
||||||
|
|
||||||
parse_timestamp(readStringRet("releaseTime"), out->m_releaseTimeString, out->m_releaseTime);
|
|
||||||
parse_timestamp(readStringRet("time"), out->m_updateTimeString, out->m_updateTime);
|
|
||||||
|
|
||||||
readString("assets", out->assets);
|
|
||||||
|
|
||||||
if (root.contains("minimumLauncherVersion"))
|
if (root.contains("minimumLauncherVersion"))
|
||||||
{
|
{
|
||||||
|
@ -19,6 +19,7 @@ typedef std::shared_ptr<VersionFile> VersionFilePtr;
|
|||||||
class VersionFile : public ProfilePatch
|
class VersionFile : public ProfilePatch
|
||||||
{
|
{
|
||||||
public: /* methods */
|
public: /* methods */
|
||||||
|
static VersionFilePtr fromMojangJson(const QJsonDocument &doc, const QString &filename);
|
||||||
static VersionFilePtr fromJson(const QJsonDocument &doc, const QString &filename,
|
static VersionFilePtr fromJson(const QJsonDocument &doc, const QString &filename,
|
||||||
const bool requireOrder);
|
const bool requireOrder);
|
||||||
virtual QJsonDocument toJson(bool saveOrder) override;
|
virtual QJsonDocument toJson(bool saveOrder) override;
|
||||||
|
Loading…
Reference in New Issue
Block a user