Add mod website button thing feature widget. It is super effective.
This commit is contained in:
102
logic/Mod.cpp
102
logic/Mod.cpp
@ -1,12 +1,12 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2012 MultiMC Contributors
|
||||
//
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@ -28,17 +28,17 @@
|
||||
#include <inifile.h>
|
||||
#include <logger/QsLog.h>
|
||||
|
||||
Mod::Mod( const QFileInfo& file )
|
||||
Mod::Mod(const QFileInfo &file)
|
||||
{
|
||||
repath(file);
|
||||
}
|
||||
|
||||
void Mod::repath ( const QFileInfo& file )
|
||||
void Mod::repath(const QFileInfo &file)
|
||||
{
|
||||
m_file = file;
|
||||
m_name = file.completeBaseName();
|
||||
m_id = file.fileName();
|
||||
|
||||
|
||||
m_type = Mod::MOD_UNKNOWN;
|
||||
if (m_file.isDir())
|
||||
m_type = MOD_FOLDER;
|
||||
@ -50,19 +50,19 @@ void Mod::repath ( const QFileInfo& file )
|
||||
else
|
||||
m_type = MOD_SINGLEFILE;
|
||||
}
|
||||
if(m_type == MOD_ZIPFILE)
|
||||
if (m_type == MOD_ZIPFILE)
|
||||
{
|
||||
QuaZip zip(m_file.filePath());
|
||||
if(!zip.open(QuaZip::mdUnzip))
|
||||
if (!zip.open(QuaZip::mdUnzip))
|
||||
return;
|
||||
|
||||
|
||||
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();
|
||||
if(name == "mcmod.info")
|
||||
if (name == "mcmod.info")
|
||||
{
|
||||
if(!file.open(QIODevice::ReadOnly))
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
zip.close();
|
||||
return;
|
||||
@ -72,9 +72,9 @@ void Mod::repath ( const QFileInfo& file )
|
||||
zip.close();
|
||||
return;
|
||||
}
|
||||
else if(name == "forgeversion.properties")
|
||||
else if (name == "forgeversion.properties")
|
||||
{
|
||||
if(!file.open(QIODevice::ReadOnly))
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
zip.close();
|
||||
return;
|
||||
@ -87,16 +87,16 @@ void Mod::repath ( const QFileInfo& file )
|
||||
}
|
||||
zip.close();
|
||||
}
|
||||
else if(m_type == MOD_FOLDER)
|
||||
else if (m_type == MOD_FOLDER)
|
||||
{
|
||||
QFileInfo mcmod_info(PathCombine(m_file.filePath(), "mcmod.info"));
|
||||
if (mcmod_info.isFile())
|
||||
{
|
||||
QFile mcmod(mcmod_info.filePath());
|
||||
if(!mcmod.open(QIODevice::ReadOnly))
|
||||
if (!mcmod.open(QIODevice::ReadOnly))
|
||||
return;
|
||||
auto data = mcmod.readAll();
|
||||
if(data.isEmpty() || data.isNull())
|
||||
if (data.isEmpty() || data.isNull())
|
||||
return;
|
||||
ReadMCModInfo(data);
|
||||
}
|
||||
@ -110,35 +110,37 @@ void Mod::repath ( const QFileInfo& file )
|
||||
// https://github.com/MinecraftForge/FML/wiki/FML-mod-information-file/5bf6a2d05145ec79387acc0d45c958642fb049fc
|
||||
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;
|
||||
auto firstObj = arr.at(0).toObject();
|
||||
m_id = firstObj.value("modid").toString();
|
||||
m_name = firstObj.value("name").toString();
|
||||
m_version = firstObj.value("version").toString();
|
||||
m_homeurl = firstObj.value("url").toString();
|
||||
return;
|
||||
};
|
||||
}
|
||||
;
|
||||
QJsonParseError jsonError;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(contents, &jsonError);
|
||||
// this is the very old format that had just the array
|
||||
if(jsonDoc.isArray())
|
||||
if (jsonDoc.isArray())
|
||||
{
|
||||
getInfoFromArray(jsonDoc.array());
|
||||
}
|
||||
else if(jsonDoc.isObject())
|
||||
else if (jsonDoc.isObject())
|
||||
{
|
||||
auto val = jsonDoc.object().value("modinfoversion");
|
||||
int version = val.toDouble();
|
||||
if(version != 2)
|
||||
if (version != 2)
|
||||
{
|
||||
QLOG_ERROR() << "BAD stuff happened to mod json:";
|
||||
QLOG_ERROR() << contents;
|
||||
return;
|
||||
}
|
||||
auto arrVal = jsonDoc.object().value("modlist");
|
||||
if(arrVal.isArray())
|
||||
if (arrVal.isArray())
|
||||
{
|
||||
getInfoFromArray(arrVal.toArray());
|
||||
}
|
||||
@ -150,33 +152,34 @@ void Mod::ReadForgeInfo(QByteArray contents)
|
||||
// Read the data
|
||||
m_name = "Minecraft Forge";
|
||||
m_id = "Forge";
|
||||
m_homeurl = "http://www.minecraftforge.net/forum/";
|
||||
INIFile ini;
|
||||
if(!ini.loadFile(contents))
|
||||
if (!ini.loadFile(contents))
|
||||
return;
|
||||
|
||||
QString major = ini.get("forge.major.number","0").toString();
|
||||
QString minor = ini.get("forge.minor.number","0").toString();
|
||||
QString revision = ini.get("forge.revision.number","0").toString();
|
||||
QString build = ini.get("forge.build.number","0").toString();
|
||||
|
||||
|
||||
QString major = ini.get("forge.major.number", "0").toString();
|
||||
QString minor = ini.get("forge.minor.number", "0").toString();
|
||||
QString revision = ini.get("forge.revision.number", "0").toString();
|
||||
QString build = ini.get("forge.build.number", "0").toString();
|
||||
|
||||
m_version = major + "." + minor + "." + revision + "." + build;
|
||||
}
|
||||
|
||||
bool Mod::replace ( Mod& with )
|
||||
bool Mod::replace(Mod &with)
|
||||
{
|
||||
if(!destroy())
|
||||
if (!destroy())
|
||||
return false;
|
||||
bool success = false;
|
||||
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());
|
||||
}
|
||||
if(t == MOD_FOLDER)
|
||||
if (t == MOD_FOLDER)
|
||||
{
|
||||
success = copyPath(with.m_file.filePath(), m_file.path());
|
||||
}
|
||||
if(success)
|
||||
if (success)
|
||||
{
|
||||
m_id = with.m_id;
|
||||
m_mcversion = with.m_mcversion;
|
||||
@ -189,10 +192,10 @@ bool Mod::replace ( Mod& with )
|
||||
|
||||
bool Mod::destroy()
|
||||
{
|
||||
if(m_type == MOD_FOLDER)
|
||||
if (m_type == MOD_FOLDER)
|
||||
{
|
||||
QDir d(m_file.filePath());
|
||||
if(d.removeRecursively())
|
||||
if (d.removeRecursively())
|
||||
{
|
||||
m_type = MOD_UNKNOWN;
|
||||
return true;
|
||||
@ -202,7 +205,7 @@ bool Mod::destroy()
|
||||
else if (m_type == MOD_SINGLEFILE || m_type == MOD_ZIPFILE)
|
||||
{
|
||||
QFile f(m_file.filePath());
|
||||
if(f.remove())
|
||||
if (f.remove())
|
||||
{
|
||||
m_type = MOD_UNKNOWN;
|
||||
return true;
|
||||
@ -212,18 +215,17 @@ bool Mod::destroy()
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
QString Mod::version() const
|
||||
{
|
||||
switch(type())
|
||||
switch (type())
|
||||
{
|
||||
case MOD_ZIPFILE:
|
||||
return m_version;
|
||||
case MOD_FOLDER:
|
||||
return "Folder";
|
||||
case MOD_SINGLEFILE:
|
||||
return "File";
|
||||
default:
|
||||
return "VOID";
|
||||
case MOD_ZIPFILE:
|
||||
return m_version;
|
||||
case MOD_FOLDER:
|
||||
return "Folder";
|
||||
case MOD_SINGLEFILE:
|
||||
return "File";
|
||||
default:
|
||||
return "VOID";
|
||||
}
|
||||
}
|
||||
|
69
logic/Mod.h
69
logic/Mod.h
@ -1,12 +1,12 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2012 MultiMC Contributors
|
||||
//
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@ -22,46 +22,72 @@ class Mod
|
||||
public:
|
||||
enum ModType
|
||||
{
|
||||
MOD_UNKNOWN, //!< Indicates an unspecified mod type.
|
||||
MOD_ZIPFILE, //!< The mod is a zip file containing the mod's class files.
|
||||
MOD_UNKNOWN, //!< Indicates an unspecified mod type.
|
||||
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_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);
|
||||
|
||||
QFileInfo filename() const { return m_file; }
|
||||
QString id() const { 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; };
|
||||
|
||||
|
||||
QFileInfo filename() const
|
||||
{
|
||||
return m_file;
|
||||
}
|
||||
QString id() const
|
||||
{
|
||||
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 homeurl() const
|
||||
{
|
||||
return m_homeurl;
|
||||
}
|
||||
|
||||
// delete all the files of this mod
|
||||
bool destroy();
|
||||
// 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)
|
||||
void repath(const QFileInfo &file);
|
||||
|
||||
// WEAK compare operator - used for replacing mods
|
||||
bool operator ==(const Mod &other) const
|
||||
bool operator==(const Mod &other) const
|
||||
{
|
||||
return filename() == other.filename();
|
||||
}
|
||||
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:
|
||||
void ReadMCModInfo(QByteArray contents);
|
||||
void ReadForgeInfo(QByteArray contents);
|
||||
|
||||
protected:
|
||||
|
||||
//FIXME: what do do with those? HMM...
|
||||
// FIXME: what do do with those? HMM...
|
||||
/*
|
||||
void ReadModInfoData(QString info);
|
||||
void ReadForgeInfoData(QString infoFileData);
|
||||
@ -72,6 +98,7 @@ protected:
|
||||
QString m_name;
|
||||
QString m_version;
|
||||
QString m_mcversion;
|
||||
QString m_homeurl;
|
||||
|
||||
ModType m_type;
|
||||
};
|
||||
|
@ -3,7 +3,7 @@
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
@ -32,10 +32,8 @@
|
||||
#define ASSETS_URLBASE "http://assets.minecraft.net/"
|
||||
#define MCN_URLBASE "http://sonicrules.org/mcnweb.py"
|
||||
|
||||
MinecraftVersionList::MinecraftVersionList(QObject *parent) :
|
||||
BaseVersionList(parent)
|
||||
MinecraftVersionList::MinecraftVersionList(QObject *parent) : BaseVersionList(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Task *MinecraftVersionList::getLoadTask()
|
||||
@ -76,7 +74,7 @@ BaseVersionPtr MinecraftVersionList::getLatestStable() const
|
||||
{
|
||||
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)
|
||||
{
|
||||
return m_vlist.at(i);
|
||||
@ -85,7 +83,7 @@ BaseVersionPtr MinecraftVersionList::getLatestStable() const
|
||||
return BaseVersionPtr();
|
||||
}
|
||||
|
||||
void MinecraftVersionList::updateListData(QList<BaseVersionPtr > versions)
|
||||
void MinecraftVersionList::updateListData(QList<BaseVersionPtr> versions)
|
||||
{
|
||||
beginResetModel();
|
||||
m_vlist = versions;
|
||||
@ -109,7 +107,6 @@ inline QDateTime timeFromS3Time(QString str)
|
||||
return QDateTime::fromString(str, Qt::ISODate);
|
||||
}
|
||||
|
||||
|
||||
MCVListLoadTask::MCVListLoadTask(MinecraftVersionList *vlist)
|
||||
{
|
||||
m_list = vlist;
|
||||
@ -151,91 +148,91 @@ void MCVListLoadTask::executeTask()
|
||||
connect(vlistReply, SIGNAL(finished()), this, SLOT(list_downloaded()));
|
||||
}
|
||||
|
||||
|
||||
void MCVListLoadTask::list_downloaded()
|
||||
{
|
||||
if(vlistReply->error() != QNetworkReply::NoError)
|
||||
if (vlistReply->error() != QNetworkReply::NoError)
|
||||
{
|
||||
vlistReply->deleteLater();
|
||||
emitFailed("Failed to load Minecraft main version list" + vlistReply->errorString());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
QJsonParseError jsonError;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(vlistReply->readAll(), &jsonError);
|
||||
vlistReply->deleteLater();
|
||||
|
||||
|
||||
if (jsonError.error != QJsonParseError::NoError)
|
||||
{
|
||||
emitFailed("Error parsing version list JSON:" + jsonError.errorString());
|
||||
return;
|
||||
}
|
||||
|
||||
if(!jsonDoc.isObject())
|
||||
if (!jsonDoc.isObject())
|
||||
{
|
||||
emitFailed("Error parsing version list JSON: jsonDoc is not an object");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
QJsonObject root = jsonDoc.object();
|
||||
|
||||
|
||||
// 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");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
QJsonObject latest = root.value("latest").toObject();
|
||||
|
||||
|
||||
QString latestReleaseID = latest.value("release").toString("");
|
||||
QString latestSnapshotID = latest.value("snapshot").toString("");
|
||||
if(latestReleaseID.isEmpty())
|
||||
if (latestReleaseID.isEmpty())
|
||||
{
|
||||
emitFailed("Error parsing version list JSON: latest release field is missing");
|
||||
return;
|
||||
}
|
||||
if(latestSnapshotID.isEmpty())
|
||||
if (latestSnapshotID.isEmpty())
|
||||
{
|
||||
emitFailed("Error parsing version list JSON: latest snapshot field is missing");
|
||||
return;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
QJsonArray versions = root.value("versions").toArray();
|
||||
|
||||
QList<BaseVersionPtr > tempList;
|
||||
|
||||
QList<BaseVersionPtr> tempList;
|
||||
for (int i = 0; i < versions.count(); i++)
|
||||
{
|
||||
bool is_snapshot = false;
|
||||
bool is_latest = false;
|
||||
|
||||
|
||||
// Load the version info.
|
||||
if(!versions[i].isObject())
|
||||
if (!versions[i].isObject())
|
||||
{
|
||||
//FIXME: log this somewhere
|
||||
// FIXME: log this somewhere
|
||||
continue;
|
||||
}
|
||||
QJsonObject version = versions[i].toObject();
|
||||
QString versionID = version.value("id").toString("");
|
||||
QString versionTimeStr = version.value("releaseTime").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;
|
||||
}
|
||||
|
||||
|
||||
// Parse the timestamp.
|
||||
QDateTime versionTime = timeFromS3Time(versionTimeStr);
|
||||
if(!versionTime.isValid())
|
||||
if (!versionTime.isValid())
|
||||
{
|
||||
//FIXME: log this somewhere
|
||||
// FIXME: log this somewhere
|
||||
continue;
|
||||
}
|
||||
// Parse the type.
|
||||
@ -243,23 +240,25 @@ void MCVListLoadTask::list_downloaded()
|
||||
// OneSix or Legacy. use filter to determine type
|
||||
if (versionTypeStr == "release")
|
||||
{
|
||||
versionType = legacyWhitelist.contains(versionID)?MinecraftVersion::Legacy:MinecraftVersion::OneSix;
|
||||
versionType = legacyWhitelist.contains(versionID) ? MinecraftVersion::Legacy
|
||||
: MinecraftVersion::OneSix;
|
||||
is_latest = (versionID == latestReleaseID);
|
||||
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_snapshot = true;
|
||||
}
|
||||
else if(versionTypeStr == "old_alpha")
|
||||
else if (versionTypeStr == "old_alpha")
|
||||
{
|
||||
versionType = MinecraftVersion::Nostalgia;
|
||||
is_latest = false;
|
||||
is_snapshot = false;
|
||||
}
|
||||
else if(versionTypeStr == "old_beta")
|
||||
else if (versionTypeStr == "old_beta")
|
||||
{
|
||||
versionType = MinecraftVersion::Legacy;
|
||||
is_latest = false;
|
||||
@ -267,12 +266,12 @@ void MCVListLoadTask::list_downloaded()
|
||||
}
|
||||
else
|
||||
{
|
||||
//FIXME: log this somewhere
|
||||
// FIXME: log this somewhere
|
||||
continue;
|
||||
}
|
||||
// Get the download URL.
|
||||
QString dlUrl = QString(MCVLIST_URLBASE) + versionID + "/";
|
||||
|
||||
|
||||
// Now, we construct the version object and add it to the list.
|
||||
std::shared_ptr<MinecraftVersion> mcVersion(new MinecraftVersion());
|
||||
mcVersion->m_name = mcVersion->m_descriptor = versionID;
|
||||
@ -284,7 +283,7 @@ void MCVListLoadTask::list_downloaded()
|
||||
tempList.append(mcVersion);
|
||||
}
|
||||
m_list->updateListData(tempList);
|
||||
|
||||
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user