prevent json file read error
This commit is contained in:
parent
e10b5b1d39
commit
a0e3339bf7
|
@ -81,7 +81,9 @@ void AutolinkManager::load()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (file.open(QFile::ReadOnly)) {
|
if (file.open(QFile::ReadOnly)) {
|
||||||
QByteArray content = file.readAll();
|
QByteArray content = file.readAll().trimmed();
|
||||||
|
if (content.isEmpty())
|
||||||
|
return;
|
||||||
QJsonDocument doc(QJsonDocument::fromJson(content));
|
QJsonDocument doc(QJsonDocument::fromJson(content));
|
||||||
fromJson(doc.array());
|
fromJson(doc.array());
|
||||||
file.close();
|
file.close();
|
||||||
|
|
|
@ -82,7 +82,9 @@ void CodeSnippetsManager::loadSnippets()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray json = file.readAll();
|
QByteArray json = file.readAll().trimmed();
|
||||||
|
if (json.isEmpty())
|
||||||
|
return;
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(json,&error);
|
QJsonDocument doc = QJsonDocument::fromJson(json,&error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
|
|
|
@ -68,7 +68,9 @@ PColorScheme ColorScheme::load(const QString &filename)
|
||||||
qDebug()<<QObject::tr("Can't open file '%1' for read").arg(file.fileName());
|
qDebug()<<QObject::tr("Can't open file '%1' for read").arg(file.fileName());
|
||||||
return PColorScheme();
|
return PColorScheme();
|
||||||
}
|
}
|
||||||
QByteArray content = file.readAll();
|
QByteArray content = file.readAll().trimmed();
|
||||||
|
if (content.isEmpty())
|
||||||
|
return PColorScheme();
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(content,&error);
|
QJsonDocument doc = QJsonDocument::fromJson(content,&error);
|
||||||
if (error.error!=QJsonParseError::NoError) {
|
if (error.error!=QJsonParseError::NoError) {
|
||||||
|
|
|
@ -381,7 +381,9 @@ QList<PIconSet> IconsManager::listIconSets()
|
||||||
pSet->displayName = pSet->name;
|
pSet->displayName = pSet->name;
|
||||||
QFile infoFile(includeTrailingPathDelimiter(fileInfo.absoluteFilePath())+"info.json");
|
QFile infoFile(includeTrailingPathDelimiter(fileInfo.absoluteFilePath())+"info.json");
|
||||||
if (infoFile.exists() && infoFile.open(QFile::ReadOnly)) {
|
if (infoFile.exists() && infoFile.open(QFile::ReadOnly)) {
|
||||||
QByteArray content = infoFile.readAll();
|
QByteArray content = infoFile.readAll().trimmed();
|
||||||
|
if (content.isEmpty())
|
||||||
|
return result;
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument doc(QJsonDocument::fromJson(content,&error));
|
QJsonDocument doc(QJsonDocument::fromJson(content,&error));
|
||||||
if (error.error == QJsonParseError::NoError) {
|
if (error.error == QJsonParseError::NoError) {
|
||||||
|
|
|
@ -1928,7 +1928,9 @@ QHash<QString, PProjectEditorLayout> Project::loadLayout()
|
||||||
QFile file(jsonFilename);
|
QFile file(jsonFilename);
|
||||||
if (!file.open(QIODevice::ReadOnly))
|
if (!file.open(QIODevice::ReadOnly))
|
||||||
return layouts;
|
return layouts;
|
||||||
QByteArray content = file.readAll();
|
QByteArray content = file.readAll().trimmed();
|
||||||
|
if (content.isEmpty())
|
||||||
|
return layouts;
|
||||||
QJsonParseError parseError;
|
QJsonParseError parseError;
|
||||||
QJsonDocument doc(QJsonDocument::fromJson(content,&parseError));
|
QJsonDocument doc(QJsonDocument::fromJson(content,&parseError));
|
||||||
file.close();
|
file.close();
|
||||||
|
|
|
@ -46,7 +46,9 @@ void ShortcutManager::load()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray json = file.readAll();
|
QByteArray json = file.readAll().trimmed();
|
||||||
|
if (json.isEmpty())
|
||||||
|
return;
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(json,&error);
|
QJsonDocument doc = QJsonDocument::fromJson(json,&error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
|
|
|
@ -42,7 +42,9 @@ void SymbolUsageManager::load()
|
||||||
tr("Can't open symbol usage file '%1' for read.")
|
tr("Can't open symbol usage file '%1' for read.")
|
||||||
.arg(filename));
|
.arg(filename));
|
||||||
}
|
}
|
||||||
QByteArray contents = file.readAll();
|
QByteArray contents = file.readAll().trimmed();
|
||||||
|
if (contents.isEmpty())
|
||||||
|
return;
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(contents,&error);
|
QJsonDocument doc = QJsonDocument::fromJson(contents,&error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
|
|
|
@ -204,7 +204,9 @@ AppTheme::AppTheme(const QString &filename, ThemeType type, QObject *parent):QOb
|
||||||
.arg(filename));
|
.arg(filename));
|
||||||
}
|
}
|
||||||
if (file.open(QFile::ReadOnly)) {
|
if (file.open(QFile::ReadOnly)) {
|
||||||
QByteArray content = file.readAll();
|
QByteArray content = file.readAll().trimmed();
|
||||||
|
if (content.isEmpty())
|
||||||
|
return;
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
|
@ -69,7 +69,9 @@ void ToolsManager::load()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray json = file.readAll();
|
QByteArray json = file.readAll().trimmed();
|
||||||
|
if (json.isEmpty())
|
||||||
|
return;
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(json,&error);
|
QJsonDocument doc = QJsonDocument::fromJson(json,&error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
|
|
|
@ -96,8 +96,11 @@ PVisitHistory VisitHistoryManager::doLoad(const QString &filename, qint64 criter
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
if (!file.open(QFile::ReadOnly))
|
if (!file.open(QFile::ReadOnly))
|
||||||
return pHistory;
|
return pHistory;
|
||||||
|
QByteArray content = file.readAll().trimmed();
|
||||||
|
if (content.isEmpty())
|
||||||
|
return pHistory;
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument doc=QJsonDocument::fromJson(file.readAll(),&error);
|
QJsonDocument doc=QJsonDocument::fromJson(content, &error);
|
||||||
if (error.error!=QJsonParseError::NoError)
|
if (error.error!=QJsonParseError::NoError)
|
||||||
return pHistory;
|
return pHistory;
|
||||||
bool ok;
|
bool ok;
|
||||||
|
|
|
@ -174,7 +174,9 @@ void OJProblemSetModel::loadFromFile(const QString &fileName, int& currentIndex)
|
||||||
{
|
{
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
if (file.open(QFile::ReadOnly)) {
|
if (file.open(QFile::ReadOnly)) {
|
||||||
QByteArray content = file.readAll();
|
QByteArray content = file.readAll().trimmed();
|
||||||
|
if (content.isEmpty())
|
||||||
|
return;
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument doc(QJsonDocument::fromJson(content,&error));
|
QJsonDocument doc(QJsonDocument::fromJson(content,&error));
|
||||||
if (error.error!=QJsonParseError::NoError) {
|
if (error.error!=QJsonParseError::NoError) {
|
||||||
|
|
Loading…
Reference in New Issue