2013-01-15 05:12:38 +05:30
|
|
|
/* Copyright 2013 MultiMC Contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2013-02-21 06:40:09 +05:30
|
|
|
#include "include/instance.h"
|
2013-01-15 05:12:38 +05:30
|
|
|
|
2013-02-19 04:28:53 +05:30
|
|
|
#include <QFileInfo>
|
|
|
|
|
2013-02-26 04:06:27 +05:30
|
|
|
#include "inisettingsobject.h"
|
|
|
|
#include "setting.h"
|
|
|
|
#include "overridesetting.h"
|
2013-02-26 02:14:36 +05:30
|
|
|
|
2013-02-21 06:40:09 +05:30
|
|
|
#include "pathutils.h"
|
2013-05-04 01:11:37 +05:30
|
|
|
#include <minecraftversionlist.h>
|
2013-02-19 04:28:53 +05:30
|
|
|
|
2013-02-19 02:20:11 +05:30
|
|
|
Instance::Instance(const QString &rootDir, QObject *parent) :
|
2013-02-26 00:54:46 +05:30
|
|
|
QObject(parent)
|
2013-01-15 05:12:38 +05:30
|
|
|
{
|
2013-02-19 04:28:53 +05:30
|
|
|
m_rootDir = rootDir;
|
2013-03-13 23:43:28 +05:30
|
|
|
m_settings = new INISettingsObject(configFile(), this);
|
2013-02-26 04:06:27 +05:30
|
|
|
|
|
|
|
settings().registerSetting(new Setting("name", "Unnamed Instance"));
|
|
|
|
settings().registerSetting(new Setting("iconKey", "default"));
|
|
|
|
settings().registerSetting(new Setting("notes", ""));
|
|
|
|
settings().registerSetting(new Setting("NeedsRebuild", true));
|
|
|
|
settings().registerSetting(new Setting("JarVersion", "Unknown"));
|
|
|
|
settings().registerSetting(new Setting("LwjglVersion", "Mojang"));
|
|
|
|
settings().registerSetting(new Setting("IntendedJarVersion", ""));
|
|
|
|
settings().registerSetting(new Setting("lastLaunchTime", 0));
|
|
|
|
|
|
|
|
// Java Settings
|
|
|
|
settings().registerSetting(new OverrideSetting("JavaPath", globalSettings->getSetting("JavaPath")));
|
|
|
|
settings().registerSetting(new OverrideSetting("JvmArgs", globalSettings->getSetting("JvmArgs")));
|
|
|
|
|
|
|
|
// Custom Commands
|
|
|
|
settings().registerSetting(new OverrideSetting("PreLaunchCommand",
|
|
|
|
globalSettings->getSetting("PreLaunchCommand")));
|
|
|
|
settings().registerSetting(new OverrideSetting("PostExitCommand",
|
|
|
|
globalSettings->getSetting("PostExitCommand")));
|
|
|
|
|
2013-03-24 20:06:00 +05:30
|
|
|
// Window Size
|
|
|
|
settings().registerSetting(new OverrideSetting("LaunchCompatMode", globalSettings->getSetting("LaunchCompatMode")));
|
|
|
|
settings().registerSetting(new OverrideSetting("LaunchMaximized", globalSettings->getSetting("LaunchMaximized")));
|
|
|
|
settings().registerSetting(new OverrideSetting("MinecraftWinWidth", globalSettings->getSetting("MinecraftWinWidth")));
|
|
|
|
settings().registerSetting(new OverrideSetting("MinecraftWinHeight", globalSettings->getSetting("MinecraftWinHeight")));
|
|
|
|
|
2013-02-26 04:06:27 +05:30
|
|
|
// Memory
|
|
|
|
settings().registerSetting(new OverrideSetting("MinMemAlloc", globalSettings->getSetting("MinMemAlloc")));
|
|
|
|
settings().registerSetting(new OverrideSetting("MaxMemAlloc", globalSettings->getSetting("MaxMemAlloc")));
|
|
|
|
|
|
|
|
// Auto login
|
|
|
|
settings().registerSetting(new OverrideSetting("AutoLogin", globalSettings->getSetting("AutoLogin")));
|
2013-02-19 04:28:53 +05:30
|
|
|
}
|
|
|
|
|
2013-02-21 06:40:09 +05:30
|
|
|
QString Instance::id() const
|
2013-02-19 04:28:53 +05:30
|
|
|
{
|
2013-02-23 05:26:17 +05:30
|
|
|
return QFileInfo(rootDir()).fileName();
|
2013-02-19 04:28:53 +05:30
|
|
|
}
|
|
|
|
|
2013-02-21 06:40:09 +05:30
|
|
|
QString Instance::rootDir() const
|
2013-02-19 04:28:53 +05:30
|
|
|
{
|
|
|
|
return m_rootDir;
|
|
|
|
}
|
|
|
|
|
2013-02-21 06:40:09 +05:30
|
|
|
InstanceList *Instance::instList() const
|
2013-02-19 04:28:53 +05:30
|
|
|
{
|
|
|
|
if (parent()->inherits("InstanceList"))
|
|
|
|
return (InstanceList *)parent();
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-02-20 20:02:26 +05:30
|
|
|
QString Instance::minecraftDir() const
|
|
|
|
{
|
|
|
|
QFileInfo mcDir(PathCombine(rootDir(), "minecraft"));
|
|
|
|
QFileInfo dotMCDir(PathCombine(rootDir(), ".minecraft"));
|
|
|
|
|
|
|
|
if (dotMCDir.exists() && !mcDir.exists())
|
2013-02-22 20:47:31 +05:30
|
|
|
return dotMCDir.filePath();
|
2013-02-20 20:02:26 +05:30
|
|
|
else
|
2013-03-13 23:43:28 +05:30
|
|
|
return mcDir.filePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Instance::instModsDir() const
|
|
|
|
{
|
|
|
|
return PathCombine(rootDir(), "instMods");
|
2013-02-20 20:02:26 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
QString Instance::binDir() const
|
|
|
|
{
|
|
|
|
return PathCombine(minecraftDir(), "bin");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Instance::savesDir() const
|
|
|
|
{
|
|
|
|
return PathCombine(minecraftDir(), "saves");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Instance::mlModsDir() const
|
|
|
|
{
|
|
|
|
return PathCombine(minecraftDir(), "mods");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Instance::coreModsDir() const
|
|
|
|
{
|
|
|
|
return PathCombine(minecraftDir(), "coremods");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Instance::resourceDir() const
|
|
|
|
{
|
|
|
|
return PathCombine(minecraftDir(), "resources");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Instance::screenshotsDir() const
|
|
|
|
{
|
|
|
|
return PathCombine(minecraftDir(), "screenshots");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Instance::texturePacksDir() const
|
|
|
|
{
|
|
|
|
return PathCombine(minecraftDir(), "texturepacks");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Instance::mcJar() const
|
|
|
|
{
|
|
|
|
return PathCombine(binDir(), "minecraft.jar");
|
|
|
|
}
|
|
|
|
|
2013-03-13 23:43:28 +05:30
|
|
|
QString Instance::mcBackup() const
|
|
|
|
{
|
|
|
|
return PathCombine(binDir(), "mcbackup.jar");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Instance::configFile() const
|
|
|
|
{
|
|
|
|
return PathCombine(rootDir(), "instance.cfg");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Instance::modListFile() const
|
|
|
|
{
|
|
|
|
return PathCombine(rootDir(), "modlist");
|
|
|
|
}
|
|
|
|
|
2013-05-04 01:11:37 +05:30
|
|
|
InstVersionList *Instance::versionList() const
|
|
|
|
{
|
|
|
|
return &MinecraftVersionList::getMainList();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Instance::shouldUpdateCurrentVersion()
|
|
|
|
{
|
|
|
|
QFileInfo jar(mcJar());
|
|
|
|
return jar.lastModified().toUTC().toMSecsSinceEpoch() != lastCurrentVersionUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Instance::updateCurrentVersion(bool keepCurrent)
|
|
|
|
{
|
|
|
|
QFileInfo jar(mcJar());
|
|
|
|
|
|
|
|
if(!jar.exists())
|
|
|
|
{
|
|
|
|
setLastCurrentVersionUpdate(0);
|
|
|
|
setCurrentVersion("Unknown");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 time = jar.lastModified().toUTC().toMSecsSinceEpoch();
|
|
|
|
|
|
|
|
setLastCurrentVersionUpdate(time);
|
|
|
|
if (!keepCurrent)
|
|
|
|
{
|
|
|
|
// TODO: Implement GetMinecraftJarVersion function.
|
|
|
|
QString newVersion = "Unknown";//javautils::GetMinecraftJarVersion(jar.absoluteFilePath());
|
|
|
|
setCurrentVersion(newVersion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-26 04:06:27 +05:30
|
|
|
SettingsObject &Instance::settings() const
|
2013-02-26 02:14:36 +05:30
|
|
|
{
|
2013-02-26 04:06:27 +05:30
|
|
|
return *m_settings;
|
2013-02-26 02:14:36 +05:30
|
|
|
}
|