More work on new assets system. Works given a properly constructed assets folder, no downloading yet
This commit is contained in:
@ -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++)
|
||||
{
|
||||
|
Reference in New Issue
Block a user