diff options
author | Sefa Eyeoglu <contact@scrumplex.net> | 2022-08-28 11:03:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-28 11:03:12 +0200 |
commit | afcd669d2f6934c2b6076939d7665f791d495994 (patch) | |
tree | b5868b4e26fc52a6b48443847fbd7ef0aafee908 /launcher/modplatform/ModIndex.cpp | |
parent | fbf542d2051576ee25556c3b28112eea094da309 (diff) | |
parent | 7b27f200b1f131f0ea3b23433974cbe68eb979bb (diff) | |
download | PrismLauncher-afcd669d2f6934c2b6076939d7665f791d495994.tar.gz PrismLauncher-afcd669d2f6934c2b6076939d7665f791d495994.tar.bz2 PrismLauncher-afcd669d2f6934c2b6076939d7665f791d495994.zip |
Merge pull request #965 from flowln/fat_files_in_memory
Refactor a bit EnsureMetadataTask and calculate hashes in a incremental manner
Diffstat (limited to 'launcher/modplatform/ModIndex.cpp')
-rw-r--r-- | launcher/modplatform/ModIndex.cpp | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/launcher/modplatform/ModIndex.cpp b/launcher/modplatform/ModIndex.cpp index 3c4b7887..34fd9f30 100644 --- a/launcher/modplatform/ModIndex.cpp +++ b/launcher/modplatform/ModIndex.cpp @@ -19,6 +19,8 @@ #include "modplatform/ModIndex.h" #include <QCryptographicHash> +#include <QDebug> +#include <QIODevice> namespace ModPlatform { @@ -53,34 +55,26 @@ auto ProviderCapabilities::hashType(Provider p) -> QStringList } return {}; } -auto ProviderCapabilities::hash(Provider p, QByteArray& data, QString type) -> QByteArray + +auto ProviderCapabilities::hash(Provider p, QIODevice* device, QString type) -> QString { + QCryptographicHash::Algorithm algo = QCryptographicHash::Sha1; switch (p) { case Provider::MODRINTH: { - // NOTE: Data is the result of reading the entire JAR file! - - // If 'type' was specified, we use that - if (!type.isEmpty() && hashType(p).contains(type)) { - if (type == "sha512") - return QCryptographicHash::hash(data, QCryptographicHash::Sha512); - else if (type == "sha1") - return QCryptographicHash::hash(data, QCryptographicHash::Sha1); - } - - return QCryptographicHash::hash(data, QCryptographicHash::Sha512); + algo = (type == "sha1") ? QCryptographicHash::Sha1 : QCryptographicHash::Sha512; + break; } case Provider::FLAME: - // 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); - } - + algo = (type == "sha1") ? QCryptographicHash::Sha1 : QCryptographicHash::Md5; break; } - return {}; + + QCryptographicHash hash(algo); + if(!hash.addData(device)) + qCritical() << "Failed to read JAR to create hash!"; + + Q_ASSERT(hash.result().length() == hash.hashLength(algo)); + return { hash.result().toHex() }; } } // namespace ModPlatform |