Skip to content

Commit

Permalink
Use Info.plist for docset name when meta.json is corrupt (fixes #310)
Browse files Browse the repository at this point in the history
  • Loading branch information
trollixx committed Apr 19, 2015
1 parent e8fc637 commit 9604c84
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/registry/docset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ Docset::Docset(const QString &path) :
else
return;

if (m_name.isEmpty()) {
// Fallback if meta.json is absent
if (!info.bundleName.isEmpty()) {
m_name = m_title = info.bundleName;
/// TODO: Remove when MainWindow::docsetName() will not use directory name
m_name.replace(QLatin1Char(' '), QLatin1Char('_'));
} else {
m_name = QFileInfo(m_path).fileName().remove(QStringLiteral(".docset"));
}
}

if (m_title.isEmpty()) {
m_title = m_name;
m_title.replace(QLatin1Char('_'), QLatin1Char(' '));
}

/// TODO: Verify if this is needed
if (info.family == QLatin1String("cheatsheet"))
m_name = m_name + QLatin1String("cheats");
Expand Down Expand Up @@ -293,11 +309,8 @@ void Docset::loadMetadata()
const QDir dir(m_path);

// Fallback if meta.json is absent
if (!dir.exists(QStringLiteral("meta.json"))) {
m_name = m_title = dir.dirName().remove(QStringLiteral(".docset"));
m_title = m_title.replace(QLatin1Char('_'), QLatin1Char(' '));
if (!dir.exists(QStringLiteral("meta.json")))
return;
}

QScopedPointer<QFile> file(new QFile(dir.filePath(QStringLiteral("meta.json"))));
if (!file->open(QIODevice::ReadOnly))
Expand Down

0 comments on commit 9604c84

Please sign in to comment.