Change the OneSix library view. It now shows a list of patches.

This commit is contained in:
Jan Dalheimer
2014-02-01 14:52:21 +01:00
parent 556d8f0ec1
commit 4a9e213238
10 changed files with 183 additions and 49 deletions

View File

@ -74,6 +74,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url)
QJsonObject installObj = installVal.toObject();
QString libraryName = installObj.value("path").toString();
internalPath = installObj.value("filePath").toString();
m_forgeVersionString = installObj.value("version").toString().remove("Forge").trimmed();
// where do we put the library? decode the mojang path
OneSixLibrary lib(libraryName);
@ -204,6 +205,11 @@ bool ForgeInstaller::add(OneSixInstance *to)
}
}
obj.insert("name", QString("Forge"));
obj.insert("id", id());
obj.insert("version", m_forgeVersionString);
obj.insert("mcVersion", to->intendedVersionId());
QFile file(filename(to->instanceRoot()));
if (!file.open(QFile::WriteOnly))
{

View File

@ -37,5 +37,6 @@ private:
QString internalPath;
QString finalPath;
QString realVersionId;
QString m_forgeVersionString;
QString m_universal_url;
};

View File

@ -78,6 +78,10 @@ bool LiteLoaderInstaller::add(OneSixInstance *to)
}
obj.insert("+libraries", libraries);
obj.insert("name", QString("LiteLoader"));
obj.insert("id", id());
obj.insert("version", to->intendedVersionId());
obj.insert("mcVersion", to->intendedVersionId());
QFile file(filename(to->instanceRoot()));
if (!file.open(QFile::WriteOnly))

View File

@ -319,8 +319,9 @@ bool OneSixInstance::shouldUpdate() const
bool OneSixInstance::versionIsCustom()
{
QDir patches(PathCombine(instanceRoot(), "patches/"));
return QFile::exists(PathCombine(instanceRoot(), "custom.json"))
|| (patches.exists() && patches.count() >= 0);
return (patches.exists() && patches.count() >= 0)
|| QFile::exists(PathCombine(instanceRoot(), "custom.json"))
|| QFile::exists(PathCombine(instanceRoot(), "user.json"));
}
QString OneSixInstance::currentVersionId() const

View File

@ -16,6 +16,7 @@
#include "OneSixVersion.h"
#include <QDebug>
#include <QFile>
#include "OneSixVersionBuilder.h"
@ -47,6 +48,7 @@ void OneSixVersion::clear()
mainClass.clear();
libraries.clear();
tweakers.clear();
versionFiles.clear();
endResetModel();
}
@ -70,6 +72,24 @@ void OneSixVersion::dump() const
qDebug().nospace() << "\n)";
}
bool OneSixVersion::canRemove(const int index) const
{
if (index < versionFiles.size())
{
return versionFiles.at(index).id != "org.multimc.version.json";
}
return false;
}
bool OneSixVersion::remove(const int index)
{
if (canRemove(index))
{
return QFile::remove(versionFiles.at(index).filename);
}
return false;
}
QList<std::shared_ptr<OneSixLibrary> > OneSixVersion::getActiveNormalLibs()
{
QList<std::shared_ptr<OneSixLibrary> > output;
@ -114,14 +134,39 @@ QVariant OneSixVersion::data(const QModelIndex &index, int role) const
int row = index.row();
int column = index.column();
if (row < 0 || row >= tweakers.size())
if (row < 0 || row >= versionFiles.size())
return QVariant();
if (role == Qt::DisplayRole)
{
if (column == 0)
switch (column)
{
return tweakers.at(row);
case 0:
return versionFiles.at(row).name;
case 1:
return versionFiles.at(row).version;
default:
return QVariant();
}
}
return QVariant();
}
QVariant OneSixVersion::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal)
{
if (role == Qt::DisplayRole)
{
switch (section)
{
case 0:
return tr("Name");
case 1:
return tr("Version");
default:
return QVariant();
}
}
}
return QVariant();
@ -136,12 +181,12 @@ Qt::ItemFlags OneSixVersion::flags(const QModelIndex &index) const
int OneSixVersion::rowCount(const QModelIndex &parent) const
{
return tweakers.size();
return versionFiles.size();
}
int OneSixVersion::columnCount(const QModelIndex &parent) const
{
return 1;
return 2;
}
QDebug operator<<(QDebug &dbg, const OneSixVersion *version)

View File

@ -32,6 +32,7 @@ public:
explicit OneSixVersion(OneSixInstance *instance, QObject *parent = 0);
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex &parent) const;
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
@ -41,6 +42,12 @@ public:
void dump() const;
bool canRemove(const int index) const;
public
slots:
bool remove(const int index);
public:
QList<std::shared_ptr<OneSixLibrary>> getActiveNormalLibs();
QList<std::shared_ptr<OneSixLibrary>> getActiveNativeLibs();
@ -109,6 +116,16 @@ public:
*/
// QList<Rule> rules;
struct VersionFile
{
QString name;
QString id;
QString version;
QString mcVersion;
QString filename;
};
QList<VersionFile> versionFiles;
private:
OneSixInstance *m_instance;
};

View File

@ -34,6 +34,14 @@
struct VersionFile
{
int order;
QString name;
QString fileId;
QString version;
// TODO use the mcVersion to determine if a version file should be removed on update
QString mcVersion;
QString filename;
// TODO requirements
// QMap<QString, QString> requirements;
QString id;
QString mainClass;
QString overwriteMinecraftArguments;
@ -216,6 +224,12 @@ struct VersionFile
}
}
out.name = root.value("name").toString();
out.fileId = root.value("id").toString();
out.version = root.value("version").toString();
out.mcVersion = root.value("mcVersion").toString();
out.filename = filename;
auto readString = [root, filename](const QString &key, QString &variable)
{
if (root.contains(key))
@ -661,6 +675,14 @@ struct VersionFile
}
}
OneSixVersion::VersionFile versionFile;
versionFile.name = name;
versionFile.id = fileId;
versionFile.version = this->version;
versionFile.mcVersion = mcVersion;
versionFile.filename = filename;
version->versionFiles.append(versionFile);
isError = false;
}
};
@ -727,6 +749,10 @@ bool OneSixVersionBuilder::build(const bool excludeCustom)
{
return false;
}
file.name = "version.json";
file.fileId = "org.multimc.version.json";
file.version = m_instance->intendedVersionId();
file.mcVersion = m_instance->intendedVersionId();
bool isError = false;
file.applyTo(m_version, isError);
if (isError)
@ -773,17 +799,21 @@ bool OneSixVersionBuilder::build(const bool excludeCustom)
}
}
// instance.json
// user.json
if (!excludeCustom)
{
if (QFile::exists(root.absoluteFilePath("instance.json")))
if (QFile::exists(root.absoluteFilePath("user.json")))
{
QLOG_INFO() << "Reading instance.json";
QLOG_INFO() << "Reading user.json";
VersionFile file;
if (!read(QFileInfo(root.absoluteFilePath("instance.json")), false, &file))
if (!read(QFileInfo(root.absoluteFilePath("user.json")), false, &file))
{
return false;
}
file.name = "user.json";
file.fileId = "org.multimc.user.json";
file.version = QString();
file.mcVersion = QString();
bool isError = false;
file.applyTo(m_version, isError);
if (isError)
@ -792,7 +822,7 @@ bool OneSixVersionBuilder::build(const bool excludeCustom)
m_widgetParent, QObject::tr("Error"),
QObject::tr(
"Error while applying %1. Please check MultiMC-0.log for more info.")
.arg(root.absoluteFilePath("instance.json")));
.arg(root.absoluteFilePath("user.json")));
return false;
}
}