mirror of
https://github.com/UltimMC/Launcher.git
synced 2025-10-04 01:00:22 +00:00
GH-336 Rename directories on instance rename
This commit is contained in:
@@ -175,6 +175,11 @@ QString BaseInstance::instanceRoot() const
|
||||
return m_rootDir;
|
||||
}
|
||||
|
||||
void BaseInstance::setInstanceRoot(QString newRoot)
|
||||
{
|
||||
m_rootDir = std::move(newRoot);
|
||||
}
|
||||
|
||||
SettingsObjectPtr BaseInstance::settings() const
|
||||
{
|
||||
return m_settings;
|
||||
@@ -225,11 +230,17 @@ QString BaseInstance::iconKey() const
|
||||
return m_settings->get("iconKey").toString();
|
||||
}
|
||||
|
||||
void BaseInstance::setName(QString val)
|
||||
void BaseInstance::setName(QString val, bool requestDirChange)
|
||||
{
|
||||
//FIXME: if no change, do not set. setting involves saving a file.
|
||||
if(m_settings->get("name") == val) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_settings->set("name", val);
|
||||
emit propertiesChanged(this);
|
||||
if(requestDirChange) {
|
||||
emit instanceDirChangeRequest(this);
|
||||
}
|
||||
}
|
||||
|
||||
QString BaseInstance::name() const
|
||||
|
@@ -93,6 +93,8 @@ public:
|
||||
/// Path to the instance's root directory.
|
||||
QString instanceRoot() const;
|
||||
|
||||
void setInstanceRoot(QString newRoot);
|
||||
|
||||
/// Path to the instance's game root directory.
|
||||
virtual QString gameRoot() const
|
||||
{
|
||||
@@ -100,7 +102,7 @@ public:
|
||||
}
|
||||
|
||||
QString name() const;
|
||||
void setName(QString val);
|
||||
void setName(QString val, bool requestDirChange);
|
||||
|
||||
/// Value used for instance window titles
|
||||
QString windowTitle() const;
|
||||
@@ -245,6 +247,8 @@ signals:
|
||||
|
||||
void statusChanged(Status from, Status to);
|
||||
|
||||
void instanceDirChangeRequest(BaseInstance *inst);
|
||||
|
||||
protected slots:
|
||||
void iconUpdated(QString key);
|
||||
|
||||
|
@@ -44,7 +44,7 @@ void InstanceCopyTask::copyFinished()
|
||||
instanceSettings->registerSetting("InstanceType", "Legacy");
|
||||
|
||||
InstancePtr inst(new NullInstance(m_globalSettings, instanceSettings, m_stagingPath));
|
||||
inst->setName(m_instName);
|
||||
inst->setName(m_instName, false);
|
||||
inst->setIconKey(m_instIcon);
|
||||
emitSucceeded();
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ void InstanceCreationTask::executeTask()
|
||||
auto components = inst.getComponentList();
|
||||
components->buildingFromScratch();
|
||||
components->setComponentVersion("net.minecraft", m_version->descriptor(), true);
|
||||
inst.setName(m_instName);
|
||||
inst.setName(m_instName, false);
|
||||
inst.setIconKey(m_instIcon);
|
||||
instanceSettings->resumeSave();
|
||||
}
|
||||
|
@@ -293,7 +293,7 @@ void InstanceImportTask::processFlame()
|
||||
// nuke the original files
|
||||
FS::deletePath(jarmodsPath);
|
||||
}
|
||||
instance.setName(m_instName);
|
||||
instance.setName(m_instName, false);
|
||||
m_modIdResolver.reset(new Flame::FileResolvingTask(pack));
|
||||
connect(m_modIdResolver.get(), &Flame::FileResolvingTask::succeeded, [&]()
|
||||
{
|
||||
@@ -384,7 +384,7 @@ void InstanceImportTask::processMultiMC()
|
||||
instance.resetTimePlayed();
|
||||
|
||||
// set a new nice name
|
||||
instance.setName(m_instName);
|
||||
instance.setName(m_instName, false);
|
||||
|
||||
// if the icon was specified by user, use that. otherwise pull icon from the pack
|
||||
if (m_instIcon != "default")
|
||||
|
@@ -135,7 +135,7 @@ bool InstanceList::setData(const QModelIndex& index, const QVariant& value, int
|
||||
{
|
||||
return true;
|
||||
}
|
||||
pdata->setName(newName);
|
||||
pdata->setName(newName, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -396,6 +396,7 @@ void InstanceList::add(const QList<InstancePtr> &t)
|
||||
for(auto & ptr : t)
|
||||
{
|
||||
connect(ptr.get(), &BaseInstance::propertiesChanged, this, &InstanceList::propertiesChanged);
|
||||
connect(ptr.get(), &BaseInstance::instanceDirChangeRequest, this, &InstanceList::instanceDirUpdateRequested);
|
||||
}
|
||||
endInsertRows();
|
||||
}
|
||||
@@ -469,6 +470,27 @@ void InstanceList::propertiesChanged(BaseInstance *inst)
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceList::instanceDirUpdateRequested(BaseInstance *inst)
|
||||
{
|
||||
if(m_groupMap.remove(inst->id()))
|
||||
{
|
||||
saveGroupList();
|
||||
}
|
||||
|
||||
QString oldRoot = inst->instanceRoot();
|
||||
QString instID = FS::DirNameFromString(inst->name(), m_instDir);
|
||||
|
||||
QString destination = FS::PathCombine(m_instDir, instID);
|
||||
if(!QDir().rename(oldRoot, destination))
|
||||
{
|
||||
qWarning() << "Failed to move" << inst->instanceRoot() << "to" << destination;
|
||||
}
|
||||
|
||||
FS::deletePath(oldRoot);
|
||||
|
||||
loadList();
|
||||
}
|
||||
|
||||
InstancePtr InstanceList::loadInstance(const InstanceId& id)
|
||||
{
|
||||
if(!m_groupsLoaded)
|
||||
|
@@ -136,6 +136,7 @@ public slots:
|
||||
|
||||
private slots:
|
||||
void propertiesChanged(BaseInstance *inst);
|
||||
void instanceDirUpdateRequested(BaseInstance *inst);
|
||||
void providerUpdated();
|
||||
void instanceDirContentsChanged(const QString &path);
|
||||
|
||||
|
@@ -66,7 +66,7 @@ void LegacyUpgradeTask::copyFinished()
|
||||
// NOTE: this scope ensures the instance is fully saved before we emitSucceeded
|
||||
{
|
||||
MinecraftInstance inst(m_globalSettings, instanceSettings, m_stagingPath);
|
||||
inst.setName(m_instName);
|
||||
inst.setName(m_instName, false);
|
||||
|
||||
QString preferredVersionNumber = decideVersion(legacyInst->currentVersionId(), legacyInst->intendedVersionId());
|
||||
if(preferredVersionNumber.isNull())
|
||||
|
@@ -186,7 +186,7 @@ void FtbPackInstallTask::install()
|
||||
|
||||
progress(4, 4);
|
||||
|
||||
instance.setName(m_instName);
|
||||
instance.setName(m_instName, false);
|
||||
if(m_instIcon == "default")
|
||||
{
|
||||
m_instIcon = "ftb_logo";
|
||||
|
@@ -845,7 +845,7 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
|
||||
actionSep->setSeparator(true);
|
||||
|
||||
bool onInstance = view->indexAt(pos).isValid();
|
||||
if (onInstance)
|
||||
if (onInstance && m_selectedInstance)
|
||||
{
|
||||
actions = ui->instanceToolBar->actions();
|
||||
|
||||
|
Reference in New Issue
Block a user