Chocobo1 2023-10-07 12:28:07 +08:00 committed by GitHub
parent c051ee9409
commit 34f7b75f12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 2 deletions

View file

@ -602,6 +602,27 @@ QString Utils::Misc::zlibVersionString()
}
#ifdef Q_OS_WIN
bool Utils::Misc::applyMarkOfTheWeb(const Path &file, const QString &url)
{
const QString zoneIDStream = file.toString() + u":Zone.Identifier";
HANDLE handle = ::CreateFileW(zoneIDStream.toStdWString().c_str(), GENERIC_WRITE
, (FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE)
, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (handle == INVALID_HANDLE_VALUE)
return false;
// 5.6.1 Zone.Identifier Stream Name
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/6e3f7352-d11c-4d76-8c39-2516a9df36e8
const QByteArray zoneID = QByteArrayLiteral("[ZoneTransfer]\r\nZoneId=3\r\n")
+ (!url.isEmpty() ? u"HostUrl=%1\r\n"_s.arg(url).toUtf8() : QByteArray());
DWORD written = 0;
const BOOL writeResult = ::WriteFile(handle, zoneID.constData(), zoneID.size(), &written, nullptr);
::CloseHandle(handle);
return writeResult && (written == zoneID.size());
}
Path Utils::Misc::windowsSystemPath()
{
static const Path path = []() -> Path