diff options
author | Petr Mrázek <peterix@gmail.com> | 2014-03-30 20:11:05 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2014-03-30 20:11:41 +0200 |
commit | fbc29b6a0626f2ce8521dc74e3171b634d68e9e5 (patch) | |
tree | d2d79201be585131be2ab0cd7d337237887af5a0 /logic/InstanceFactory.cpp | |
parent | e1e1d99102936b419aac52974f1fdb8be835b0d4 (diff) | |
download | MultiMC-fbc29b6a0626f2ce8521dc74e3171b634d68e9e5.tar MultiMC-fbc29b6a0626f2ce8521dc74e3171b634d68e9e5.tar.gz MultiMC-fbc29b6a0626f2ce8521dc74e3171b634d68e9e5.tar.lz MultiMC-fbc29b6a0626f2ce8521dc74e3171b634d68e9e5.tar.xz MultiMC-fbc29b6a0626f2ce8521dc74e3171b634d68e9e5.zip |
Fix many memory leaks.
Diffstat (limited to 'logic/InstanceFactory.cpp')
-rw-r--r-- | logic/InstanceFactory.cpp | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/logic/InstanceFactory.cpp b/logic/InstanceFactory.cpp index d6e06133..4f65221c 100644 --- a/logic/InstanceFactory.cpp +++ b/logic/InstanceFactory.cpp @@ -41,7 +41,7 @@ InstanceFactory::InstanceFactory() : QObject(NULL) { } -InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst, +InstanceFactory::InstLoadError InstanceFactory::loadInstance(InstancePtr &inst, const QString &instDir) { auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg")); @@ -53,23 +53,23 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst // FIXME: replace with a map lookup, where instance classes register their types if (inst_type == "OneSix") { - inst = new OneSixInstance(instDir, m_settings, this); + inst.reset(new OneSixInstance(instDir, m_settings, this)); } else if (inst_type == "Legacy") { - inst = new LegacyInstance(instDir, m_settings, this); + inst.reset(new LegacyInstance(instDir, m_settings, this)); } else if (inst_type == "Nostalgia") { - inst = new NostalgiaInstance(instDir, m_settings, this); + inst.reset(new NostalgiaInstance(instDir, m_settings, this)); } else if (inst_type == "LegacyFTB") { - inst = new LegacyFTBInstance(instDir, m_settings, this); + inst.reset(new LegacyFTBInstance(instDir, m_settings, this)); } else if (inst_type == "OneSixFTB") { - inst = new OneSixFTBInstance(instDir, m_settings, this); + inst.reset(new OneSixFTBInstance(instDir, m_settings, this)); } else { @@ -79,10 +79,8 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst return NoLoadError; } -InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *&inst, - BaseVersionPtr version, - const QString &instDir, - const InstType type) +InstanceFactory::InstCreateError InstanceFactory::createInstance(InstancePtr &inst, BaseVersionPtr version, + const QString &instDir, const InstanceFactory::InstType type) { QDir rootDir(instDir); @@ -105,19 +103,19 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *& case MinecraftVersion::Legacy: // TODO new instance type m_settings->set("InstanceType", "Legacy"); - inst = new LegacyInstance(instDir, m_settings, this); + inst.reset(new LegacyInstance(instDir, m_settings, this)); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; case MinecraftVersion::OneSix: m_settings->set("InstanceType", "OneSix"); - inst = new OneSixInstance(instDir, m_settings, this); + inst.reset(new OneSixInstance(instDir, m_settings, this)); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; case MinecraftVersion::Nostalgia: m_settings->set("InstanceType", "Nostalgia"); - inst = new NostalgiaInstance(instDir, m_settings, this); + inst.reset(new NostalgiaInstance(instDir, m_settings, this)); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; @@ -134,13 +132,13 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *& { case MinecraftVersion::Legacy: m_settings->set("InstanceType", "LegacyFTB"); - inst = new LegacyFTBInstance(instDir, m_settings, this); + inst.reset(new LegacyFTBInstance(instDir, m_settings, this)); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; case MinecraftVersion::OneSix: m_settings->set("InstanceType", "OneSixFTB"); - inst = new OneSixFTBInstance(instDir, m_settings, this); + inst.reset(new OneSixFTBInstance(instDir, m_settings, this)); inst->setIntendedVersionId(version->descriptor()); inst->setShouldUseCustomBaseJar(false); break; @@ -163,8 +161,8 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *& return InstanceFactory::NoCreateError; } -InstanceFactory::InstCreateError InstanceFactory::copyInstance(BaseInstance *&newInstance, - BaseInstance *&oldInstance, +InstanceFactory::InstCreateError InstanceFactory::copyInstance(InstancePtr &newInstance, + InstancePtr &oldInstance, const QString &instDir) { QDir rootDir(instDir); @@ -175,14 +173,6 @@ InstanceFactory::InstCreateError InstanceFactory::copyInstance(BaseInstance *&ne rootDir.removeRecursively(); return InstanceFactory::CantCreateDir; } - auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg")); - m_settings->registerSetting("InstanceType", "Legacy"); - QString inst_type = m_settings->get("InstanceType").toString(); - - if(inst_type == "OneSixFTB") - m_settings->set("InstanceType", "OneSix"); - if(inst_type == "LegacyFTB") - m_settings->set("InstanceType", "Legacy"); oldInstance->copy(instDir); @@ -198,6 +188,7 @@ InstanceFactory::InstCreateError InstanceFactory::copyInstance(BaseInstance *&ne default: case UnknownLoadError: rootDir.removeRecursively(); - return UnknownCreateError; + return UnknownCreateError; } + return UnknownCreateError; } |