summaryrefslogtreecommitdiffstats
path: root/api/logic/InstanceCreationTask.cpp
blob: 001567016abab7d913eed2e4fee8ee3dc36689db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "InstanceCreationTask.h"
#include "BaseInstanceProvider.h"
#include "settings/INISettingsObject.h"
#include "FileSystem.h"

//FIXME: remove this
#include "minecraft/MinecraftVersion.h"
#include "minecraft/onesix/OneSixInstance.h"

InstanceCreationTask::InstanceCreationTask(SettingsObjectPtr settings, BaseInstanceProvider* target, BaseVersionPtr version,
	const QString& instName, const QString& instIcon, const QString& instGroup)
{
	m_globalSettings = settings;
	m_target = target;
	m_instName = instName;
	m_instIcon = instIcon;
	m_instGroup = instGroup;
	m_version = version;
}

void InstanceCreationTask::executeTask()
{
	setStatus(tr("Creating instance from version %1").arg(m_version->name()));
	auto minecraftVersion = std::dynamic_pointer_cast<MinecraftVersion>(m_version);
	if(!minecraftVersion)
	{
		emitFailed(tr("The supplied version is not a Minecraft version."));
		return ;
	}

	QString stagingPath = m_target->getStagedInstancePath();
	QDir rootDir(stagingPath);

	auto instanceSettings = std::make_shared<INISettingsObject>(FS::PathCombine(stagingPath, "instance.cfg"));
	instanceSettings->registerSetting("InstanceType", "Legacy");

	auto mcVer = std::dynamic_pointer_cast<MinecraftVersion>(m_version);
	instanceSettings->set("InstanceType", "OneSix");
	InstancePtr inst(new OneSixInstance(m_globalSettings, instanceSettings, stagingPath));
	inst->setIntendedVersionId(m_version->descriptor());
	inst->setName(m_instName);
	inst->setIconKey(m_instIcon);
	inst->init();
	m_target->commitStagedInstance(stagingPath, stagingPath, m_instName, m_instGroup);
	emitSucceeded();
}