summaryrefslogtreecommitdiffstats
path: root/backend
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-08-12 00:39:19 +0200
committerPetr Mrázek <peterix@gmail.com>2013-08-12 00:39:19 +0200
commitff33d4a1a48abf1442cde77c2253f071d0870d50 (patch)
tree7846f144b2ee2e24574745847c0f921677021d73 /backend
parent7e78a422e8bb22572706b7fadb58fc45e7b8a7db (diff)
downloadMultiMC-ff33d4a1a48abf1442cde77c2253f071d0870d50.tar
MultiMC-ff33d4a1a48abf1442cde77c2253f071d0870d50.tar.gz
MultiMC-ff33d4a1a48abf1442cde77c2253f071d0870d50.tar.lz
MultiMC-ff33d4a1a48abf1442cde77c2253f071d0870d50.tar.xz
MultiMC-ff33d4a1a48abf1442cde77c2253f071d0870d50.zip
OneSix instances now have a minecraft folder inside.
Also, the main instance view was expanded with helpful key events: F2 for rename, F5 for refresh, Enter for start instance, Delete for...
Diffstat (limited to 'backend')
-rw-r--r--backend/BaseInstance.cpp15
-rw-r--r--backend/BaseInstance.h5
-rw-r--r--backend/LegacyInstance.cpp46
-rw-r--r--backend/LegacyInstance.h3
-rw-r--r--backend/LegacyUpdate.cpp67
-rw-r--r--backend/LegacyUpdate.h11
-rw-r--r--backend/MinecraftProcess.cpp2
-rw-r--r--backend/OneSixInstance.cpp11
-rw-r--r--backend/OneSixUpdate.cpp11
-rw-r--r--backend/OneSixUpdate.h1
-rw-r--r--backend/lists/MinecraftVersionList.cpp3
11 files changed, 135 insertions, 40 deletions
diff --git a/backend/BaseInstance.cpp b/backend/BaseInstance.cpp
index d94f3de9..951b403a 100644
--- a/backend/BaseInstance.cpp
+++ b/backend/BaseInstance.cpp
@@ -75,7 +75,7 @@ BaseInstance::BaseInstance( BaseInstancePrivate* d_in,
QString BaseInstance::id() const
{
- return QFileInfo(rootDir()).fileName();
+ return QFileInfo(instanceRoot()).fileName();
}
QString BaseInstance::instanceType() const
@@ -85,12 +85,23 @@ QString BaseInstance::instanceType() const
}
-QString BaseInstance::rootDir() const
+QString BaseInstance::instanceRoot() const
{
I_D(BaseInstance);
return d->m_rootDir;
}
+QString BaseInstance::minecraftRoot() const
+{
+ QFileInfo mcDir(PathCombine(instanceRoot(), "minecraft"));
+ QFileInfo dotMCDir(PathCombine(instanceRoot(), ".minecraft"));
+
+ if (dotMCDir.exists() && !mcDir.exists())
+ return dotMCDir.filePath();
+ else
+ return mcDir.filePath();
+}
+
InstanceList *BaseInstance::instList() const
{
if (parent()->inherits("InstanceList"))
diff --git a/backend/BaseInstance.h b/backend/BaseInstance.h
index 3a344cea..05f3ce00 100644
--- a/backend/BaseInstance.h
+++ b/backend/BaseInstance.h
@@ -56,7 +56,10 @@ public:
QString instanceType() const;
/// Path to the instance's root directory.
- QString rootDir() const;
+ QString instanceRoot() const;
+
+ /// Path to the instance's minecraft directory.
+ QString minecraftRoot() const;
QString name() const;
void setName(QString val);
diff --git a/backend/LegacyInstance.cpp b/backend/LegacyInstance.cpp
index bf5c674b..9102c9c7 100644
--- a/backend/LegacyInstance.cpp
+++ b/backend/LegacyInstance.cpp
@@ -21,17 +21,6 @@ LegacyInstance::LegacyInstance(const QString& rootDir, SettingsObject* settings,
settings->registerSetting(new Setting("IntendedJarVersion", ""));
}
-QString LegacyInstance::minecraftDir() const
-{
- QFileInfo mcDir(PathCombine(rootDir(), "minecraft"));
- QFileInfo dotMCDir(PathCombine(rootDir(), ".minecraft"));
-
- if (dotMCDir.exists() && !mcDir.exists())
- return dotMCDir.filePath();
- else
- return mcDir.filePath();
-}
-
BaseUpdate* LegacyInstance::doUpdate()
{
return new LegacyUpdate(this, this);
@@ -42,10 +31,10 @@ MinecraftProcess* LegacyInstance::prepareForLaunch(QString user, QString session
MinecraftProcess * proc = new MinecraftProcess(this);
// FIXME: extract the icon
- // QImage(":/icons/instances/" + iconKey()).save(PathCombine(minecraftDir(), "icon.png"));
+ // QImage(":/icons/instances/" + iconKey()).save(PathCombine(minecraftRoot(), "icon.png"));
// extract the legacy launcher
- QFile(":/launcher/launcher.jar").copy(PathCombine(minecraftDir(), LAUNCHER_FILE));
+ QFile(":/launcher/launcher.jar").copy(PathCombine(minecraftRoot(), LAUNCHER_FILE));
// set the process arguments
{
@@ -88,7 +77,7 @@ MinecraftProcess* LegacyInstance::prepareForLaunch(QString user, QString session
}
// set the process work path
- proc->setMinecraftWorkdir(minecraftDir());
+ proc->setMinecraftWorkdir(minecraftRoot());
return proc;
}
@@ -101,32 +90,32 @@ void LegacyInstance::cleanupAfterRun()
QString LegacyInstance::instModsDir() const
{
- return PathCombine(rootDir(), "instMods");
+ return PathCombine(instanceRoot(), "instMods");
}
QString LegacyInstance::binDir() const
{
- return PathCombine(minecraftDir(), "bin");
+ return PathCombine(minecraftRoot(), "bin");
}
QString LegacyInstance::savesDir() const
{
- return PathCombine(minecraftDir(), "saves");
+ return PathCombine(minecraftRoot(), "saves");
}
QString LegacyInstance::mlModsDir() const
{
- return PathCombine(minecraftDir(), "mods");
+ return PathCombine(minecraftRoot(), "mods");
}
QString LegacyInstance::coreModsDir() const
{
- return PathCombine(minecraftDir(), "coremods");
+ return PathCombine(minecraftRoot(), "coremods");
}
QString LegacyInstance::resourceDir() const
{
- return PathCombine(minecraftDir(), "resources");
+ return PathCombine(minecraftRoot(), "resources");
}
QString LegacyInstance::mcJar() const
@@ -141,7 +130,7 @@ QString LegacyInstance::mcBackup() const
QString LegacyInstance::modListFile() const
{
- return PathCombine(rootDir(), "modlist");
+ return PathCombine(instanceRoot(), "modlist");
}
bool LegacyInstance::shouldUpdateCurrentVersion() const
@@ -220,10 +209,21 @@ QString LegacyInstance::intendedVersionId() const
}
bool LegacyInstance::setIntendedVersionId ( QString version )
{
- return false;
+ settings().set("IntendedJarVersion", version);
+ setShouldUpdate(true);
+ return true;
}
bool LegacyInstance::shouldUpdate() const
{
+ I_D(LegacyInstance);
+ QVariant var = settings().get ( "ShouldUpdate" );
+ if ( !var.isValid() || var.toBool() == false )
+ {
+ return intendedVersionId() != currentVersionId();
+ }
return true;
}
-void LegacyInstance::setShouldUpdate ( bool val ) {}
+void LegacyInstance::setShouldUpdate ( bool val )
+{
+ settings().set ( "ShouldUpdate", val );
+}
diff --git a/backend/LegacyInstance.h b/backend/LegacyInstance.h
index e7cf347c..6c9a295f 100644
--- a/backend/LegacyInstance.h
+++ b/backend/LegacyInstance.h
@@ -21,10 +21,9 @@ public:
QString modListFile() const;
////// Directories //////
- QString minecraftDir() const;
+ QString savesDir() const;
QString instModsDir() const;
QString binDir() const;
- QString savesDir() const;
QString mlModsDir() const;
QString coreModsDir() const;
QString resourceDir() const;
diff --git a/backend/LegacyUpdate.cpp b/backend/LegacyUpdate.cpp
index 630f7f29..8580a2f2 100644
--- a/backend/LegacyUpdate.cpp
+++ b/backend/LegacyUpdate.cpp
@@ -1,5 +1,6 @@
#include "LegacyUpdate.h"
#include "lists/LwjglVersionList.h"
+#include "lists/MinecraftVersionList.h"
#include "BaseInstance.h"
#include "LegacyInstance.h"
#include "net/NetWorker.h"
@@ -27,7 +28,7 @@ void LegacyUpdate::lwjglStart()
QFileInfo doneFile(PathCombine(lwjglTargetPath, "done"));
if(doneFile.exists())
{
- emitSucceeded();
+ jarStart();
return;
}
@@ -38,6 +39,7 @@ void LegacyUpdate::lwjglStart()
return;
}
+ setStatus("Downloading new LWJGL.");
auto version = list.getVersion(lwjglVersion);
if(!version)
{
@@ -104,6 +106,7 @@ void LegacyUpdate::lwjglFinished(QNetworkReply* reply)
saveMe.close();
setStatus("Installing new LWJGL...");
extractLwjgl();
+ jarStart();
}
void LegacyUpdate::extractLwjgl()
{
@@ -189,7 +192,6 @@ void LegacyUpdate::extractLwjgl()
doneFile.open(QIODevice::WriteOnly);
doneFile.write("done.");
doneFile.close();
- emitSucceeded();
}
void LegacyUpdate::lwjglFailed()
@@ -197,3 +199,64 @@ void LegacyUpdate::lwjglFailed()
emitFailed("Bad stuff happened while trying to get the lwjgl libs...");
}
+void LegacyUpdate::jarStart()
+{
+ setStatus("Checking ...");
+ LegacyInstance * inst = (LegacyInstance *) m_inst;
+ QString current_version_id = inst->currentVersionId();
+ QString intended_version_id = inst->intendedVersionId();
+ bool shouldUpdate = inst->shouldUpdate();
+ if(!shouldUpdate)
+ {
+ emitSucceeded();
+ return;
+ }
+
+ // Get a pointer to the version object that corresponds to the instance's version.
+ auto targetVersion = MinecraftVersionList::getMainList().findVersion(intended_version_id);
+
+ if(!targetVersion)
+ {
+ emitFailed("Not a valid version:" + intended_version_id);
+ return;
+ }
+
+ // Make directories
+ QDir binDir(inst->binDir());
+ if (!binDir.exists() && !binDir.mkpath("."))
+ {
+ emitFailed("Failed to create bin folder.");
+ return;
+ }
+
+ // Build a list of URLs that will need to be downloaded.
+ setStatus("Downloading new minecraft.jar");
+
+ // This will be either 'minecraft' or the version number, depending on where
+ // we're downloading from.
+ QString jarFilename = "minecraft";
+ QString download_path = PathCombine(inst->minecraftRoot(), "bin/minecraft.jar");
+
+ QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/");
+ urlstr += targetVersion->descriptor + "/" + targetVersion->descriptor + ".jar";
+ auto dljob = DownloadJob::create(QUrl(urlstr), download_path);
+
+ legacyDownloadJob.reset(new JobList());
+ legacyDownloadJob->add(dljob);
+ connect(legacyDownloadJob.data(), SIGNAL(finished()), SLOT(jarFinished()));
+ connect(legacyDownloadJob.data(), SIGNAL(failed()), SLOT(jarFailed()));
+ connect(legacyDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
+ download_queue.enqueue(legacyDownloadJob);
+}
+
+void LegacyUpdate::jarFinished()
+{
+ // process the jar
+ emitSucceeded();
+}
+
+void LegacyUpdate::jarFailed()
+{
+ // bad, bad
+ emitFailed("Failed to download the minecraft jar. Try again later.");
+}
diff --git a/backend/LegacyUpdate.h b/backend/LegacyUpdate.h
index cc1f5efd..ad58fc85 100644
--- a/backend/LegacyUpdate.h
+++ b/backend/LegacyUpdate.h
@@ -38,6 +38,11 @@ private slots:
void lwjglStart();
void lwjglFinished( QNetworkReply* );
void lwjglFailed();
+
+ void jarStart();
+ void jarFinished();
+ void jarFailed();
+
void extractLwjgl();
private:
@@ -50,6 +55,12 @@ private:
QString lwjglTargetPath;
QString lwjglNativesPath;
+private:
+ JobListPtr legacyDownloadJob;
+ JobListQueue download_queue;
+
+ // target version, determined during this task
+ QSharedPointer<MinecraftVersion> targetVersion;
};
diff --git a/backend/MinecraftProcess.cpp b/backend/MinecraftProcess.cpp
index d4d1da3c..d34be835 100644
--- a/backend/MinecraftProcess.cpp
+++ b/backend/MinecraftProcess.cpp
@@ -49,7 +49,7 @@ MinecraftProcess::MinecraftProcess( BaseInstance* inst ) :
// export some infos
env.insert("INST_NAME", inst->name());
env.insert("INST_ID", inst->id());
- env.insert("INST_DIR", QDir(inst->rootDir()).absolutePath());
+ env.insert("INST_DIR", QDir(inst->instanceRoot()).absolutePath());
this->setProcessEnvironment(env);
m_prepostlaunchprocess.setProcessEnvironment(env);
diff --git a/backend/OneSixInstance.cpp b/backend/OneSixInstance.cpp
index bf8fd84e..46866b0e 100644
--- a/backend/OneSixInstance.cpp
+++ b/backend/OneSixInstance.cpp
@@ -70,7 +70,7 @@ QStringList OneSixInstance::processMinecraftArgs( QString user, QString session
token_mapping["profile_name"] = name();
token_mapping["version_name"] = version->id;
- QString absRootDir = QDir(rootDir()).absolutePath();
+ QString absRootDir = QDir(minecraftRoot()).absolutePath();
token_mapping["game_directory"] = absRootDir;
QString absAssetsDir = QDir("assets/").absolutePath();
token_mapping["game_assets"] = absAssetsDir;
@@ -91,7 +91,7 @@ MinecraftProcess* OneSixInstance::prepareForLaunch ( QString user, QString sessi
if(!version)
return nullptr;
auto libs_to_extract = version->getActiveNativeLibs();
- QString natives_dir_raw = PathCombine(rootDir(), "natives/");
+ QString natives_dir_raw = PathCombine(instanceRoot(), "natives/");
bool success = ensurePathExists(natives_dir_raw);
if(!success)
{
@@ -140,13 +140,13 @@ MinecraftProcess* OneSixInstance::prepareForLaunch ( QString user, QString sessi
// create the process and set its parameters
MinecraftProcess * proc = new MinecraftProcess(this);
proc->setMinecraftArguments(args);
- proc->setMinecraftWorkdir(rootDir());
+ proc->setMinecraftWorkdir(minecraftRoot());
return proc;
}
void OneSixInstance::cleanupAfterRun()
{
- QString target_dir = PathCombine(rootDir(), "natives/");
+ QString target_dir = PathCombine(instanceRoot(), "natives/");
QDir dir(target_dir);
dir.removeRecursively();
}
@@ -155,6 +155,7 @@ bool OneSixInstance::setIntendedVersionId ( QString version )
{
settings().set("IntendedVersion", version);
setShouldUpdate(true);
+ return true;
}
QString OneSixInstance::intendedVersionId() const
@@ -187,7 +188,7 @@ bool OneSixInstance::reloadFullVersion()
{
I_D(OneSixInstance);
- QString verpath = PathCombine(rootDir(), "version.json");
+ QString verpath = PathCombine(instanceRoot(), "version.json");
QFile versionfile(verpath);
if(versionfile.exists() && versionfile.open(QIODevice::ReadOnly))
{
diff --git a/backend/OneSixUpdate.cpp b/backend/OneSixUpdate.cpp
index 5506d9aa..5cd2c78c 100644
--- a/backend/OneSixUpdate.cpp
+++ b/backend/OneSixUpdate.cpp
@@ -38,6 +38,15 @@ OneSixUpdate::OneSixUpdate(BaseInstance *inst, QObject *parent):BaseUpdate(inst,
void OneSixUpdate::executeTask()
{
QString intendedVersion = m_inst->intendedVersionId();
+
+ // Make directories
+ QDir mcDir(m_inst->minecraftRoot());
+ if (!mcDir.exists() && !mcDir.mkpath("."))
+ {
+ emitFailed("Failed to create bin folder.");
+ return;
+ }
+
// Get a pointer to the version object that corresponds to the instance's version.
targetVersion = MinecraftVersionList::getMainList().findVersion(intendedVersion).dynamicCast<MinecraftVersion>();
if(targetVersion == nullptr)
@@ -78,7 +87,7 @@ void OneSixUpdate::versionFileFinished()
auto DlJob = firstJob.dynamicCast<DownloadJob>();
QString version_id = targetVersion->descriptor;
- QString inst_dir = m_inst->rootDir();
+ QString inst_dir = m_inst->instanceRoot();
// save the version file in $instanceId/version.json
{
QString version1 = PathCombine(inst_dir, "/version.json");
diff --git a/backend/OneSixUpdate.h b/backend/OneSixUpdate.h
index bab2d335..75575166 100644
--- a/backend/OneSixUpdate.h
+++ b/backend/OneSixUpdate.h
@@ -44,7 +44,6 @@ private slots:
void jarlibFailed();
private:
- JobListPtr legacyDownloadJob;
JobListPtr specificVersionDownloadJob;
JobListPtr jarlibDownloadJob;
JobListQueue download_queue;
diff --git a/backend/lists/MinecraftVersionList.cpp b/backend/lists/MinecraftVersionList.cpp
index bf0406dc..2e5f0cd7 100644
--- a/backend/lists/MinecraftVersionList.cpp
+++ b/backend/lists/MinecraftVersionList.cpp
@@ -141,8 +141,7 @@ MCVListLoadTask::MCVListLoadTask(MinecraftVersionList *vlist)
legacyWhitelist.insert("1.2.1");
legacyWhitelist.insert("1.1");
legacyWhitelist.insert("1.0.1");
- legacyWhitelist.insert("1.0.0");
- // TODO: consider adding betas here too (whatever the legacy launcher supports)
+ legacyWhitelist.insert("1.0");
}
MCVListLoadTask::~MCVListLoadTask()