GH-907 fix location/java override for java detection

This commit is contained in:
Petr Mrázek 2015-05-05 01:09:28 +02:00
parent 49d3705d16
commit 4c6edc9fd4

View File

@ -1,22 +1,47 @@
#include "MinecraftInstance.h" #include "MinecraftInstance.h"
#include <settings/Setting.h>
#include "settings/SettingsObject.h" #include "settings/SettingsObject.h"
#include <pathutils.h> #include <pathutils.h>
#include "Env.h" #include "Env.h"
#include "minecraft/MinecraftVersionList.h" #include "minecraft/MinecraftVersionList.h"
// all of this because keeping things compatible with deprecated old settings
// if either of the settings {a, b} is true, this also resolves to true
class OrSetting : public Setting
{
Q_OBJECT
public:
OrSetting(QString id, std::shared_ptr<Setting> a, std::shared_ptr<Setting> b)
:Setting({id}, false), m_a(a), m_b(b)
{
}
virtual QVariant get() const
{
bool a = m_a->get().toBool();
bool b = m_b->get().toBool();
return a || b;
}
virtual void reset() {}
virtual void set(QVariant value) {}
private:
std::shared_ptr<Setting> m_a;
std::shared_ptr<Setting> m_b;
};
MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir) MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr settings, const QString &rootDir)
: BaseInstance(globalSettings, settings, rootDir) : BaseInstance(globalSettings, settings, rootDir)
{ {
// Java Settings // Java Settings
m_settings->registerSetting("OverrideJava", false); auto javaOverride = m_settings->registerSetting("OverrideJava", false);
auto locationOverride = m_settings->registerSetting("OverrideJavaLocation", false); auto locationOverride = m_settings->registerSetting("OverrideJavaLocation", false);
auto javaOrLocation = std::make_shared<OrSetting>("JavaOrLocationOverride", javaOverride, locationOverride);
m_settings->registerSetting("OverrideJavaArgs", false); m_settings->registerSetting("OverrideJavaArgs", false);
m_settings->registerOverride(globalSettings->getSetting("JavaPath")); m_settings->registerOverride(globalSettings->getSetting("JavaPath"));
m_settings->registerOverride(globalSettings->getSetting("JvmArgs")); m_settings->registerOverride(globalSettings->getSetting("JvmArgs"));
// special! // special!
m_settings->registerPassthrough(globalSettings->getSetting("JavaTimestamp"), locationOverride); m_settings->registerPassthrough(globalSettings->getSetting("JavaTimestamp"), javaOrLocation);
m_settings->registerPassthrough(globalSettings->getSetting("JavaVersion"), locationOverride); m_settings->registerPassthrough(globalSettings->getSetting("JavaVersion"), javaOrLocation);
// Window Size // Window Size
m_settings->registerSetting("OverrideWindow", false); m_settings->registerSetting("OverrideWindow", false);
@ -46,3 +71,5 @@ std::shared_ptr< BaseVersionList > MinecraftInstance::versionList() const
{ {
return ENV.getVersionList("net.minecraft"); return ENV.getVersionList("net.minecraft");
} }
#include "MinecraftInstance.moc"