InstanceFactory::InstLoadError InstanceFactory::loadInstance(InstancePtr &inst, const QString &instDir) { auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg")); m_settings->registerSetting("InstanceType", "Legacy"); QString inst_type = m_settings->get("InstanceType").toString(); // FIXME: replace with a map lookup, where instance classes register their types if (inst_type == "OneSix" || inst_type == "Nostalgia") { inst.reset(new OneSixInstance(instDir, m_settings, this)); } else if (inst_type == "Legacy") { inst.reset(new LegacyInstance(instDir, m_settings, this)); } else if (inst_type == "LegacyFTB") { inst.reset(new LegacyFTBInstance(instDir, m_settings, this)); } else if (inst_type == "OneSixFTB") { inst.reset(new OneSixFTBInstance(instDir, m_settings, this)); } else { return InstanceFactory::UnknownLoadError; } inst->init(); return NoLoadError; }
InstanceFactory::InstCreateError InstanceFactory::createInstance(InstancePtr &inst, BaseVersionPtr version, const QString &instDir, const InstanceFactory::InstType type) { QDir rootDir(instDir); QLOG_DEBUG() << instDir.toUtf8(); if (!rootDir.exists() && !rootDir.mkpath(".")) { return InstanceFactory::CantCreateDir; } auto mcVer = std::dynamic_pointer_cast<MinecraftVersion>(version); if (!mcVer) return InstanceFactory::NoSuchVersion; auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg")); m_settings->registerSetting("InstanceType", "Legacy"); if (type == NormalInst) { m_settings->set("InstanceType", "OneSix"); inst.reset(new OneSixInstance(instDir, m_settings, this)); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); } else if (type == FTBInstance) { if(mcVer->usesLegacyLauncher()) { m_settings->set("InstanceType", "LegacyFTB"); inst.reset(new LegacyFTBInstance(instDir, m_settings, this)); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); } else { m_settings->set("InstanceType", "OneSixFTB"); inst.reset(new OneSixFTBInstance(instDir, m_settings, this)); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); } } else { delete m_settings; return InstanceFactory::NoSuchVersion; } inst->init(); // FIXME: really, how do you even know? return InstanceFactory::NoCreateError; }