Mark files as being downloaded from the web on Windows

This commit is contained in:
Nicolas Werner 2024-09-09 23:15:45 +02:00
parent 3b41d20506
commit b37909a2c8
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
6 changed files with 25 additions and 3 deletions

View file

@ -279,9 +279,10 @@ MxcImageProvider::download(const QString &id,
}
}
image.setText(QStringLiteral("mxc url"), "mxc://" + id);
if (image.save(fileInfo.absoluteFilePath(), "png"))
if (image.save(fileInfo.absoluteFilePath(), "png")) {
utils::markFileAsFromWeb(fileInfo.absoluteFilePath());
nhlog::ui()->debug("Wrote: {}", fileInfo.absoluteFilePath().toStdString());
else
} else
nhlog::ui()->debug("Failed to write: {}",
fileInfo.absoluteFilePath().toStdString());
@ -356,6 +357,7 @@ MxcImageProvider::download(const QString &id,
}
f.write(tempData.data(), tempData.size());
f.close();
utils::markFileAsFromWeb(fileInfo.absoluteFilePath());
if (encryptionInfo) {
tempData = mtx::crypto::to_string(

View file

@ -13,6 +13,7 @@
#include <QBuffer>
#include <QComboBox>
#include <QCryptographicHash>
#include <QFile>
#include <QGuiApplication>
#include <QImageReader>
#include <QProcessEnvironment>
@ -2230,3 +2231,18 @@ utils::parseMatrixUri(QString uri)
.vias = std::move(vias),
};
}
void
utils::markFileAsFromWeb(const QString &path [[maybe_unused]])
{
#ifdef Q_OS_WINDOWS
QFile file(path + ":Zone.Identifier");
if (!file.open(QIODevice::Truncate | QIODevice::WriteOnly)) {
nhlog::net()->error("Failed to open alternate stream for {}", path.toStdString());
return;
}
file.write("[ZoneTransfer]\nZoneId=3");
file.close();
#endif
}

View file

@ -215,4 +215,7 @@ struct MatrixUriParseResult
std::optional<MatrixUriParseResult>
parseMatrixUri(QString uri);
void
markFileAsFromWeb(const QString &file);
}

View file

@ -8,7 +8,6 @@
#include <QCommandLineParser>
#include <QDesktopServices>
#include <QDir>
#include <QFile>
#include <QFontDatabase>
#include <QLabel>
#include <QLibraryInfo>

View file

@ -1990,6 +1990,7 @@ TimelineModel::saveMedia(const QString &eventId) const
file.write(QByteArray(temp.data(), (int)temp.size()));
file.close();
utils::markFileAsFromWeb(filename);
return;
} catch (const std::exception &e) {

View file

@ -369,6 +369,7 @@ TimelineViewManager::saveMedia(QString mxcUrl)
file.write(QByteArray(data.data(), (int)data.size()));
file.close();
utils::markFileAsFromWeb(filename);
return;
} catch (const std::exception &e) {