change: support newest changes with packwiz regarding CF

This commit is contained in:
flow 2022-05-07 19:39:00 -03:00 committed by flow
parent 59d628208b
commit 0985adfd74
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
7 changed files with 46 additions and 18 deletions

View File

@ -30,7 +30,8 @@ auto ProviderCapabilities::hashType(Provider p) -> QStringList
case Provider::MODRINTH:
return { "sha512", "sha1" };
case Provider::FLAME:
return { "murmur2" };
// Try newer formats first, fall back to old format
return { "sha1", "md5", "murmur2" };
}
return {};
}
@ -51,7 +52,14 @@ auto ProviderCapabilities::hash(Provider p, QByteArray& data, QString type) -> Q
return QCryptographicHash::hash(data, QCryptographicHash::Sha512);
}
case Provider::FLAME:
// TODO
// If 'type' was specified, we use that
if (!type.isEmpty() && hashType(p).contains(type)) {
if(type == "sha1")
return QCryptographicHash::hash(data, QCryptographicHash::Sha1);
else if (type == "md5")
return QCryptographicHash::hash(data, QCryptographicHash::Md5);
}
break;
}
return {};

View File

@ -30,6 +30,17 @@ void FlameMod::loadIndexedPack(ModPlatform::IndexedPack& pack, QJsonObject& obj)
}
}
static QString enumToString(int hash_algorithm)
{
switch(hash_algorithm){
default:
case 1:
return "sha1";
case 2:
return "md5";
}
}
void FlameMod::loadIndexedPackVersions(ModPlatform::IndexedPack& pack,
QJsonArray& arr,
const shared_qobject_ptr<QNetworkAccessManager>& network,
@ -63,14 +74,14 @@ void FlameMod::loadIndexedPackVersions(ModPlatform::IndexedPack& pack,
file.fileName = Json::requireString(obj, "fileName");
auto hash_list = Json::ensureArray(obj, "hashes");
if(!hash_list.isEmpty()){
for(auto h : hash_list){
auto hash_entry = Json::ensureObject(h);
auto hash_types = ProviderCaps.hashType(ModPlatform::Provider::FLAME);
for(auto& hash_type : hash_types) {
if(hash_list.contains(hash_type)) {
file.hash = Json::requireString(hash_list, "value");
file.hash_type = hash_type;
break;
}
auto hash_algo = enumToString(Json::ensureInteger(hash_entry, "algo", 1, "algorithm"));
if(hash_types.contains(hash_algo)){
file.hash = Json::requireString(hash_entry, "value");
file.hash_type = hash_algo;
break;
}
}

View File

@ -14,9 +14,9 @@ namespace Packwiz {
// Helpers
static inline auto indexFileName(QString const& mod_name) -> QString
{
if(mod_name.endsWith(".toml"))
if(mod_name.endsWith(".pw.toml"))
return mod_name;
return QString("%1.toml").arg(mod_name);
return QString("%1.pw.toml").arg(mod_name);
}
static ModPlatform::ProviderCapabilities ProviderCaps;
@ -28,7 +28,14 @@ auto V1::createModFormat(QDir& index_dir, ModPlatform::IndexedPack& mod_pack, Mo
mod.name = mod_pack.name;
mod.filename = mod_version.fileName;
mod.url = mod_version.downloadUrl;
if(mod_pack.provider == ModPlatform::Provider::FLAME){
mod.mode = "metadata:curseforge";
}
else {
mod.mode = "url";
mod.url = mod_version.downloadUrl;
}
mod.hash_format = mod_version.hash_type;
mod.hash = mod_version.hash;
@ -84,6 +91,7 @@ void V1::updateModIndex(QDir& index_dir, Mod& mod)
addToStream("side", mod.side);
in_stream << QString("\n[download]\n");
addToStream("mode", mod.mode);
addToStream("url", mod.url.toString());
addToStream("hash-format", mod.hash_format);
addToStream("hash", mod.hash);
@ -186,6 +194,7 @@ auto V1::getIndexForMod(QDir& index_dir, QString& index_file_name) -> Mod
return {};
}
mod.mode = stringEntry(download_table, "mode");
mod.url = stringEntry(download_table, "url");
mod.hash_format = stringEntry(download_table, "hash-format");
mod.hash = stringEntry(download_table, "hash");

View File

@ -22,8 +22,8 @@ class V1 {
QString side {"both"};
// [download]
QString mode {};
QUrl url {};
// FIXME: make hash-format an enum
QString hash_format {};
QString hash {};
@ -42,11 +42,11 @@ class V1 {
auto version() -> QVariant& { return file_id; }
};
/* Generates the object representing the information in a mod.toml file via
/* Generates the object representing the information in a mod.pw.toml file via
* its common representation in the launcher, when downloading mods.
* */
static auto createModFormat(QDir& index_dir, ModPlatform::IndexedPack& mod_pack, ModPlatform::IndexedVersion& mod_version) -> Mod;
/* Generates the object representing the information in a mod.toml file via
/* Generates the object representing the information in a mod.pw.toml file via
* its common representation in the launcher.
* */
static auto createModFormat(QDir& index_dir, ::Mod& internal_mod) -> Mod;

View File

@ -14,7 +14,7 @@ class PackwizTest : public QObject {
QString source = QFINDTESTDATA("testdata");
QDir index_dir(source);
QString name_mod("borderless-mining.toml");
QString name_mod("borderless-mining.pw.toml");
QVERIFY(index_dir.entryList().contains(name_mod));
auto metadata = Packwiz::V1::getIndexForMod(index_dir, name_mod);
@ -39,10 +39,10 @@ class PackwizTest : public QObject {
QString source = QFINDTESTDATA("testdata");
QDir index_dir(source);
QString name_mod("screenshot-to-clipboard-fabric.toml");
QString name_mod("screenshot-to-clipboard-fabric.pw.toml");
QVERIFY(index_dir.entryList().contains(name_mod));
// Try without the .toml at the end
// Try without the .pw.toml at the end
name_mod.chop(5);
auto metadata = Packwiz::V1::getIndexForMod(index_dir, name_mod);