Add mod website button thing feature widget. It is super effective.

This commit is contained in:
Petr Mrázek 2013-10-08 01:36:11 +02:00
parent a58912eaf7
commit 05e2da51d8
11 changed files with 270 additions and 134 deletions

View File

@ -24,6 +24,7 @@
#include <pathutils.h> #include <pathutils.h>
#include <QFileDialog> #include <QFileDialog>
//#include <QMessageBox>
#include <QDebug> #include <QDebug>
#include <QEvent> #include <QEvent>
#include <QKeyEvent> #include <QKeyEvent>
@ -343,3 +344,35 @@ void LegacyModEditDialog::on_buttonBox_rejected()
{ {
close(); close();
} }
//FIXME: too much copypasta makes peterix a sad hacker. BUT IT'S SO DELICIOUS!
void LegacyModEditDialog::on_coreWebsite_clicked()
{
int first, last;
auto list = ui->coreModsTreeView->selectionModel()->selectedRows();
if (!lastfirst(list, first, last))
return;
showWebsiteForMod(this, m_coremods->operator[](first));
}
void LegacyModEditDialog::on_jarWebsite_clicked()
{
int first, last;
auto list = ui->jarModsTreeView->selectionModel()->selectedRows();
if (!lastfirst(list, first, last))
return;
showWebsiteForMod(this, m_jarmods->operator[](first));
}
void LegacyModEditDialog::on_loaderWebsite_clicked()
{
int first, last;
auto list = ui->loaderModTreeView->selectionModel()->selectedRows();
if (!lastfirst(list, first, last))
return;
showWebsiteForMod(this, m_mods->operator[](first));
}

View File

@ -19,7 +19,8 @@
#include "logic/LegacyInstance.h" #include "logic/LegacyInstance.h"
#include <logic/net/DownloadJob.h> #include <logic/net/DownloadJob.h>
namespace Ui { namespace Ui
{
class LegacyModEditDialog; class LegacyModEditDialog;
} }
@ -28,10 +29,11 @@ class LegacyModEditDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit LegacyModEditDialog(LegacyInstance* inst, QWidget *parent = 0); explicit LegacyModEditDialog(LegacyInstance *inst, QWidget *parent = 0);
~LegacyModEditDialog(); ~LegacyModEditDialog();
private slots: private
slots:
void on_addJarBtn_clicked(); void on_addJarBtn_clicked();
void on_rmJarBtn_clicked(); void on_rmJarBtn_clicked();
@ -50,20 +52,27 @@ private slots:
void on_addTexPackBtn_clicked(); void on_addTexPackBtn_clicked();
void on_rmTexPackBtn_clicked(); void on_rmTexPackBtn_clicked();
void on_viewTexPackBtn_clicked(); void on_viewTexPackBtn_clicked();
void on_jarWebsite_clicked();
void on_loaderWebsite_clicked();
void on_coreWebsite_clicked();
// Questionable: SettingsDialog doesn't need this for some reason? // Questionable: SettingsDialog doesn't need this for some reason?
void on_buttonBox_rejected(); void on_buttonBox_rejected();
protected: protected:
bool eventFilter(QObject *obj, QEvent *ev); bool eventFilter(QObject *obj, QEvent *ev);
bool jarListFilter( QKeyEvent* ev ); bool jarListFilter(QKeyEvent *ev);
bool coreListFilter( QKeyEvent* ev ); bool coreListFilter(QKeyEvent *ev);
bool loaderListFilter( QKeyEvent* ev ); bool loaderListFilter(QKeyEvent *ev);
bool texturePackListFilter( QKeyEvent* ev ); bool texturePackListFilter(QKeyEvent *ev);
private: private:
Ui::LegacyModEditDialog *ui; Ui::LegacyModEditDialog *ui;
std::shared_ptr<ModList> m_mods; std::shared_ptr<ModList> m_mods;
std::shared_ptr<ModList> m_coremods; std::shared_ptr<ModList> m_coremods;
std::shared_ptr<ModList> m_jarmods; std::shared_ptr<ModList> m_jarmods;
std::shared_ptr<ModList> m_texturepacks; std::shared_ptr<ModList> m_texturepacks;
LegacyInstance * m_inst; LegacyInstance *m_inst;
DownloadJobPtr forgeJob; DownloadJobPtr forgeJob;
}; };

View File

@ -57,6 +57,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="jarWebsite">
<property name="text">
<string>Website</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="jarModsButtonSpacer"> <spacer name="jarModsButtonSpacer">
<property name="orientation"> <property name="orientation">
@ -116,6 +123,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="coreWebsite">
<property name="text">
<string>Website</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="coreModsButtonSpacer"> <spacer name="coreModsButtonSpacer">
<property name="orientation"> <property name="orientation">
@ -171,6 +185,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="loaderWebsite">
<property name="text">
<string>Website</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="mlModsButtonSpacer"> <spacer name="mlModsButtonSpacer">
<property name="orientation"> <property name="orientation">

View File

@ -1,17 +1,40 @@
#include "ModEditDialogCommon.h" #include "ModEditDialogCommon.h"
#include <QDesktopServices>
bool lastfirst (QModelIndexList & list, int & first, int & last) #include <QMessageBox>
#include <QString>
#include <QUrl>
bool lastfirst(QModelIndexList &list, int &first, int &last)
{ {
if(!list.size()) if (!list.size())
return false; return false;
first = last = list[0].row(); first = last = list[0].row();
for(auto item: list) for (auto item : list)
{ {
int row = item.row(); int row = item.row();
if(row < first) if (row < first)
first = row; first = row;
if(row > last) if (row > last)
last = row; last = row;
} }
return true; return true;
} }
void showWebsiteForMod(QWidget *parentDlg, Mod &m)
{
QString url = m.homeurl();
if (url.size())
{
// catch the cases where the protocol is missing
if(!url.startsWith("http"))
{
url = "http://" + url;
}
QDesktopServices::openUrl(url);
}
else
{
QMessageBox::warning(
parentDlg, parentDlg->tr("How sad!"),
parentDlg->tr("The mod author didn't provide a website link for this mod."));
}
}

View File

@ -1,4 +1,7 @@
#pragma once #pragma once
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <logic/Mod.h>
bool lastfirst (QModelIndexList & list, int & first, int & last); bool lastfirst (QModelIndexList & list, int & first, int & last);
void showWebsiteForMod(QWidget * parentDlg, Mod& m);

View File

@ -30,6 +30,7 @@
#include <QDebug> #include <QDebug>
#include <QEvent> #include <QEvent>
#include <QKeyEvent> #include <QKeyEvent>
#include <QDesktopServices>
OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent)
: m_inst(inst), QDialog(parent), ui(new Ui::OneSixModEditDialog) : m_inst(inst), QDialog(parent), ui(new Ui::OneSixModEditDialog)
@ -296,3 +297,13 @@ void OneSixModEditDialog::on_viewResPackBtn_clicked()
{ {
openDirInDefaultProgram(m_inst->resourcePacksDir(), true); openDirInDefaultProgram(m_inst->resourcePacksDir(), true);
} }
void OneSixModEditDialog::on_loaderWebsite_clicked()
{
int first, last;
auto list = ui->loaderModTreeView->selectionModel()->selectedRows();
if (!lastfirst(list, first, last))
return;
showWebsiteForMod(this, m_mods->operator[](first));
}

View File

@ -44,6 +44,7 @@ private slots:
void on_forgeBtn_clicked(); void on_forgeBtn_clicked();
void on_customizeBtn_clicked(); void on_customizeBtn_clicked();
void on_revertBtn_clicked(); void on_revertBtn_clicked();
void on_loaderWebsite_clicked();
void updateVersionControls(); void updateVersionControls();
void disableVersionControls(); void disableVersionControls();
protected: protected:

View File

@ -184,6 +184,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="loaderWebsite">
<property name="text">
<string>Website</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">

View File

@ -28,12 +28,12 @@
#include <inifile.h> #include <inifile.h>
#include <logger/QsLog.h> #include <logger/QsLog.h>
Mod::Mod( const QFileInfo& file ) Mod::Mod(const QFileInfo &file)
{ {
repath(file); repath(file);
} }
void Mod::repath ( const QFileInfo& file ) void Mod::repath(const QFileInfo &file)
{ {
m_file = file; m_file = file;
m_name = file.completeBaseName(); m_name = file.completeBaseName();
@ -50,19 +50,19 @@ void Mod::repath ( const QFileInfo& file )
else else
m_type = MOD_SINGLEFILE; m_type = MOD_SINGLEFILE;
} }
if(m_type == MOD_ZIPFILE) if (m_type == MOD_ZIPFILE)
{ {
QuaZip zip(m_file.filePath()); QuaZip zip(m_file.filePath());
if(!zip.open(QuaZip::mdUnzip)) if (!zip.open(QuaZip::mdUnzip))
return; return;
QuaZipFile file(&zip); QuaZipFile file(&zip);
for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile())
{ {
QString name = zip.getCurrentFileName(); QString name = zip.getCurrentFileName();
if(name == "mcmod.info") if (name == "mcmod.info")
{ {
if(!file.open(QIODevice::ReadOnly)) if (!file.open(QIODevice::ReadOnly))
{ {
zip.close(); zip.close();
return; return;
@ -72,9 +72,9 @@ void Mod::repath ( const QFileInfo& file )
zip.close(); zip.close();
return; return;
} }
else if(name == "forgeversion.properties") else if (name == "forgeversion.properties")
{ {
if(!file.open(QIODevice::ReadOnly)) if (!file.open(QIODevice::ReadOnly))
{ {
zip.close(); zip.close();
return; return;
@ -87,16 +87,16 @@ void Mod::repath ( const QFileInfo& file )
} }
zip.close(); zip.close();
} }
else if(m_type == MOD_FOLDER) else if (m_type == MOD_FOLDER)
{ {
QFileInfo mcmod_info(PathCombine(m_file.filePath(), "mcmod.info")); QFileInfo mcmod_info(PathCombine(m_file.filePath(), "mcmod.info"));
if (mcmod_info.isFile()) if (mcmod_info.isFile())
{ {
QFile mcmod(mcmod_info.filePath()); QFile mcmod(mcmod_info.filePath());
if(!mcmod.open(QIODevice::ReadOnly)) if (!mcmod.open(QIODevice::ReadOnly))
return; return;
auto data = mcmod.readAll(); auto data = mcmod.readAll();
if(data.isEmpty() || data.isNull()) if (data.isEmpty() || data.isNull())
return; return;
ReadMCModInfo(data); ReadMCModInfo(data);
} }
@ -110,35 +110,37 @@ void Mod::repath ( const QFileInfo& file )
// https://github.com/MinecraftForge/FML/wiki/FML-mod-information-file/5bf6a2d05145ec79387acc0d45c958642fb049fc // https://github.com/MinecraftForge/FML/wiki/FML-mod-information-file/5bf6a2d05145ec79387acc0d45c958642fb049fc
void Mod::ReadMCModInfo(QByteArray contents) void Mod::ReadMCModInfo(QByteArray contents)
{ {
auto getInfoFromArray = [&]( QJsonArray arr ) -> void auto getInfoFromArray = [&](QJsonArray arr)->void
{ {
if(!arr.at(0).isObject()) if (!arr.at(0).isObject())
return; return;
auto firstObj = arr.at(0).toObject(); auto firstObj = arr.at(0).toObject();
m_id = firstObj.value("modid").toString(); m_id = firstObj.value("modid").toString();
m_name = firstObj.value("name").toString(); m_name = firstObj.value("name").toString();
m_version = firstObj.value("version").toString(); m_version = firstObj.value("version").toString();
m_homeurl = firstObj.value("url").toString();
return; return;
}; }
;
QJsonParseError jsonError; QJsonParseError jsonError;
QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError); QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError);
// this is the very old format that had just the array // this is the very old format that had just the array
if(jsonDoc.isArray()) if (jsonDoc.isArray())
{ {
getInfoFromArray(jsonDoc.array()); getInfoFromArray(jsonDoc.array());
} }
else if(jsonDoc.isObject()) else if (jsonDoc.isObject())
{ {
auto val = jsonDoc.object().value("modinfoversion"); auto val = jsonDoc.object().value("modinfoversion");
int version = val.toDouble(); int version = val.toDouble();
if(version != 2) if (version != 2)
{ {
QLOG_ERROR() << "BAD stuff happened to mod json:"; QLOG_ERROR() << "BAD stuff happened to mod json:";
QLOG_ERROR() << contents; QLOG_ERROR() << contents;
return; return;
} }
auto arrVal = jsonDoc.object().value("modlist"); auto arrVal = jsonDoc.object().value("modlist");
if(arrVal.isArray()) if (arrVal.isArray())
{ {
getInfoFromArray(arrVal.toArray()); getInfoFromArray(arrVal.toArray());
} }
@ -150,33 +152,34 @@ void Mod::ReadForgeInfo(QByteArray contents)
// Read the data // Read the data
m_name = "Minecraft Forge"; m_name = "Minecraft Forge";
m_id = "Forge"; m_id = "Forge";
m_homeurl = "http://www.minecraftforge.net/forum/";
INIFile ini; INIFile ini;
if(!ini.loadFile(contents)) if (!ini.loadFile(contents))
return; return;
QString major = ini.get("forge.major.number","0").toString(); QString major = ini.get("forge.major.number", "0").toString();
QString minor = ini.get("forge.minor.number","0").toString(); QString minor = ini.get("forge.minor.number", "0").toString();
QString revision = ini.get("forge.revision.number","0").toString(); QString revision = ini.get("forge.revision.number", "0").toString();
QString build = ini.get("forge.build.number","0").toString(); QString build = ini.get("forge.build.number", "0").toString();
m_version = major + "." + minor + "." + revision + "." + build; m_version = major + "." + minor + "." + revision + "." + build;
} }
bool Mod::replace ( Mod& with ) bool Mod::replace(Mod &with)
{ {
if(!destroy()) if (!destroy())
return false; return false;
bool success = false; bool success = false;
auto t = with.type(); auto t = with.type();
if(t == MOD_ZIPFILE || t == MOD_SINGLEFILE) if (t == MOD_ZIPFILE || t == MOD_SINGLEFILE)
{ {
success = QFile::copy(with.m_file.filePath(), m_file.path()); success = QFile::copy(with.m_file.filePath(), m_file.path());
} }
if(t == MOD_FOLDER) if (t == MOD_FOLDER)
{ {
success = copyPath(with.m_file.filePath(), m_file.path()); success = copyPath(with.m_file.filePath(), m_file.path());
} }
if(success) if (success)
{ {
m_id = with.m_id; m_id = with.m_id;
m_mcversion = with.m_mcversion; m_mcversion = with.m_mcversion;
@ -189,10 +192,10 @@ bool Mod::replace ( Mod& with )
bool Mod::destroy() bool Mod::destroy()
{ {
if(m_type == MOD_FOLDER) if (m_type == MOD_FOLDER)
{ {
QDir d(m_file.filePath()); QDir d(m_file.filePath());
if(d.removeRecursively()) if (d.removeRecursively())
{ {
m_type = MOD_UNKNOWN; m_type = MOD_UNKNOWN;
return true; return true;
@ -202,7 +205,7 @@ bool Mod::destroy()
else if (m_type == MOD_SINGLEFILE || m_type == MOD_ZIPFILE) else if (m_type == MOD_SINGLEFILE || m_type == MOD_ZIPFILE)
{ {
QFile f(m_file.filePath()); QFile f(m_file.filePath());
if(f.remove()) if (f.remove())
{ {
m_type = MOD_UNKNOWN; m_type = MOD_UNKNOWN;
return true; return true;
@ -212,18 +215,17 @@ bool Mod::destroy()
return true; return true;
} }
QString Mod::version() const QString Mod::version() const
{ {
switch(type()) switch (type())
{ {
case MOD_ZIPFILE: case MOD_ZIPFILE:
return m_version; return m_version;
case MOD_FOLDER: case MOD_FOLDER:
return "Folder"; return "Folder";
case MOD_SINGLEFILE: case MOD_SINGLEFILE:
return "File"; return "File";
default: default:
return "VOID"; return "VOID";
} }
} }

View File

@ -22,46 +22,72 @@ class Mod
public: public:
enum ModType enum ModType
{ {
MOD_UNKNOWN, //!< Indicates an unspecified mod type. MOD_UNKNOWN, //!< Indicates an unspecified mod type.
MOD_ZIPFILE, //!< The mod is a zip file containing the mod's class files. MOD_ZIPFILE, //!< The mod is a zip file containing the mod's class files.
MOD_SINGLEFILE, //!< The mod is a single file (not a zip file). MOD_SINGLEFILE, //!< The mod is a single file (not a zip file).
MOD_FOLDER, //!< The mod is in a folder on the filesystem. MOD_FOLDER, //!< The mod is in a folder on the filesystem.
}; };
Mod(const QFileInfo &file); Mod(const QFileInfo &file);
QFileInfo filename() const { return m_file; } QFileInfo filename() const
QString id() const { return m_id; } {
ModType type() const { return m_type; } return m_file;
QString mcversion() const { return m_mcversion; }; }
bool valid() {return m_type != MOD_UNKNOWN;} QString id() const
QString name() const {return m_name; }; {
return m_id;
}
ModType type() const
{
return m_type;
}
QString mcversion() const
{
return m_mcversion;
}
;
bool valid()
{
return m_type != MOD_UNKNOWN;
}
QString name() const
{
return m_name;
}
QString version() const; QString version() const;
QString homeurl() const
{
return m_homeurl;
}
// delete all the files of this mod // delete all the files of this mod
bool destroy(); bool destroy();
// replace this mod with a copy of the other // replace this mod with a copy of the other
bool replace(Mod & with); bool replace(Mod &with);
// change the mod's filesystem path (used by mod lists for *MAGIC* purposes) // change the mod's filesystem path (used by mod lists for *MAGIC* purposes)
void repath(const QFileInfo &file); void repath(const QFileInfo &file);
// WEAK compare operator - used for replacing mods // WEAK compare operator - used for replacing mods
bool operator ==(const Mod &other) const bool operator==(const Mod &other) const
{ {
return filename() == other.filename(); return filename() == other.filename();
} }
bool strongCompare(const Mod &other) const bool strongCompare(const Mod &other) const
{ {
return filename() == other.filename() && id() == other.id() && version() == other.version() && type() == other.type(); return filename() == other.filename() && id() == other.id() &&
version() == other.version() && type() == other.type();
} }
private: private:
void ReadMCModInfo(QByteArray contents); void ReadMCModInfo(QByteArray contents);
void ReadForgeInfo(QByteArray contents); void ReadForgeInfo(QByteArray contents);
protected: protected:
//FIXME: what do do with those? HMM... // FIXME: what do do with those? HMM...
/* /*
void ReadModInfoData(QString info); void ReadModInfoData(QString info);
void ReadForgeInfoData(QString infoFileData); void ReadForgeInfoData(QString infoFileData);
@ -72,6 +98,7 @@ protected:
QString m_name; QString m_name;
QString m_version; QString m_version;
QString m_mcversion; QString m_mcversion;
QString m_homeurl;
ModType m_type; ModType m_type;
}; };

View File

@ -32,10 +32,8 @@
#define ASSETS_URLBASE "http://assets.minecraft.net/" #define ASSETS_URLBASE "http://assets.minecraft.net/"
#define MCN_URLBASE "http://sonicrules.org/mcnweb.py" #define MCN_URLBASE "http://sonicrules.org/mcnweb.py"
MinecraftVersionList::MinecraftVersionList(QObject *parent) : MinecraftVersionList::MinecraftVersionList(QObject *parent) : BaseVersionList(parent)
BaseVersionList(parent)
{ {
} }
Task *MinecraftVersionList::getLoadTask() Task *MinecraftVersionList::getLoadTask()
@ -76,7 +74,7 @@ BaseVersionPtr MinecraftVersionList::getLatestStable() const
{ {
for (int i = 0; i < m_vlist.length(); i++) for (int i = 0; i < m_vlist.length(); i++)
{ {
auto ver =std::dynamic_pointer_cast<MinecraftVersion>(m_vlist.at(i)); auto ver = std::dynamic_pointer_cast<MinecraftVersion>(m_vlist.at(i));
if (ver->is_latest && !ver->is_snapshot) if (ver->is_latest && !ver->is_snapshot)
{ {
return m_vlist.at(i); return m_vlist.at(i);
@ -85,7 +83,7 @@ BaseVersionPtr MinecraftVersionList::getLatestStable() const
return BaseVersionPtr(); return BaseVersionPtr();
} }
void MinecraftVersionList::updateListData(QList<BaseVersionPtr > versions) void MinecraftVersionList::updateListData(QList<BaseVersionPtr> versions)
{ {
beginResetModel(); beginResetModel();
m_vlist = versions; m_vlist = versions;
@ -109,7 +107,6 @@ inline QDateTime timeFromS3Time(QString str)
return QDateTime::fromString(str, Qt::ISODate); return QDateTime::fromString(str, Qt::ISODate);
} }
MCVListLoadTask::MCVListLoadTask(MinecraftVersionList *vlist) MCVListLoadTask::MCVListLoadTask(MinecraftVersionList *vlist)
{ {
m_list = vlist; m_list = vlist;
@ -151,10 +148,9 @@ void MCVListLoadTask::executeTask()
connect(vlistReply, SIGNAL(finished()), this, SLOT(list_downloaded())); connect(vlistReply, SIGNAL(finished()), this, SLOT(list_downloaded()));
} }
void MCVListLoadTask::list_downloaded() void MCVListLoadTask::list_downloaded()
{ {
if(vlistReply->error() != QNetworkReply::NoError) if (vlistReply->error() != QNetworkReply::NoError)
{ {
vlistReply->deleteLater(); vlistReply->deleteLater();
emitFailed("Failed to load Minecraft main version list" + vlistReply->errorString()); emitFailed("Failed to load Minecraft main version list" + vlistReply->errorString());
@ -171,7 +167,7 @@ void MCVListLoadTask::list_downloaded()
return; return;
} }
if(!jsonDoc.isObject()) if (!jsonDoc.isObject())
{ {
emitFailed("Error parsing version list JSON: jsonDoc is not an object"); emitFailed("Error parsing version list JSON: jsonDoc is not an object");
return; return;
@ -180,7 +176,7 @@ void MCVListLoadTask::list_downloaded()
QJsonObject root = jsonDoc.object(); QJsonObject root = jsonDoc.object();
// Get the ID of the latest release and the latest snapshot. // Get the ID of the latest release and the latest snapshot.
if(!root.value("latest").isObject()) if (!root.value("latest").isObject())
{ {
emitFailed("Error parsing version list JSON: version list is missing 'latest' object"); emitFailed("Error parsing version list JSON: version list is missing 'latest' object");
return; return;
@ -190,52 +186,53 @@ void MCVListLoadTask::list_downloaded()
QString latestReleaseID = latest.value("release").toString(""); QString latestReleaseID = latest.value("release").toString("");
QString latestSnapshotID = latest.value("snapshot").toString(""); QString latestSnapshotID = latest.value("snapshot").toString("");
if(latestReleaseID.isEmpty()) if (latestReleaseID.isEmpty())
{ {
emitFailed("Error parsing version list JSON: latest release field is missing"); emitFailed("Error parsing version list JSON: latest release field is missing");
return; return;
} }
if(latestSnapshotID.isEmpty()) if (latestSnapshotID.isEmpty())
{ {
emitFailed("Error parsing version list JSON: latest snapshot field is missing"); emitFailed("Error parsing version list JSON: latest snapshot field is missing");
return; return;
} }
// Now, get the array of versions. // Now, get the array of versions.
if(!root.value("versions").isArray()) if (!root.value("versions").isArray())
{ {
emitFailed("Error parsing version list JSON: version list object is missing 'versions' array"); emitFailed(
"Error parsing version list JSON: version list object is missing 'versions' array");
return; return;
} }
QJsonArray versions = root.value("versions").toArray(); QJsonArray versions = root.value("versions").toArray();
QList<BaseVersionPtr > tempList; QList<BaseVersionPtr> tempList;
for (int i = 0; i < versions.count(); i++) for (int i = 0; i < versions.count(); i++)
{ {
bool is_snapshot = false; bool is_snapshot = false;
bool is_latest = false; bool is_latest = false;
// Load the version info. // Load the version info.
if(!versions[i].isObject()) if (!versions[i].isObject())
{ {
//FIXME: log this somewhere // FIXME: log this somewhere
continue; continue;
} }
QJsonObject version = versions[i].toObject(); QJsonObject version = versions[i].toObject();
QString versionID = version.value("id").toString(""); QString versionID = version.value("id").toString("");
QString versionTimeStr = version.value("releaseTime").toString(""); QString versionTimeStr = version.value("releaseTime").toString("");
QString versionTypeStr = version.value("type").toString(""); QString versionTypeStr = version.value("type").toString("");
if(versionID.isEmpty() || versionTimeStr.isEmpty() || versionTypeStr.isEmpty()) if (versionID.isEmpty() || versionTimeStr.isEmpty() || versionTypeStr.isEmpty())
{ {
//FIXME: log this somewhere // FIXME: log this somewhere
continue; continue;
} }
// Parse the timestamp. // Parse the timestamp.
QDateTime versionTime = timeFromS3Time(versionTimeStr); QDateTime versionTime = timeFromS3Time(versionTimeStr);
if(!versionTime.isValid()) if (!versionTime.isValid())
{ {
//FIXME: log this somewhere // FIXME: log this somewhere
continue; continue;
} }
// Parse the type. // Parse the type.
@ -243,23 +240,25 @@ void MCVListLoadTask::list_downloaded()
// OneSix or Legacy. use filter to determine type // OneSix or Legacy. use filter to determine type
if (versionTypeStr == "release") if (versionTypeStr == "release")
{ {
versionType = legacyWhitelist.contains(versionID)?MinecraftVersion::Legacy:MinecraftVersion::OneSix; versionType = legacyWhitelist.contains(versionID) ? MinecraftVersion::Legacy
: MinecraftVersion::OneSix;
is_latest = (versionID == latestReleaseID); is_latest = (versionID == latestReleaseID);
is_snapshot = false; is_snapshot = false;
} }
else if(versionTypeStr == "snapshot") // It's a snapshot... yay else if (versionTypeStr == "snapshot") // It's a snapshot... yay
{ {
versionType = legacyWhitelist.contains(versionID)?MinecraftVersion::Legacy:MinecraftVersion::OneSix; versionType = legacyWhitelist.contains(versionID) ? MinecraftVersion::Legacy
: MinecraftVersion::OneSix;
is_latest = (versionID == latestSnapshotID); is_latest = (versionID == latestSnapshotID);
is_snapshot = true; is_snapshot = true;
} }
else if(versionTypeStr == "old_alpha") else if (versionTypeStr == "old_alpha")
{ {
versionType = MinecraftVersion::Nostalgia; versionType = MinecraftVersion::Nostalgia;
is_latest = false; is_latest = false;
is_snapshot = false; is_snapshot = false;
} }
else if(versionTypeStr == "old_beta") else if (versionTypeStr == "old_beta")
{ {
versionType = MinecraftVersion::Legacy; versionType = MinecraftVersion::Legacy;
is_latest = false; is_latest = false;
@ -267,7 +266,7 @@ void MCVListLoadTask::list_downloaded()
} }
else else
{ {
//FIXME: log this somewhere // FIXME: log this somewhere
continue; continue;
} }
// Get the download URL. // Get the download URL.