From ba3cbb7330fd3435423eb3a77373ca82d65681d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 20 Sep 2017 23:38:31 +0200 Subject: NOISSUE more work on Legacy migration --- api/logic/minecraft/legacy/LegacyMigrationTask.cpp | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 api/logic/minecraft/legacy/LegacyMigrationTask.cpp (limited to 'api/logic/minecraft/legacy/LegacyMigrationTask.cpp') 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 + +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::finished, this, &LegacyMigrationTask::copyFinished); + connect(&m_copyFutureWatcher, &QFutureWatcher::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(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; +} + -- cgit v1.2.3