summaryrefslogtreecommitdiffstats
path: root/api/logic/minecraft/legacy
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2017-09-20 23:38:31 +0200
committerPetr Mrázek <peterix@gmail.com>2017-09-20 23:38:31 +0200
commitba3cbb7330fd3435423eb3a77373ca82d65681d3 (patch)
treed03c176ce5c30e13e15143967b6d800f0d403f92 /api/logic/minecraft/legacy
parent9a6c2b0e2c0a4fb9f26b9c9d1137a66d7977251b (diff)
downloadMultiMC-ba3cbb7330fd3435423eb3a77373ca82d65681d3.tar
MultiMC-ba3cbb7330fd3435423eb3a77373ca82d65681d3.tar.gz
MultiMC-ba3cbb7330fd3435423eb3a77373ca82d65681d3.tar.lz
MultiMC-ba3cbb7330fd3435423eb3a77373ca82d65681d3.tar.xz
MultiMC-ba3cbb7330fd3435423eb3a77373ca82d65681d3.zip
NOISSUE more work on Legacy migration
Diffstat (limited to 'api/logic/minecraft/legacy')
-rw-r--r--api/logic/minecraft/legacy/LegacyInstance.cpp9
-rw-r--r--api/logic/minecraft/legacy/LegacyInstance.h11
-rw-r--r--api/logic/minecraft/legacy/LegacyMigrationTask.cpp51
-rw-r--r--api/logic/minecraft/legacy/LegacyMigrationTask.h37
4 files changed, 108 insertions, 0 deletions
diff --git a/api/logic/minecraft/legacy/LegacyInstance.cpp b/api/logic/minecraft/legacy/LegacyInstance.cpp
index 532e8307..95cc4689 100644
--- a/api/logic/minecraft/legacy/LegacyInstance.cpp
+++ b/api/logic/minecraft/legacy/LegacyInstance.cpp
@@ -272,6 +272,15 @@ QString LegacyInstance::defaultCustomBaseJar() const
return FS::PathCombine(binRoot(), "mcbackup.jar");
}
+std::shared_ptr<WorldList> LegacyInstance::worldList() const
+{
+ if (!m_world_list)
+ {
+ m_world_list.reset(new WorldList(savesDir()));
+ }
+ return m_world_list;
+}
+
QString LegacyInstance::typeName() const
{
return tr("Legacy");
diff --git a/api/logic/minecraft/legacy/LegacyInstance.h b/api/logic/minecraft/legacy/LegacyInstance.h
index 9c5cedd3..5f67cddb 100644
--- a/api/logic/minecraft/legacy/LegacyInstance.h
+++ b/api/logic/minecraft/legacy/LegacyInstance.h
@@ -22,6 +22,7 @@
class ModList;
class LegacyModList;
+class WorldList;
class Task;
/*
* WHY: Legacy instances - from MultiMC 3 and 4 - are here only to provide a way to upgrade them to the current format.
@@ -74,6 +75,7 @@ public:
std::shared_ptr<LegacyModList> jarModList() const;
QList<Mod> getJarMods() const;
+ std::shared_ptr<WorldList> worldList() const;
/*!
* Whether or not the instance's minecraft.jar needs to be rebuilt.
@@ -95,6 +97,14 @@ public:
virtual QString typeName() const override;
+ bool canLaunch() const override
+ {
+ return false;
+ }
+ bool canEdit() const override
+ {
+ return true;
+ }
bool canExport() const override
{
return false;
@@ -125,4 +135,5 @@ public:
}
protected:
mutable std::shared_ptr<LegacyModList> jar_mod_list;
+ mutable std::shared_ptr<WorldList> m_world_list;
};
diff --git a/api/logic/minecraft/legacy/LegacyMigrationTask.cpp b/api/logic/minecraft/legacy/LegacyMigrationTask.cpp
new file mode 100644
index 00000000..0d3cef35
--- /dev/null
+++ b/api/logic/minecraft/legacy/LegacyMigrationTask.cpp
@@ -0,0 +1,51 @@
+#include "LegacyMigrationTask.h"
+#include "BaseInstanceProvider.h"
+#include "settings/INISettingsObject.h"
+#include "FileSystem.h"
+#include "NullInstance.h"
+#include "pathmatcher/RegexpMatcher.h"
+#include <QtConcurrentRun>
+
+LegacyMigrationTask::LegacyMigrationTask(SettingsObjectPtr settings, const QString & stagingPath, InstancePtr origInstance)
+{
+ m_globalSettings = settings;
+ m_stagingPath = stagingPath;
+ m_origInstance = origInstance;
+}
+
+void LegacyMigrationTask::executeTask()
+{
+ setStatus(tr("Copying instance %1").arg(m_origInstance->name()));
+
+ FS::copy folderCopy(m_origInstance->instanceRoot(), m_stagingPath);
+ folderCopy.followSymlinks(true);
+
+ m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), folderCopy);
+ connect(&m_copyFutureWatcher, &QFutureWatcher<bool>::finished, this, &LegacyMigrationTask::copyFinished);
+ connect(&m_copyFutureWatcher, &QFutureWatcher<bool>::canceled, this, &LegacyMigrationTask::copyAborted);
+ m_copyFutureWatcher.setFuture(m_copyFuture);
+}
+
+void LegacyMigrationTask::copyFinished()
+{
+ auto successful = m_copyFuture.result();
+ if(!successful)
+ {
+ emitFailed(tr("Instance folder copy failed."));
+ return;
+ }
+ // FIXME: shouldn't this be able to report errors?
+ auto instanceSettings = std::make_shared<INISettingsObject>(FS::PathCombine(m_stagingPath, "instance.cfg"));
+ instanceSettings->registerSetting("InstanceType", "Legacy");
+
+ InstancePtr inst(new NullInstance(m_globalSettings, instanceSettings, m_stagingPath));
+ inst->setName(tr("%1 (Migrated)").arg(m_origInstance->name()));
+ emitSucceeded();
+}
+
+void LegacyMigrationTask::copyAborted()
+{
+ emitFailed(tr("Instance folder copy has been aborted."));
+ return;
+}
+
diff --git a/api/logic/minecraft/legacy/LegacyMigrationTask.h b/api/logic/minecraft/legacy/LegacyMigrationTask.h
new file mode 100644
index 00000000..36cfa240
--- /dev/null
+++ b/api/logic/minecraft/legacy/LegacyMigrationTask.h
@@ -0,0 +1,37 @@
+#pragma once
+
+#include "tasks/Task.h"
+#include "multimc_logic_export.h"
+#include "net/NetJob.h"
+#include <QUrl>
+#include <QFuture>
+#include <QFutureWatcher>
+#include "settings/SettingsObject.h"
+#include "BaseVersion.h"
+#include "BaseInstance.h"
+
+
+class BaseInstanceProvider;
+
+class MULTIMC_LOGIC_EXPORT LegacyMigrationTask : public Task
+{
+ Q_OBJECT
+public:
+ explicit LegacyMigrationTask(SettingsObjectPtr settings, const QString & stagingPath, InstancePtr origInstance);
+
+protected:
+ //! Entry point for tasks.
+ virtual void executeTask() override;
+ void copyFinished();
+ void copyAborted();
+
+private: /* data */
+ SettingsObjectPtr m_globalSettings;
+ InstancePtr m_origInstance;
+ QString m_stagingPath;
+ QFuture<bool> m_copyFuture;
+ QFutureWatcher<bool> m_copyFutureWatcher;
+};
+
+
+