Add instance copying, fix instance creation (with identical names)

This commit is contained in:
Petr Mrázek 2013-11-03 21:28:04 +01:00
parent ab21b6977d
commit 4466929074
13 changed files with 495 additions and 90 deletions

View File

@ -183,6 +183,8 @@ gui/mainwindow.h
gui/mainwindow.cpp gui/mainwindow.cpp
gui/settingsdialog.h gui/settingsdialog.h
gui/settingsdialog.cpp gui/settingsdialog.cpp
gui/CopyInstanceDialog.h
gui/CopyInstanceDialog.cpp
gui/newinstancedialog.h gui/newinstancedialog.h
gui/newinstancedialog.cpp gui/newinstancedialog.cpp
gui/logindialog.h gui/logindialog.h
@ -332,6 +334,7 @@ logic/NagUtils.cpp
SET(MULTIMC_UIS SET(MULTIMC_UIS
gui/mainwindow.ui gui/mainwindow.ui
gui/settingsdialog.ui gui/settingsdialog.ui
gui/CopyInstanceDialog.ui
gui/newinstancedialog.ui gui/newinstancedialog.ui
gui/logindialog.ui gui/logindialog.ui
gui/aboutdialog.ui gui/aboutdialog.ui

View File

@ -149,3 +149,5 @@ void openFileInDefaultProgram ( QString filename )
{ {
QDesktopServices::openUrl ( "file:///" + QFileInfo ( filename ).absolutePath() ); QDesktopServices::openUrl ( "file:///" + QFileInfo ( filename ).absolutePath() );
} }

View File

@ -0,0 +1,84 @@
/* Copyright 2013 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <MultiMC.h>
#include "CopyInstanceDialog.h"
#include "ui_CopyInstanceDialog.h"
#include "logic/InstanceFactory.h"
#include "logic/BaseVersion.h"
#include "logic/lists/IconList.h"
#include "logic/lists/MinecraftVersionList.h"
#include "logic/tasks/Task.h"
#include <logic/BaseInstance.h>
#include "gui/platform.h"
#include "versionselectdialog.h"
#include "ProgressDialog.h"
#include "IconPickerDialog.h"
#include <QLayout>
#include <QPushButton>
CopyInstanceDialog::CopyInstanceDialog(BaseInstance *original, QWidget *parent)
: m_original(original), QDialog(parent), ui(new Ui::CopyInstanceDialog)
{
MultiMCPlatform::fixWM_CLASS(this);
ui->setupUi(this);
resize(minimumSizeHint());
layout()->setSizeConstraint(QLayout::SetFixedSize);
InstIconKey = original->iconKey();
ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey));
ui->instNameTextBox->setText(original->name());
ui->instNameTextBox->setFocus();
}
CopyInstanceDialog::~CopyInstanceDialog()
{
delete ui;
}
void CopyInstanceDialog::updateDialogState()
{
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!instName().isEmpty());
}
QString CopyInstanceDialog::instName() const
{
return ui->instNameTextBox->text();
}
QString CopyInstanceDialog::iconKey() const
{
return InstIconKey;
}
void CopyInstanceDialog::on_iconButton_clicked()
{
IconPickerDialog dlg(this);
dlg.exec(InstIconKey);
if (dlg.result() == QDialog::Accepted)
{
InstIconKey = dlg.selectedIconKey;
ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey));
}
}
void CopyInstanceDialog::on_instNameTextBox_textChanged(const QString &arg1)
{
updateDialogState();
}

50
gui/CopyInstanceDialog.h Normal file
View File

@ -0,0 +1,50 @@
/* Copyright 2013 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <QDialog>
#include "logic/BaseVersion.h"
class BaseInstance;
namespace Ui
{
class CopyInstanceDialog;
}
class CopyInstanceDialog : public QDialog
{
Q_OBJECT
public:
explicit CopyInstanceDialog(BaseInstance *original, QWidget *parent = 0);
~CopyInstanceDialog();
void updateDialogState();
QString instName() const;
QString iconKey() const;
private
slots:
void on_iconButton_clicked();
void on_instNameTextBox_textChanged(const QString &arg1);
private:
Ui::CopyInstanceDialog *ui;
QString InstIconKey;
BaseInstance *m_original;
};

134
gui/CopyInstanceDialog.ui Normal file
View File

@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CopyInstanceDialog</class>
<widget class="QDialog" name="CopyInstanceDialog">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>345</width>
<height>205</height>
</rect>
</property>
<property name="windowTitle">
<string>Copy Instance</string>
</property>
<property name="windowIcon">
<iconset resource="../multimc.qrc">
<normaloff>:/icons/toolbar/copy</normaloff>:/icons/toolbar/copy</iconset>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="iconBtnLayout">
<item>
<spacer name="iconBtnLeftSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="iconButton">
<property name="icon">
<iconset resource="../multimc.qrc">
<normaloff>:/icons/instances/infinity</normaloff>:/icons/instances/infinity</iconset>
</property>
<property name="iconSize">
<size>
<width>80</width>
<height>80</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="iconBtnRightSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLineEdit" name="instNameTextBox">
<property name="placeholderText">
<string>Name</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../multimc.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>CopyInstanceDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>CopyInstanceDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -74,6 +74,7 @@
#include "IconPickerDialog.h" #include "IconPickerDialog.h"
#include "LabeledToolButton.h" #include "LabeledToolButton.h"
#include "EditNotesDialog.h" #include "EditNotesDialog.h"
#include "CopyInstanceDialog.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{ {
@ -91,7 +92,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
// The instance action toolbar customizations // The instance action toolbar customizations
{ {
// disabled until we have an instance selected
ui->instanceToolBar->setEnabled(false); ui->instanceToolBar->setEnabled(false);
// the rename label is inside the rename tool button // the rename label is inside the rename tool button
renameButton = new LabeledToolButton(); renameButton = new LabeledToolButton();
renameButton->setText("Instance Name"); renameButton->setText("Instance Name");
@ -267,8 +270,9 @@ void MainWindow::on_actionAddInstance_triggered()
BaseInstance *newInstance = NULL; BaseInstance *newInstance = NULL;
QString instDirName = DirNameFromString(newInstDlg.instName()); QString instancesDir = MMC->settings()->get("InstanceDir").toString();
QString instDir = PathCombine(MMC->settings()->get("InstanceDir").toString(), instDirName); QString instDirName = DirNameFromString(newInstDlg.instName(), instancesDir);
QString instDir = PathCombine(instancesDir, instDirName);
auto &loader = InstanceFactory::get(); auto &loader = InstanceFactory::get();
@ -305,6 +309,56 @@ void MainWindow::on_actionAddInstance_triggered()
} }
} }
void MainWindow::on_actionCopyInstance_triggered()
{
if (!m_selectedInstance)
return;
CopyInstanceDialog copyInstDlg(m_selectedInstance, this);
if (!copyInstDlg.exec())
return;
QString instancesDir = MMC->settings()->get("InstanceDir").toString();
QString instDirName = DirNameFromString(copyInstDlg.instName(), instancesDir);
QString instDir = PathCombine(instancesDir, instDirName);
auto &loader = InstanceFactory::get();
BaseInstance *newInstance = NULL;
auto error = loader.copyInstance(newInstance, m_selectedInstance, instDir);
QString errorMsg = QString("Failed to create instance %1: ").arg(instDirName);
switch (error)
{
case InstanceFactory::NoCreateError:
newInstance->setName(copyInstDlg.instName());
newInstance->setIconKey(copyInstDlg.iconKey());
MMC->instances()->add(InstancePtr(newInstance));
return;
case InstanceFactory::InstExists:
{
errorMsg += "An instance with the given directory name already exists.";
CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show();
break;
}
case InstanceFactory::CantCreateDir:
{
errorMsg += "Failed to create the instance directory.";
CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show();
break;
}
default:
{
errorMsg += QString("Unknown instance loader error %1").arg(error);
CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show();
break;
}
}
}
void MainWindow::on_actionChangeInstIcon_triggered() void MainWindow::on_actionChangeInstIcon_triggered()
{ {
if (!m_selectedInstance) if (!m_selectedInstance)
@ -395,10 +449,10 @@ void MainWindow::on_actionDeleteInstance_triggered()
{ {
if (m_selectedInstance) if (m_selectedInstance)
{ {
auto response = CustomMessageBox::selectable(this, tr("CAREFUL"), auto response = CustomMessageBox::selectable(
tr("This is permanent! Are you sure?\nAbout to delete: ") this, tr("CAREFUL"), tr("This is permanent! Are you sure?\nAbout to delete: ") +
+ m_selectedInstance->name(), m_selectedInstance->name(),
QMessageBox::Question, QMessageBox::Yes | QMessageBox::No)->exec(); QMessageBox::Question, QMessageBox::Yes | QMessageBox::No)->exec();
if (response == QMessageBox::Yes) if (response == QMessageBox::Yes)
{ {
m_selectedInstance->nuke(); m_selectedInstance->nuke();
@ -640,7 +694,8 @@ void MainWindow::onGameUpdateComplete()
void MainWindow::onGameUpdateError(QString error) void MainWindow::onGameUpdateError(QString error)
{ {
CustomMessageBox::selectable(this, tr("Error updating instance"), error, QMessageBox::Warning)->show(); CustomMessageBox::selectable(this, tr("Error updating instance"), error,
QMessageBox::Warning)->show();
} }
void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response) void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response)
@ -709,9 +764,10 @@ void MainWindow::on_actionMakeDesktopShortcut_triggered()
QStringList() << "-dl" << QDir::currentPath() << "test", name, QStringList() << "-dl" << QDir::currentPath() << "test", name,
"application-x-octet-stream"); "application-x-octet-stream");
CustomMessageBox::selectable(this, tr("Not useful"), CustomMessageBox::selectable(
tr("A Dummy Shortcut was created. it will not do anything productive"), this, tr("Not useful"),
QMessageBox::Warning)->show(); tr("A Dummy Shortcut was created. it will not do anything productive"),
QMessageBox::Warning)->show();
} }
// BrowserDialog // BrowserDialog
@ -732,10 +788,11 @@ void MainWindow::on_actionChangeInstMCVersion_triggered()
{ {
if (m_selectedInstance->versionIsCustom()) if (m_selectedInstance->versionIsCustom())
{ {
auto result = CustomMessageBox::selectable(this, tr("Are you sure?"), auto result = CustomMessageBox::selectable(
tr("This will remove any library/version customization you did previously. " this, tr("Are you sure?"),
"This includes things like Forge install and similar."), tr("This will remove any library/version customization you did previously. "
QMessageBox::Warning, QMessageBox::Ok, QMessageBox::Abort)->exec(); "This includes things like Forge install and similar."),
QMessageBox::Warning, QMessageBox::Ok, QMessageBox::Abort)->exec();
if (result != QMessageBox::Ok) if (result != QMessageBox::Ok)
return; return;
@ -867,11 +924,12 @@ void MainWindow::checkSetDefaultJava()
java = std::dynamic_pointer_cast<JavaVersion>(vselect.selectedVersion()); java = std::dynamic_pointer_cast<JavaVersion>(vselect.selectedVersion());
else else
{ {
CustomMessageBox::selectable(this, tr("Invalid version selected"), CustomMessageBox::selectable(
tr("You didn't select a valid Java version, so MultiMC will " this, tr("Invalid version selected"),
"select the default. " tr("You didn't select a valid Java version, so MultiMC will "
"You can change this in the settings dialog."), "select the default. "
QMessageBox::Warning)->show(); "You can change this in the settings dialog."),
QMessageBox::Warning)->show();
JavaUtils ju; JavaUtils ju;
java = ju.GetDefaultJava(); java = ju.GetDefaultJava();

View File

@ -22,6 +22,7 @@
#include "logic/net/LoginTask.h" #include "logic/net/LoginTask.h"
#include "logic/BaseInstance.h" #include "logic/BaseInstance.h"
class QToolButton;
class LabeledToolButton; class LabeledToolButton;
class QLabel; class QLabel;
class InstanceProxyModel; class InstanceProxyModel;
@ -51,13 +52,16 @@ public:
void checkSetDefaultJava(); void checkSetDefaultJava();
private slots: private
slots:
void onCatToggled(bool); void onCatToggled(bool);
void on_actionAbout_triggered(); void on_actionAbout_triggered();
void on_actionAddInstance_triggered(); void on_actionAddInstance_triggered();
void on_actionCopyInstance_triggered();
void on_actionChangeInstGroup_triggered(); void on_actionChangeInstGroup_triggered();
void on_actionChangeInstIcon_triggered(); void on_actionChangeInstIcon_triggered();
@ -122,7 +126,8 @@ private slots:
void assetsFailed(); void assetsFailed();
void assetsFinished(); void assetsFinished();
public slots: public
slots:
void instanceActivated(QModelIndex); void instanceActivated(QModelIndex);
void instanceChanged(const QModelIndex &current, const QModelIndex &previous); void instanceChanged(const QModelIndex &current, const QModelIndex &previous);
@ -146,6 +151,7 @@ private:
ConsoleWindow *console; ConsoleWindow *console;
OneSixAssets *assets_downloader; OneSixAssets *assets_downloader;
LabeledToolButton *renameButton; LabeledToolButton *renameButton;
QToolButton *changeIconButton;
BaseInstance *m_selectedInstance; BaseInstance *m_selectedInstance;

View File

@ -62,6 +62,8 @@
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<addaction name="actionAddInstance"/> <addaction name="actionAddInstance"/>
<addaction name="actionCopyInstance"/>
<addaction name="separator"/>
<addaction name="actionViewInstanceFolder"/> <addaction name="actionViewInstanceFolder"/>
<addaction name="actionViewCentralModsFolder"/> <addaction name="actionViewCentralModsFolder"/>
<addaction name="actionRefresh"/> <addaction name="actionRefresh"/>
@ -310,6 +312,9 @@
<property name="statusTip"> <property name="statusTip">
<string>Change the selected instance's icon.</string> <string>Change the selected instance's icon.</string>
</property> </property>
<property name="iconVisibleInMenu">
<bool>true</bool>
</property>
</action> </action>
<action name="actionEditInstNotes"> <action name="actionEditInstNotes">
<property name="text"> <property name="text">
@ -445,6 +450,21 @@
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-weight:600; color:#ff0004;&quot;&gt;Catnarok!&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;Or just a cat with a ball of yarn?&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;WHO KNOWS?!&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;:/icons/instances/tnt&quot;/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-weight:600; color:#ff0004;&quot;&gt;Catnarok!&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;Or just a cat with a ball of yarn?&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;WHO KNOWS?!&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;img src=&quot;:/icons/instances/tnt&quot;/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
</action> </action>
<action name="actionCopyInstance">
<property name="icon">
<iconset resource="../multimc.qrc">
<normaloff>:/icons/toolbar/copy</normaloff>:/icons/toolbar/copy</iconset>
</property>
<property name="text">
<string>Copy Instance</string>
</property>
<property name="toolTip">
<string>Copy the selected instance.</string>
</property>
<property name="statusTip">
<string>Add a new instance.</string>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<resources> <resources>

View File

@ -13,13 +13,13 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef NEWINSTANCEDIALOG_H #pragma once
#define NEWINSTANCEDIALOG_H
#include <QDialog> #include <QDialog>
#include "logic/BaseVersion.h" #include "logic/BaseVersion.h"
namespace Ui { namespace Ui
{
class NewInstanceDialog; class NewInstanceDialog;
} }
@ -41,7 +41,8 @@ public:
QString iconKey() const; QString iconKey() const;
BaseVersionPtr selectedVersion() const; BaseVersionPtr selectedVersion() const;
private slots: private
slots:
void on_btnChangeVersion_clicked(); void on_btnChangeVersion_clicked();
void on_iconButton_clicked(); void on_iconButton_clicked();
void on_instNameTextBox_textChanged(const QString &arg1); void on_instNameTextBox_textChanged(const QString &arg1);
@ -52,5 +53,3 @@ private:
BaseVersionPtr m_selectedVersion; BaseVersionPtr m_selectedVersion;
QString InstIconKey; QString InstIconKey;
}; };
#endif // NEWINSTANCEDIALOG_H

View File

@ -34,13 +34,12 @@
InstanceFactory InstanceFactory::loader; InstanceFactory InstanceFactory::loader;
InstanceFactory::InstanceFactory() : InstanceFactory::InstanceFactory() : QObject(NULL)
QObject(NULL)
{ {
} }
InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst, const QString &instDir) InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst,
const QString &instDir)
{ {
auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg")); auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg"));
@ -48,16 +47,16 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst
QString inst_type = m_settings->get("InstanceType").toString(); QString inst_type = m_settings->get("InstanceType").toString();
//FIXME: replace with a map lookup, where instance classes register their types // FIXME: replace with a map lookup, where instance classes register their types
if(inst_type == "Legacy") if (inst_type == "Legacy")
{ {
inst = new LegacyInstance(instDir, m_settings, this); inst = new LegacyInstance(instDir, m_settings, this);
} }
else if(inst_type == "OneSix") else if (inst_type == "OneSix")
{ {
inst = new OneSixInstance(instDir, m_settings, this); inst = new OneSixInstance(instDir, m_settings, this);
} }
else if(inst_type == "Nostalgia") else if (inst_type == "Nostalgia")
{ {
inst = new NostalgiaInstance(instDir, m_settings, this); inst = new NostalgiaInstance(instDir, m_settings, this);
} }
@ -68,8 +67,9 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst
return NoLoadError; return NoLoadError;
} }
InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *&inst,
InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*& inst, BaseVersionPtr version, const QString& instDir ) BaseVersionPtr version,
const QString &instDir)
{ {
QDir rootDir(instDir); QDir rootDir(instDir);
@ -79,39 +79,69 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*&
return InstanceFactory::CantCreateDir; return InstanceFactory::CantCreateDir;
} }
auto mcVer = std::dynamic_pointer_cast<MinecraftVersion>(version); auto mcVer = std::dynamic_pointer_cast<MinecraftVersion>(version);
if(!mcVer) if (!mcVer)
return InstanceFactory::NoSuchVersion; return InstanceFactory::NoSuchVersion;
auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg")); auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg"));
m_settings->registerSetting(new Setting("InstanceType", "Legacy")); m_settings->registerSetting(new Setting("InstanceType", "Legacy"));
switch(mcVer->type) switch (mcVer->type)
{ {
case MinecraftVersion::Legacy: case MinecraftVersion::Legacy:
m_settings->set("InstanceType", "Legacy"); m_settings->set("InstanceType", "Legacy");
inst = new LegacyInstance(instDir, m_settings, this); inst = new LegacyInstance(instDir, m_settings, this);
inst->setIntendedVersionId(version->descriptor()); inst->setIntendedVersionId(version->descriptor());
inst->setShouldUseCustomBaseJar(false); inst->setShouldUseCustomBaseJar(false);
break; break;
case MinecraftVersion::OneSix: case MinecraftVersion::OneSix:
m_settings->set("InstanceType", "OneSix"); m_settings->set("InstanceType", "OneSix");
inst = new OneSixInstance(instDir, m_settings, this); inst = new OneSixInstance(instDir, m_settings, this);
inst->setIntendedVersionId(version->descriptor()); inst->setIntendedVersionId(version->descriptor());
inst->setShouldUseCustomBaseJar(false); inst->setShouldUseCustomBaseJar(false);
break; break;
case MinecraftVersion::Nostalgia: case MinecraftVersion::Nostalgia:
m_settings->set("InstanceType", "Nostalgia"); m_settings->set("InstanceType", "Nostalgia");
inst = new NostalgiaInstance(instDir, m_settings, this); inst = new NostalgiaInstance(instDir, m_settings, this);
inst->setIntendedVersionId(version->descriptor()); inst->setIntendedVersionId(version->descriptor());
inst->setShouldUseCustomBaseJar(false); inst->setShouldUseCustomBaseJar(false);
break; break;
default: default:
{ {
delete m_settings; delete m_settings;
return InstanceFactory::NoSuchVersion; return InstanceFactory::NoSuchVersion;
} }
} }
//FIXME: really, how do you even know? // FIXME: really, how do you even know?
return InstanceFactory::NoCreateError; return InstanceFactory::NoCreateError;
} }
InstanceFactory::InstCreateError InstanceFactory::copyInstance(BaseInstance *&newInstance,
BaseInstance *&oldInstance,
const QString &instDir)
{
QDir rootDir(instDir);
QLOG_DEBUG() << instDir.toUtf8();
if (!copyPath(oldInstance->instanceRoot(), instDir))
{
rootDir.removeRecursively();
return InstanceFactory::CantCreateDir;
}
auto error = loadInstance(newInstance, instDir);
switch(error)
{
case NoLoadError:
return NoCreateError;
case UnknownLoadError:
{
rootDir.removeRecursively();
return UnknownCreateError;
}
case NotAnInstance:
{
rootDir.removeRecursively();
return CantCreateDir;
}
};
}

View File

@ -34,7 +34,10 @@ public:
/*! /*!
* \brief Gets a reference to the instance loader. * \brief Gets a reference to the instance loader.
*/ */
static InstanceFactory &get() { return loader; } static InstanceFactory &get()
{
return loader;
}
enum InstLoadError enum InstLoadError
{ {
@ -56,12 +59,27 @@ public:
* \brief Creates a stub instance * \brief Creates a stub instance
* *
* \param inst Pointer to store the created instance in. * \param inst Pointer to store the created instance in.
* \param instDir The instance's directory. * \param inst Game version to use for the instance
* \param instDir The new instance's directory.
* \return An InstCreateError error code. * \return An InstCreateError error code.
* - InstExists if the given instance directory is already an instance. * - InstExists if the given instance directory is already an instance.
* - CantCreateDir if the given instance directory cannot be created. * - CantCreateDir if the given instance directory cannot be created.
*/ */
InstCreateError createInstance(BaseInstance *&inst, BaseVersionPtr version, const QString &instDir); InstCreateError createInstance(BaseInstance *&inst, BaseVersionPtr version,
const QString &instDir);
/*!
* \brief Creates a copy of an existing instance with a new name
*
* \param newInstance Pointer to store the created instance in.
* \param oldInstance The instance to copy
* \param instDir The new instance's directory.
* \return An InstCreateError error code.
* - InstExists if the given instance directory is already an instance.
* - CantCreateDir if the given instance directory cannot be created.
*/
InstCreateError copyInstance(BaseInstance *&newInstance, BaseInstance *&oldInstance,
const QString &instDir);
/*! /*!
* \brief Loads an instance from the given directory. * \brief Loads an instance from the given directory.

View File

@ -6,6 +6,7 @@
<file alias="checkupdate">resources/icons/toolbar/checkupdate.png</file> <file alias="checkupdate">resources/icons/toolbar/checkupdate.png</file>
<file alias="help">resources/icons/toolbar/help.png</file> <file alias="help">resources/icons/toolbar/help.png</file>
<file alias="new">resources/icons/toolbar/new.png</file> <file alias="new">resources/icons/toolbar/new.png</file>
<file alias="copy">resources/icons/toolbar/InstCopy.png</file>
<file alias="news">resources/icons/toolbar/NewsIcon.png</file> <file alias="news">resources/icons/toolbar/NewsIcon.png</file>
<file alias="refresh">resources/icons/toolbar/refresh.png</file> <file alias="refresh">resources/icons/toolbar/refresh.png</file>
<file alias="settings">resources/icons/toolbar/settings.png</file> <file alias="settings">resources/icons/toolbar/settings.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B