fix: add support for QByteArray inifile

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-07-26 23:56:01 +03:00
parent a0944dab7a
commit 1e82cb6a7c
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
3 changed files with 24 additions and 9 deletions

View File

@ -1,9 +1,9 @@
#include "LocalModParseTask.h" #include "LocalModParseTask.h"
#include <qdcss.h>
#include <quazip/quazip.h> #include <quazip/quazip.h>
#include <quazip/quazipfile.h> #include <quazip/quazipfile.h>
#include <toml++/toml.h> #include <toml++/toml.h>
#include <qdcss.h>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
@ -369,12 +369,11 @@ ModDetails ReadQuiltModInfo(QByteArray contents)
details.icon_file = icon.toString(); details.icon_file = icon.toString();
} }
} }
} }
return details; return details;
} }
ModDetails ReadForgeInfo(QString fileName) ModDetails ReadForgeInfo(QByteArray contents)
{ {
ModDetails details; ModDetails details;
// Read the data // Read the data
@ -382,7 +381,7 @@ ModDetails ReadForgeInfo(QString fileName)
details.mod_id = "Forge"; details.mod_id = "Forge";
details.homeurl = "http://www.minecraftforge.net/forum/"; details.homeurl = "http://www.minecraftforge.net/forum/";
INIFile ini; INIFile ini;
if (!ini.loadFile(fileName)) if (!ini.loadFile(contents))
return details; return details;
QString major = ini.get("forge.major.number", "0").toString(); QString major = ini.get("forge.major.number", "0").toString();
@ -554,7 +553,7 @@ bool processZIP(Mod& mod, ProcessingLevel level)
return false; return false;
} }
details = ReadForgeInfo(file.getFileName()); details = ReadForgeInfo(file.readAll());
file.close(); file.close();
zip.close(); zip.close();

View File

@ -37,11 +37,12 @@
#include "settings/INIFile.h" #include "settings/INIFile.h"
#include <FileSystem.h> #include <FileSystem.h>
#include <QFile>
#include <QTextStream>
#include <QStringList>
#include <QSaveFile>
#include <QDebug> #include <QDebug>
#include <QFile>
#include <QSaveFile>
#include <QStringList>
#include <QTemporaryFile>
#include <QTextStream>
#include <QSettings> #include <QSettings>
@ -71,6 +72,7 @@ bool INIFile::saveFile(QString fileName)
return true; return true;
} }
QString unescape(QString orig) QString unescape(QString orig)
{ {
QString out; QString out;
@ -185,6 +187,19 @@ bool INIFile::loadFile(QString fileName)
return true; return true;
} }
bool INIFile::loadFile(QByteArray data)
{
QTemporaryFile file;
if (!file.open())
return false;
file.write(data);
file.flush();
file.close();
auto loaded = loadFile(file.fileName());
file.remove();
return loaded;
}
QVariant INIFile::get(QString key, QVariant def) const QVariant INIFile::get(QString key, QVariant def) const
{ {
if (!this->contains(key)) if (!this->contains(key))

View File

@ -50,6 +50,7 @@ public:
explicit INIFile(); explicit INIFile();
bool loadFile(QString fileName); bool loadFile(QString fileName);
bool loadFile(QByteArray data);
bool saveFile(QString fileName); bool saveFile(QString fileName);
QVariant get(QString key, QVariant def) const; QVariant get(QString key, QVariant def) const;