Commit cc0080b0 authored by DonLakeFlyer's avatar DonLakeFlyer

parent d2bfb99a
......@@ -225,11 +225,27 @@ bool JsonHelper::isJsonFile(const QByteArray& bytes, QJsonDocument& jsonDoc, QSt
if (parseError.error == QJsonParseError::NoError) {
return true;
} else {
int startPos = qMax(0, parseError.offset - 100);
int length = qMin(bytes.count() - startPos, 200);
qDebug() << QStringLiteral("Json read error '%1'").arg(bytes.mid(startPos, length).constData());
errorString = parseError.errorString();
return false;
}
}
bool JsonHelper::isJsonFile(const QString& fileName, QJsonDocument& jsonDoc, QString& errorString)
{
QFile jsonFile(fileName);
if (!jsonFile.open(QFile::ReadOnly)) {
errorString = tr("File open failed: file:error %1 %2").arg(jsonFile.fileName()).arg(jsonFile.errorString());
return false;
}
QByteArray jsonBytes = jsonFile.readAll();
jsonFile.close();
return isJsonFile(jsonBytes, jsonDoc, errorString);
}
bool JsonHelper::validateInternalQGCJsonFile(const QJsonObject& jsonObject,
const QString& expectedFileType,
int minSupportedVersion,
......
......@@ -26,6 +26,12 @@ class JsonHelper
Q_DECLARE_TR_FUNCTIONS(JsonHelper)
public:
/// Determines is the specified file is a json file
/// @return true: file is json, false: file is not json
static bool isJsonFile(const QString& fileName, ///< filename
QJsonDocument& jsonDoc, ///< returned json document
QString& errorString); ///< error on parse failure
/// Determines is the specified data is a json file
/// @return true: file is json, false: file is not json
static bool isJsonFile(const QByteArray& bytes, ///< json bytes
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment