Merge branch 'feature_derpstances' of https://github.com/02JanDal/MultiMC5 into feature_derpstances

Conflicts:
	gui/dialogs/OneSixModEditDialog.cpp
	logic/OneSixUpdate.cpp
This commit is contained in:
Petr Mrázek
2014-02-01 19:37:16 +01:00
24 changed files with 1596 additions and 606 deletions

View File

@ -55,7 +55,8 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent)
main_model->setSourceModel(m_version.get());
ui->libraryTreeView->setModel(main_model);
ui->libraryTreeView->installEventFilter(this);
ui->mainClassEdit->setText(m_version->mainClass);
connect(ui->libraryTreeView->selectionModel(), &QItemSelectionModel::currentChanged,
this, &OneSixModEditDialog::versionCurrent);
updateVersionControls();
}
else
@ -81,6 +82,8 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent)
ui->resPackTreeView->installEventFilter(this);
m_resourcepacks->startWatching();
}
connect(m_inst, &OneSixInstance::versionReloaded, this, &OneSixModEditDialog::updateVersionControls);
}
OneSixModEditDialog::~OneSixModEditDialog()
@ -92,98 +95,76 @@ OneSixModEditDialog::~OneSixModEditDialog()
void OneSixModEditDialog::updateVersionControls()
{
bool customVersion = m_inst->versionIsCustom();
ui->customizeBtn->setEnabled(!customVersion);
ui->revertBtn->setEnabled(customVersion);
ui->forgeBtn->setEnabled(true);
ui->liteloaderBtn->setEnabled(LiteLoaderInstaller(m_inst->intendedVersionId()).canApply());
ui->customEditorBtn->setEnabled(customVersion);
ui->liteloaderBtn->setEnabled(LiteLoaderInstaller().canApply(m_inst));
ui->mainClassEdit->setText(m_version->mainClass);
}
void OneSixModEditDialog::disableVersionControls()
{
ui->customizeBtn->setEnabled(false);
ui->revertBtn->setEnabled(false);
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_customizeBtn_clicked()
void OneSixModEditDialog::on_userEditorBtn_clicked()
{
if (m_inst->customizeVersion())
QDir root(m_inst->instanceRoot());
if (!root.exists("user.json"))
{
m_version = m_inst->getFullVersion();
main_model->setSourceModel(m_version.get());
updateVersionControls();
}
}
void OneSixModEditDialog::on_revertBtn_clicked()
{
auto response = CustomMessageBox::selectable(
this, tr("Revert?"), tr("Do you want to revert the "
"version of this instance to its original configuration?"),
QMessageBox::Question, QMessageBox::Yes | QMessageBox::No)->exec();
if (response == QMessageBox::Yes)
{
if (m_inst->revertCustomVersion())
QFile file(root.absoluteFilePath("user.json"));
if (!file.open(QFile::WriteOnly))
{
m_version = m_inst->getFullVersion();
main_model->setSourceModel(m_version.get());
updateVersionControls();
QMessageBox::critical(this, tr("Error"), tr("Couldn't write a skeletion user.json file: %1").arg(file.errorString()));
return;
}
file.write("{\n}");
file.close();
}
if (!MMC->openJsonEditor(root.absoluteFilePath("user.json")))
{
QMessageBox::warning(this, tr("Error"), tr("Unable to open user.json, check the settings"));
}
}
void OneSixModEditDialog::on_customEditorBtn_clicked()
void OneSixModEditDialog::on_reloadLibrariesBtn_clicked()
{
if (m_inst->versionIsCustom())
m_inst->reloadVersion(this);
}
void OneSixModEditDialog::on_removeLibraryBtn_clicked()
{
if (ui->libraryTreeView->currentIndex().isValid())
{
if (!MMC->openJsonEditor(m_inst->instanceRoot() + "/custom.json"))
if (!m_version->remove(ui->libraryTreeView->currentIndex().row()))
{
QMessageBox::warning(this, tr("Error"),
tr("Unable to open custom.json, check the settings"));
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());
vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") +
m_inst->currentVersionId());
if (vselect.exec() && vselect.selectedVersion())
{
if (m_inst->versionIsCustom())
{
auto reply = QMessageBox::question(
this, tr("Revert?"),
tr("This will revert any "
"changes you did to the version up to this point. Is that "
"OK?"),
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes)
{
m_inst->revertCustomVersion();
m_inst->customizeVersion();
{
m_version = m_inst->getFullVersion();
main_model->setSourceModel(m_version.get());
updateVersionControls();
}
}
else
return;
}
else
{
m_inst->customizeVersion();
m_version = m_inst->getFullVersion();
main_model->setSourceModel(m_version.get());
updateVersionControls();
}
ForgeVersionPtr forgeVersion =
std::dynamic_pointer_cast<ForgeVersion>(vselect.selectedVersion());
if (!forgeVersion)
@ -200,9 +181,9 @@ void OneSixModEditDialog::on_forgeBtn_clicked()
// install
QString forgePath = entry->getFullPath();
ForgeInstaller forge(forgePath, forgeVersion->universal_url);
if (!forge.apply(m_version))
if (!forge.add(m_inst))
{
// failure notice
QLOG_ERROR() << "Failure installing forge";
}
}
else
@ -215,18 +196,27 @@ void OneSixModEditDialog::on_forgeBtn_clicked()
// install
QString forgePath = entry->getFullPath();
ForgeInstaller forge(forgePath, forgeVersion->universal_url);
if (!forge.apply(m_version))
if (!forge.add(m_inst))
{
// failure notice
QLOG_ERROR() << "Failure installing forge";
}
}
}
m_inst->reloadVersion(this);
}
void OneSixModEditDialog::on_liteloaderBtn_clicked()
{
LiteLoaderInstaller liteloader(m_inst->intendedVersionId());
if (!liteloader.canApply())
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))
{
QMessageBox::critical(
this, tr("LiteLoader"),
@ -234,19 +224,16 @@ void OneSixModEditDialog::on_liteloaderBtn_clicked()
"into this version of Minecraft"));
return;
}
if (!m_inst->versionIsCustom())
{
m_inst->customizeVersion();
m_version = m_inst->getFullVersion();
main_model->setSourceModel(m_version.get());
updateVersionControls();
}
if (!liteloader.apply(m_version))
if (!liteloader.add(m_inst))
{
QMessageBox::critical(this, tr("LiteLoader"),
tr("For reasons unknown, the LiteLoader installation failed. "
"Check your MultiMC log files for details."));
}
else
{
m_inst->reloadVersion(this);
}
}
bool OneSixModEditDialog::loaderListFilter(QKeyEvent *keyEvent)
@ -365,3 +352,15 @@ void OneSixModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previou
Mod &m = m_mods->operator[](row);
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,9 +45,9 @@ slots:
void on_buttonBox_rejected();
void on_forgeBtn_clicked();
void on_liteloaderBtn_clicked();
void on_customizeBtn_clicked();
void on_revertBtn_clicked();
void on_customEditorBtn_clicked();
void on_userEditorBtn_clicked();
void on_reloadLibrariesBtn_clicked();
void on_removeLibraryBtn_clicked();
void updateVersionControls();
void disableVersionControls();
@ -66,4 +66,5 @@ private:
public
slots:
void loaderCurrent(QModelIndex current, QModelIndex previous);
void versionCurrent(const QModelIndex &current, const QModelIndex &previous);
};

View File

@ -26,7 +26,7 @@
</size>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="libTab">
<attribute name="title">
@ -43,6 +43,9 @@
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<attribute name="headerVisible">
<bool>true</bool>
</attribute>
</widget>
</item>
<item>
@ -84,62 +87,24 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="customizeBtn">
<property name="toolTip">
<string>Create an customized copy of the base version</string>
</property>
<property name="text">
<string>Customize</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="revertBtn">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Revert to original base version</string>
</property>
<property name="text">
<string>Revert</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="addLibraryBtn">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Add new libraries</string>
</property>
<widget class="QPushButton" name="reloadLibrariesBtn">
<property name="text">
<string>&amp;Add</string>
<string>Reload</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeLibraryBtn">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Remove selected libraries</string>
</property>
<property name="text">
<string>&amp;Remove</string>
<string>Remove</string>
</property>
</widget>
</item>
@ -151,9 +116,9 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="customEditorBtn">
<widget class="QPushButton" name="userEditorBtn">
<property name="text">
<string>Open custom.json</string>
<string>Open user.json</string>
</property>
</widget>
</item>