收敛稳定性风险

This commit is contained in:
2026-05-31 16:27:49 +08:00
parent 49fd9b3130
commit 4388a168f1
31 changed files with 1445 additions and 384 deletions
+66
View File
@@ -0,0 +1,66 @@
#include "ResourcePaths.h"
#include <QCoreApplication>
#include <QDir>
#include <QFileInfo>
namespace
{
QString cleanRelativePath(QString relativePath)
{
relativePath.replace(QLatin1Char('\\'), QLatin1Char('/'));
while (relativePath.startsWith(QLatin1Char('/')))
{
relativePath.remove(0, 1);
}
return QDir::cleanPath(relativePath);
}
QString appResourcesRootPath()
{
return QDir::cleanPath(QDir(QCoreApplication::applicationDirPath()).filePath(QStringLiteral("resources")));
}
QString sourceResourcesRootPath()
{
return QDir::cleanPath(QStringLiteral(PET_SOURCE_DIR) + QStringLiteral("/resources"));
}
}
QString ResourcePaths::resourcesRootPath()
{
const QString appResources = appResourcesRootPath();
if (QFileInfo::exists(appResources))
{
return appResources;
}
return sourceResourcesRootPath();
}
QString ResourcePaths::resourcePath(const QString &relativePath)
{
const QString cleanedRelativePath = cleanRelativePath(relativePath);
const QString appPath = QDir(appResourcesRootPath()).filePath(cleanedRelativePath);
if (QFileInfo::exists(appPath))
{
return QDir::cleanPath(appPath);
}
return QDir::cleanPath(QDir(sourceResourcesRootPath()).filePath(cleanedRelativePath));
}
QString ResourcePaths::charactersRootPath()
{
return resourcePath(QStringLiteral("characters"));
}
QString ResourcePaths::appIconPath()
{
return resourcePath(QStringLiteral("icons/app_icon.ico"));
}
QString ResourcePaths::appIconSourcePngPath()
{
return resourcePath(QStringLiteral("icons/app_icon_1024.png"));
}