Skip to content
Merged
Show file tree
Hide file tree
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
48 changes: 47 additions & 1 deletion src/service/filehander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,47 @@
return result;
}

bool FileHander::pathControl(const QString &sPath)
{
if (sPath.isEmpty()) return false;

QStringList tmpLocation;
tmpLocation << QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
tmpLocation << QStandardPaths::standardLocations(QStandardPaths::PicturesLocation);
if (tmpLocation.empty()) {
qWarning() << "Failed to get standard locations";
return false;
}

QDBusMessage reply;
QDBusInterface iface("com.deepin.FileArmor1", "/com/deepin/FileArmor1", "com.deepin.FileArmor1", QDBusConnection::systemBus());
if (!iface.isValid()) {
qWarning() << "Failed to connect to D-Bus interface";
return false;
}

for (const QString &location : tmpLocation) {
if (sPath.startsWith(location)) {

Check warning on line 699 in src/service/filehander.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Consider using std::find_if algorithm instead of a raw loop.
qDebug() << "Check location:" << location;
reply = iface.call("GetApps", location);
break;
}
}

if (reply.type() == QDBusMessage::ReplyMessage) {
QList<QString> lValue = reply.arguments().takeFirst().toStringList();
qDebug() << "App list:" << lValue;
QString strApp = QStandardPaths::findExecutable("deepin-draw");
// 此路径对画板进行了权限禁用
if (!strApp.isEmpty() && lValue.contains(strApp)) {
qWarning() << "Permission denied for app:" << strApp;
return true;
}
}

return false;
}

PageContext *FileHander::loadDdf(const QString &file)
{
qDebug() << "Loading DDF file:" << file;
Expand Down Expand Up @@ -738,9 +779,14 @@
if (checkFileBeforeLoad(file, false)) {
auto legalPath = toLegalFile(file);
QImage img = loadImage_helper(legalPath, this);
if (img.isNull()) {
if (pathControl(legalPath)){
qWarning() << "Failed to load image: No permissions";
d_pri()->setError(EFileNotExist, tr("No permissions to open it"));
return QImage();
} else if (img.isNull()) {
qWarning() << "Failed to load image, file may be damaged";
d_pri()->setError(EDamagedImageFile, tr("Damaged file, unable to open it"));
return QImage();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
// 应用颜色空间转换,解决CMYK等格式的颜色显示问题 (仅Qt6)
Expand Down
4 changes: 4 additions & 0 deletions src/service/filehander.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class FileHander: public QObject

static bool isLegalFile(const QString &file);
static QString toLegalFile(const QString &file);
/**
* @brief pathControl 返回输入sPath文件是否被读写权限管控
*/
static bool pathControl(const QString &sPath);

PageContext *loadDdf(const QString &file);
bool saveToDdf(PageContext *context, const QString &file = "");
Expand Down
5 changes: 5 additions & 0 deletions translations/deepin-draw_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,11 @@
<source>Saving...</source>
<translation>正在保存...</translation>
</message>
<message>
<location filename="../src/service/filehander.cpp" line="650"/>
<source>No permissions to open it</source>
<translation>没有权限打开</translation>
</message>
<message>
<location filename="../src/service/filehander.cpp" line="651"/>
<source>Damaged file, unable to open it</source>
Expand Down