Files
update-client/Common/RuntimeProtectionPolicy.h
T

39 lines
1.2 KiB
C++
Raw Normal View History

#pragma once
#include <QDir>
#include <QSet>
#include <QString>
namespace UpdateClient
{
inline bool isRuntimeProtectedPath(const QString& path,
const QString& runtimeRelativePath)
{
const QString normalizedPath =
QDir::cleanPath(QDir::fromNativeSeparators(path)).toCaseFolded();
static const QSet<QString> protectedPaths{
QStringLiteral("bootstrap.exe"),
QStringLiteral("client.ini"),
QStringLiteral("config/app_config.json"),
QStringLiteral("config/local_state.json"),
QStringLiteral("config/client_identity.dat"),
QStringLiteral("config/version_policy.dat")
};
if (protectedPaths.contains(normalizedPath))
return true;
QString runtimePrefix = QDir::cleanPath(
QDir::fromNativeSeparators(runtimeRelativePath)).toCaseFolded();
if (runtimePrefix.isEmpty() || runtimePrefix == QStringLiteral("."))
return false;
while (runtimePrefix.startsWith(QStringLiteral("./")))
runtimePrefix.remove(0, 2);
for (const QString& protectedPath : protectedPaths) {
if (normalizedPath == runtimePrefix + QLatin1Char('/') + protectedPath)
return true;
}
return false;
}
}