diff --git a/gui/dialogs/OneSixModEditDialog.cpp b/gui/dialogs/OneSixModEditDialog.cpp
index ad15311b..a34409f5 100644
--- a/gui/dialogs/OneSixModEditDialog.cpp
+++ b/gui/dialogs/OneSixModEditDialog.cpp
@@ -55,6 +55,8 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent)
main_model->setSourceModel(m_version.get());
ui->libraryTreeView->setModel(main_model);
ui->libraryTreeView->installEventFilter(this);
+ connect(ui->libraryTreeView->selectionModel(), &QItemSelectionModel::currentChanged,
+ this, &OneSixModEditDialog::versionCurrent);
updateVersionControls();
}
else
@@ -93,10 +95,8 @@ OneSixModEditDialog::~OneSixModEditDialog()
void OneSixModEditDialog::updateVersionControls()
{
- bool customVersion = m_inst->versionIsCustom();
ui->forgeBtn->setEnabled(true);
ui->liteloaderBtn->setEnabled(LiteLoaderInstaller().canApply(m_inst));
- ui->customEditorBtn->setEnabled(customVersion);
ui->mainClassEdit->setText(m_version->mainClass);
}
@@ -104,23 +104,52 @@ void OneSixModEditDialog::disableVersionControls()
{
ui->forgeBtn->setEnabled(false);
ui->liteloaderBtn->setEnabled(false);
- ui->customEditorBtn->setEnabled(false);
+ ui->reloadLibrariesBtn->setEnabled(false);
+ ui->removeLibraryBtn->setEnabled(false);
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()
{
+ 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);
vselect.setFilter(1, m_inst->currentVersionId());
if (vselect.exec() && vselect.selectedVersion())
@@ -167,6 +196,14 @@ void OneSixModEditDialog::on_forgeBtn_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;
if (!liteloader.canApply(m_inst))
{
@@ -304,3 +341,15 @@ void OneSixModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previou
Mod &m = m_mods->operator[](row);
ui->frame->updateWithMod(m);
}
+
+void OneSixModEditDialog::versionCurrent(const QModelIndex ¤t, const QModelIndex &previous)
+{
+ if (!current.isValid())
+ {
+ ui->removeLibraryBtn->setDisabled(true);
+ }
+ else
+ {
+ ui->removeLibraryBtn->setEnabled(m_version->canRemove(current.row()));
+ }
+}
diff --git a/gui/dialogs/OneSixModEditDialog.h b/gui/dialogs/OneSixModEditDialog.h
index 161604c9..7e759f48 100644
--- a/gui/dialogs/OneSixModEditDialog.h
+++ b/gui/dialogs/OneSixModEditDialog.h
@@ -45,7 +45,9 @@ slots:
void on_buttonBox_rejected();
void on_forgeBtn_clicked();
void on_liteloaderBtn_clicked();
- void on_customEditorBtn_clicked();
+ void on_userEditorBtn_clicked();
+ void on_reloadLibrariesBtn_clicked();
+ void on_removeLibraryBtn_clicked();
void updateVersionControls();
void disableVersionControls();
@@ -64,4 +66,5 @@ private:
public
slots:
void loaderCurrent(QModelIndex current, QModelIndex previous);
+ void versionCurrent(const QModelIndex ¤t, const QModelIndex &previous);
};
diff --git a/gui/dialogs/OneSixModEditDialog.ui b/gui/dialogs/OneSixModEditDialog.ui
index 67642c23..d90c6d93 100644
--- a/gui/dialogs/OneSixModEditDialog.ui
+++ b/gui/dialogs/OneSixModEditDialog.ui
@@ -26,7 +26,7 @@
- 1
+ 0
@@ -35,13 +35,6 @@
-
-
-
-
-
- Tweakers:
-
-
-
-
@@ -51,7 +44,7 @@
Qt::ScrollBarAlwaysOff
- false
+ true
@@ -96,37 +89,22 @@
-
-
- QFrame::Sunken
-
Qt::Horizontal
-
-
-
- false
-
-
- Add new libraries
-
+
- &Add
+ Reload
-
-
- false
-
-
- Remove selected libraries
-
- &Remove
+ Remove
@@ -138,9 +116,9 @@
-
-
+
- Open custom.json
+ Open user.json
diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp
index 8d2445ed..c7160d6e 100644
--- a/logic/ForgeInstaller.cpp
+++ b/logic/ForgeInstaller.cpp
@@ -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))
{
diff --git a/logic/ForgeInstaller.h b/logic/ForgeInstaller.h
index eb8ecd79..c5052092 100644
--- a/logic/ForgeInstaller.h
+++ b/logic/ForgeInstaller.h
@@ -37,5 +37,6 @@ private:
QString internalPath;
QString finalPath;
QString realVersionId;
+ QString m_forgeVersionString;
QString m_universal_url;
};
diff --git a/logic/LiteLoaderInstaller.cpp b/logic/LiteLoaderInstaller.cpp
index f658f834..48bbaeff 100644
--- a/logic/LiteLoaderInstaller.cpp
+++ b/logic/LiteLoaderInstaller.cpp
@@ -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))
diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp
index 19d5e112..88c40316 100644
--- a/logic/OneSixInstance.cpp
+++ b/logic/OneSixInstance.cpp
@@ -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
diff --git a/logic/OneSixVersion.cpp b/logic/OneSixVersion.cpp
index 1abd5114..0b6d1986 100644
--- a/logic/OneSixVersion.cpp
+++ b/logic/OneSixVersion.cpp
@@ -16,6 +16,7 @@
#include "OneSixVersion.h"
#include
+#include
#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 > OneSixVersion::getActiveNormalLibs()
{
QList > 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)
diff --git a/logic/OneSixVersion.h b/logic/OneSixVersion.h
index 98a4b418..d7a6684d 100644
--- a/logic/OneSixVersion.h
+++ b/logic/OneSixVersion.h
@@ -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> getActiveNormalLibs();
QList> getActiveNativeLibs();
@@ -109,6 +116,16 @@ public:
*/
// QList rules;
+ struct VersionFile
+ {
+ QString name;
+ QString id;
+ QString version;
+ QString mcVersion;
+ QString filename;
+ };
+ QList versionFiles;
+
private:
OneSixInstance *m_instance;
};
diff --git a/logic/OneSixVersionBuilder.cpp b/logic/OneSixVersionBuilder.cpp
index a8e7253b..08506d4b 100644
--- a/logic/OneSixVersionBuilder.cpp
+++ b/logic/OneSixVersionBuilder.cpp
@@ -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 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;
}
}