Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions src/dlicenseinfo.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

Expand All @@ -8,12 +8,19 @@

#include <QFile>
#include <QJsonParseError>
#include <QJsonObject>

Check warning on line 11 in src/dlicenseinfo.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QJsonArray>

Check warning on line 12 in src/dlicenseinfo.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonArray> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDebug>

Check warning on line 13 in src/dlicenseinfo.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QCoreApplication>

Check warning on line 14 in src/dlicenseinfo.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCoreApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QStandardPaths>

Check warning on line 15 in src/dlicenseinfo.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QStandardPaths> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DCORE_BEGIN_NAMESPACE

// /usr/share/spdx-licenses
constexpr auto SystemLicenseDir = "spdx-licenses";
constexpr auto CustomLicenseDir = "custom-licenses";
constexpr auto SystemConfigDir = "deepin/credits";

class DLicenseInfo::DComponentInfoPrivate : public DObjectPrivate
{
public:
Expand Down Expand Up @@ -88,8 +95,18 @@
clear();
}

bool DLicenseInfoPrivate::loadFile(const QString &file)

Check warning on line 98 in src/dlicenseinfo.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'file' shadows outer argument
{
clear();
if (file.isEmpty()) {
const QString relPath = QString("%1/%2.json").arg(SystemConfigDir, qApp->applicationName());
for (const QString &dataDir : QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation)) {
const QString file = dataDir + '/' + relPath;
if (QFile::exists(file))
return loadFile(file);
}
return false;
}
QFile jsonFile(file);
if (!jsonFile.open(QIODevice::ReadOnly)) {
qWarning() << QString("Failed on open file: \"%1\", error message: \"%2\"").arg(
Expand Down Expand Up @@ -141,24 +158,20 @@

QByteArray DLicenseInfoPrivate::licenseContent(const QString &licenseName)
{
QByteArray content;
QStringList dirs{"/usr/share/spdx-license"};
const QStringList dataDirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以用dtk的DStandardPaths

QStringList searchDirs;
if (!licenseSearchPath.isEmpty())
dirs.prepend(licenseSearchPath);
for (const QString &dir : dirs) {
QFile file(QString("%1/%2.txt").arg(dir).arg(licenseName));
if (!file.exists())
continue;
if (file.open(QIODevice::ReadOnly)) {
content = file.readAll();
file.close();
break;
}
}
if (content.isEmpty()) {
qWarning() << QString("License content is empty when getting license content!");
searchDirs << licenseSearchPath;
Comment thread
18202781743 marked this conversation as resolved.
for (const QString &dataDir : dataDirs)
for (const auto *dir : {CustomLicenseDir, SystemLicenseDir})
searchDirs << (dataDir + '/' + dir);

for (const QString &dir : searchDirs) {
QFile file(dir + '/' + licenseName + ".txt");
if (file.open(QIODevice::ReadOnly))
return file.readAll();
}
return content;
return {};
}

void DLicenseInfoPrivate::clear()
Expand Down
Loading