summaryrefslogtreecommitdiffstats
path: root/logic/OneSixInstance.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-12-08 22:19:58 +0100
committerPetr Mrázek <peterix@gmail.com>2013-12-08 22:19:58 +0100
commit8db2e5db81c91cca9291ca35ed74e632278563e6 (patch)
treeb4aa9ff8db2561e674e03027b05107a973e4d3a5 /logic/OneSixInstance.cpp
parentb0dbd4f4afcf60e4021cbb3218bfe280c4989859 (diff)
parent2fe27fd0daca14644a2a71456cd60c9a38befbdf (diff)
downloadMultiMC-8db2e5db81c91cca9291ca35ed74e632278563e6.tar
MultiMC-8db2e5db81c91cca9291ca35ed74e632278563e6.tar.gz
MultiMC-8db2e5db81c91cca9291ca35ed74e632278563e6.tar.lz
MultiMC-8db2e5db81c91cca9291ca35ed74e632278563e6.tar.xz
MultiMC-8db2e5db81c91cca9291ca35ed74e632278563e6.zip
Merge branch 'feature_assets' into develop
Diffstat (limited to 'logic/OneSixInstance.cpp')
-rw-r--r--logic/OneSixInstance.cpp65
1 files changed, 64 insertions, 1 deletions
diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp
index b18dd2ba..e804de11 100644
--- a/logic/OneSixInstance.cpp
+++ b/logic/OneSixInstance.cpp
@@ -26,6 +26,8 @@
#include <JlCompress.h>
#include "gui/dialogs/OneSixModEditDialog.h"
#include "logger/QsLog.h"
+#include "logic/assets/AssetsIndex.h"
+#include "logic/assets/AssetsUtils.h"
OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *setting_obj,
QObject *parent)
@@ -66,6 +68,63 @@ QString replaceTokensIn(QString text, QMap<QString, QString> with)
return result;
}
+QDir OneSixInstance::reconstructAssets(std::shared_ptr<OneSixVersion> version)
+{
+ QDir assetsDir = QDir("assets/");
+ QDir indexDir = QDir(PathCombine(assetsDir.path(), "indexes"));
+ QDir objectDir = QDir(PathCombine(assetsDir.path(), "objects"));
+ QDir virtualDir = QDir(PathCombine(assetsDir.path(), "virtual"));
+
+ QString indexPath = PathCombine(indexDir.path(), version->assets + ".json");
+ QFile indexFile(indexPath);
+ QDir virtualRoot(PathCombine(virtualDir.path(), version->assets));
+
+ if(!indexFile.exists())
+ {
+ QLOG_ERROR() << "No assets index file" << indexPath << "; can't reconstruct assets";
+ return virtualRoot;
+ }
+
+ QLOG_DEBUG() << "reconstructAssets" << assetsDir.path() << indexDir.path() << objectDir.path() << virtualDir.path() << virtualRoot.path();
+
+ AssetsIndex index;
+ bool loadAssetsIndex = AssetsUtils::loadAssetsIndexJson(indexPath, &index);
+
+ if(loadAssetsIndex)
+ {
+ if(index.isVirtual)
+ {
+ QLOG_INFO() << "Reconstructing virtual assets folder at" << virtualRoot.path();
+
+ for(QString map : index.objects->keys())
+ {
+ AssetObject asset_object = index.objects->value(map);
+ QString target_path = PathCombine(virtualRoot.path(), map);
+ QFile target(target_path);
+
+ QString tlk = asset_object.hash.left(2);
+
+ QString original_path = PathCombine(PathCombine(objectDir.path(), tlk), asset_object.hash);
+ QFile original(original_path);
+ if(!target.exists())
+ {
+ QFileInfo info(target_path);
+ QDir target_dir = info.dir();
+ //QLOG_DEBUG() << target_dir;
+ if(!target_dir.exists()) QDir("").mkpath(target_dir.path());
+
+ bool couldCopy = original.copy(target_path);
+ QLOG_DEBUG() << " Copying" << original_path << "to" << target_path << QString::number(couldCopy);// << original.errorString();
+ }
+ }
+
+ // TODO: Write last used time to virtualRoot/.lastused
+ }
+ }
+
+ return virtualRoot;
+}
+
QStringList OneSixInstance::processMinecraftArgs(MojangAccountPtr account)
{
I_D(OneSixInstance);
@@ -93,10 +152,14 @@ QStringList OneSixInstance::processMinecraftArgs(MojangAccountPtr account)
QString absRootDir = QDir(minecraftRoot()).absolutePath();
token_mapping["game_directory"] = absRootDir;
QString absAssetsDir = QDir("assets/").absolutePath();
- token_mapping["game_assets"] = absAssetsDir;
+ token_mapping["game_assets"] = reconstructAssets(d->version).absolutePath();
//TODO: this is something new and not even fully implemented in the vanilla launcher.
token_mapping["user_properties"] = "{ }";
+ // 1.7.3+ assets tokens
+ token_mapping["assets_root"] = absAssetsDir;
+ token_mapping["assets_index_name"] = version->assets;
+
QStringList parts = args_pattern.split(' ', QString::SkipEmptyParts);
for (int i = 0; i < parts.length(); i++)
{