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

@ -55,6 +55,8 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent)
main_model->setSourceModel(m_version.get()); main_model->setSourceModel(m_version.get());
ui->libraryTreeView->setModel(main_model); ui->libraryTreeView->setModel(main_model);
ui->libraryTreeView->installEventFilter(this); ui->libraryTreeView->installEventFilter(this);
connect(ui->libraryTreeView->selectionModel(), &QItemSelectionModel::currentChanged,
this, &OneSixModEditDialog::versionCurrent);
updateVersionControls(); updateVersionControls();
} }
else else
@ -93,10 +95,8 @@ OneSixModEditDialog::~OneSixModEditDialog()
void OneSixModEditDialog::updateVersionControls() void OneSixModEditDialog::updateVersionControls()
{ {
bool customVersion = m_inst->versionIsCustom();
ui->forgeBtn->setEnabled(true); ui->forgeBtn->setEnabled(true);
ui->liteloaderBtn->setEnabled(LiteLoaderInstaller().canApply(m_inst)); ui->liteloaderBtn->setEnabled(LiteLoaderInstaller().canApply(m_inst));
ui->customEditorBtn->setEnabled(customVersion);
ui->mainClassEdit->setText(m_version->mainClass); ui->mainClassEdit->setText(m_version->mainClass);
} }
@ -104,23 +104,52 @@ void OneSixModEditDialog::disableVersionControls()
{ {
ui->forgeBtn->setEnabled(false); ui->forgeBtn->setEnabled(false);
ui->liteloaderBtn->setEnabled(false); ui->liteloaderBtn->setEnabled(false);
ui->customEditorBtn->setEnabled(false); ui->reloadLibrariesBtn->setEnabled(false);
ui->removeLibraryBtn->setEnabled(false);
ui->mainClassEdit->setText(""); ui->mainClassEdit->setText("");
} }
void OneSixModEditDialog::on_customEditorBtn_clicked() void OneSixModEditDialog::on_userEditorBtn_clicked()
{ {
if (QDir(m_inst->instanceRoot()).exists("custom.json")) if (QDir(m_inst->instanceRoot()).exists("user.json"))
{ {
if (!MMC->openJsonEditor(m_inst->instanceRoot() + "/custom.json")) if (!MMC->openJsonEditor(m_inst->instanceRoot() + "/user.json"))
{ {
QMessageBox::warning(this, tr("Error"), tr("Unable to open custom.json, check the settings")); QMessageBox::warning(this, tr("Error"), tr("Unable to open user.json, check the settings"));
}
}
}
void OneSixModEditDialog::on_reloadLibrariesBtn_clicked()
{
m_inst->reloadVersion(this);
}
void OneSixModEditDialog::on_removeLibraryBtn_clicked()
{
if (ui->libraryTreeView->currentIndex().isValid())
{
if (!m_version->remove(ui->libraryTreeView->currentIndex().row()))
{
QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file"));
}
else
{
m_inst->reloadVersion(this);
} }
} }
} }
void OneSixModEditDialog::on_forgeBtn_clicked() void OneSixModEditDialog::on_forgeBtn_clicked()
{ {
if (QDir(m_inst->instanceRoot()).exists("custom.json"))
{
if (QMessageBox::question(this, tr("Revert?"), tr("This action will remove your custom.json. Continue?")) != QMessageBox::Yes)
{
return;
}
QDir(m_inst->instanceRoot()).remove("custom.json");
}
VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this);
vselect.setFilter(1, m_inst->currentVersionId()); vselect.setFilter(1, m_inst->currentVersionId());
if (vselect.exec() && vselect.selectedVersion()) if (vselect.exec() && vselect.selectedVersion())
@ -167,6 +196,14 @@ void OneSixModEditDialog::on_forgeBtn_clicked()
void OneSixModEditDialog::on_liteloaderBtn_clicked() void OneSixModEditDialog::on_liteloaderBtn_clicked()
{ {
if (QDir(m_inst->instanceRoot()).exists("custom.json"))
{
if (QMessageBox::question(this, tr("Revert?"), tr("This action will remove your custom.json. Continue?")) != QMessageBox::Yes)
{
return;
}
QDir(m_inst->instanceRoot()).remove("custom.json");
}
LiteLoaderInstaller liteloader; LiteLoaderInstaller liteloader;
if (!liteloader.canApply(m_inst)) if (!liteloader.canApply(m_inst))
{ {
@ -304,3 +341,15 @@ void OneSixModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previou
Mod &m = m_mods->operator[](row); Mod &m = m_mods->operator[](row);
ui->frame->updateWithMod(m); ui->frame->updateWithMod(m);
} }
void OneSixModEditDialog::versionCurrent(const QModelIndex &current, const QModelIndex &previous)
{
if (!current.isValid())
{
ui->removeLibraryBtn->setDisabled(true);
}
else
{
ui->removeLibraryBtn->setEnabled(m_version->canRemove(current.row()));
}
}

View File

@ -45,7 +45,9 @@ slots:
void on_buttonBox_rejected(); void on_buttonBox_rejected();
void on_forgeBtn_clicked(); void on_forgeBtn_clicked();
void on_liteloaderBtn_clicked(); void on_liteloaderBtn_clicked();
void on_customEditorBtn_clicked(); void on_userEditorBtn_clicked();
void on_reloadLibrariesBtn_clicked();
void on_removeLibraryBtn_clicked();
void updateVersionControls(); void updateVersionControls();
void disableVersionControls(); void disableVersionControls();
@ -64,4 +66,5 @@ private:
public public
slots: slots:
void loaderCurrent(QModelIndex current, QModelIndex previous); void loaderCurrent(QModelIndex current, QModelIndex previous);
void versionCurrent(const QModelIndex &current, const QModelIndex &previous);
}; };

View File

@ -26,7 +26,7 @@
</size> </size>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="libTab"> <widget class="QWidget" name="libTab">
<attribute name="title"> <attribute name="title">
@ -35,13 +35,6 @@
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_10"> <layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Tweakers:</string>
</property>
</widget>
</item>
<item> <item>
<widget class="ModListView" name="libraryTreeView"> <widget class="ModListView" name="libraryTreeView">
<property name="verticalScrollBarPolicy"> <property name="verticalScrollBarPolicy">
@ -51,7 +44,7 @@
<enum>Qt::ScrollBarAlwaysOff</enum> <enum>Qt::ScrollBarAlwaysOff</enum>
</property> </property>
<attribute name="headerVisible"> <attribute name="headerVisible">
<bool>false</bool> <bool>true</bool>
</attribute> </attribute>
</widget> </widget>
</item> </item>
@ -96,37 +89,22 @@
</item> </item>
<item> <item>
<widget class="Line" name="line"> <widget class="Line" name="line">
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="addLibraryBtn"> <widget class="QPushButton" name="reloadLibrariesBtn">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Add new libraries</string>
</property>
<property name="text"> <property name="text">
<string>&amp;Add</string> <string>Reload</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="removeLibraryBtn"> <widget class="QPushButton" name="removeLibraryBtn">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Remove selected libraries</string>
</property>
<property name="text"> <property name="text">
<string>&amp;Remove</string> <string>Remove</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -138,9 +116,9 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="customEditorBtn"> <widget class="QPushButton" name="userEditorBtn">
<property name="text"> <property name="text">
<string>Open custom.json</string> <string>Open user.json</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -74,6 +74,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url)
QJsonObject installObj = installVal.toObject(); QJsonObject installObj = installVal.toObject();
QString libraryName = installObj.value("path").toString(); QString libraryName = installObj.value("path").toString();
internalPath = installObj.value("filePath").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 // where do we put the library? decode the mojang path
OneSixLibrary lib(libraryName); 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())); QFile file(filename(to->instanceRoot()));
if (!file.open(QFile::WriteOnly)) if (!file.open(QFile::WriteOnly))
{ {

View File

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

View File

@ -78,6 +78,10 @@ bool LiteLoaderInstaller::add(OneSixInstance *to)
} }
obj.insert("+libraries", libraries); 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())); QFile file(filename(to->instanceRoot()));
if (!file.open(QFile::WriteOnly)) if (!file.open(QFile::WriteOnly))

View File

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

View File

@ -16,6 +16,7 @@
#include "OneSixVersion.h" #include "OneSixVersion.h"
#include <QDebug> #include <QDebug>
#include <QFile>
#include "OneSixVersionBuilder.h" #include "OneSixVersionBuilder.h"
@ -47,6 +48,7 @@ void OneSixVersion::clear()
mainClass.clear(); mainClass.clear();
libraries.clear(); libraries.clear();
tweakers.clear(); tweakers.clear();
versionFiles.clear();
endResetModel(); endResetModel();
} }
@ -70,6 +72,24 @@ void OneSixVersion::dump() const
qDebug().nospace() << "\n)"; 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> > OneSixVersion::getActiveNormalLibs()
{ {
QList<std::shared_ptr<OneSixLibrary> > output; QList<std::shared_ptr<OneSixLibrary> > output;
@ -114,14 +134,39 @@ QVariant OneSixVersion::data(const QModelIndex &index, int role) const
int row = index.row(); int row = index.row();
int column = index.column(); int column = index.column();
if (row < 0 || row >= tweakers.size()) if (row < 0 || row >= versionFiles.size())
return QVariant(); return QVariant();
if (role == Qt::DisplayRole) 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(); return QVariant();
@ -136,12 +181,12 @@ Qt::ItemFlags OneSixVersion::flags(const QModelIndex &index) const
int OneSixVersion::rowCount(const QModelIndex &parent) const int OneSixVersion::rowCount(const QModelIndex &parent) const
{ {
return tweakers.size(); return versionFiles.size();
} }
int OneSixVersion::columnCount(const QModelIndex &parent) const int OneSixVersion::columnCount(const QModelIndex &parent) const
{ {
return 1; return 2;
} }
QDebug operator<<(QDebug &dbg, const OneSixVersion *version) QDebug operator<<(QDebug &dbg, const OneSixVersion *version)

View File

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

View File

@ -34,6 +34,14 @@
struct VersionFile struct VersionFile
{ {
int order; 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 id;
QString mainClass; QString mainClass;
QString overwriteMinecraftArguments; 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) auto readString = [root, filename](const QString &key, QString &variable)
{ {
if (root.contains(key)) 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; isError = false;
} }
}; };
@ -727,6 +749,10 @@ bool OneSixVersionBuilder::build(const bool excludeCustom)
{ {
return false; 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; bool isError = false;
file.applyTo(m_version, isError); file.applyTo(m_version, isError);
if (isError) if (isError)
@ -773,17 +799,21 @@ bool OneSixVersionBuilder::build(const bool excludeCustom)
} }
} }
// instance.json // user.json
if (!excludeCustom) 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; VersionFile file;
if (!read(QFileInfo(root.absoluteFilePath("instance.json")), false, &file)) if (!read(QFileInfo(root.absoluteFilePath("user.json")), false, &file))
{ {
return false; return false;
} }
file.name = "user.json";
file.fileId = "org.multimc.user.json";
file.version = QString();
file.mcVersion = QString();
bool isError = false; bool isError = false;
file.applyTo(m_version, isError); file.applyTo(m_version, isError);
if (isError) if (isError)
@ -792,7 +822,7 @@ bool OneSixVersionBuilder::build(const bool excludeCustom)
m_widgetParent, QObject::tr("Error"), m_widgetParent, QObject::tr("Error"),
QObject::tr( QObject::tr(
"Error while applying %1. Please check MultiMC-0.log for more info.") "Error while applying %1. Please check MultiMC-0.log for more info.")
.arg(root.absoluteFilePath("instance.json"))); .arg(root.absoluteFilePath("user.json")));
return false; return false;
} }
} }