chore(clang-tidy): modernize the code

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2026-05-13 11:14:42 +03:00
parent 2b0b9824a3
commit 3435c6de48
No known key found for this signature in database
GPG key ID: 55EF5DA53DB36318
8 changed files with 63 additions and 61 deletions

View file

@ -230,7 +230,7 @@ int DataPack::compare(const Resource& other, SortType type) const
return 0; return 0;
} }
bool DataPack::applyFilter(QRegularExpression filter) const bool DataPack::applyFilter(const QRegularExpression& filter) const
{ {
if (filter.match(description()).hasMatch()) { if (filter.match(description()).hasMatch()) {
return true; return true;

View file

@ -59,7 +59,7 @@ class DataPack : public Resource {
bool valid() const override; bool valid() const override;
[[nodiscard]] int compare(const Resource& other, SortType type) const override; [[nodiscard]] int compare(const Resource& other, SortType type) const override;
[[nodiscard]] bool applyFilter(QRegularExpression filter) const override; [[nodiscard]] bool applyFilter(const QRegularExpression& filter) const override;
QString packFormatStr() const; QString packFormatStr() const;

View file

@ -123,7 +123,7 @@ int Mod::compare(const Resource& other, SortType type) const
return 0; return 0;
} }
bool Mod::applyFilter(QRegularExpression filter) const bool Mod::applyFilter(const QRegularExpression& filter) const
{ {
if (filter.match(description()).hasMatch()) if (filter.match(description()).hasMatch())
return true; return true;
@ -225,8 +225,8 @@ auto Mod::authors() const -> QStringList
void Mod::finishResolvingWithDetails(ModDetails&& details) void Mod::finishResolvingWithDetails(ModDetails&& details)
{ {
m_is_resolving = false; m_isResolving = false;
m_is_resolved = true; m_isResolved = true;
m_local_details = std::move(details); m_local_details = std::move(details);
if (!iconPath().isEmpty()) { if (!iconPath().isEmpty()) {

View file

@ -85,7 +85,7 @@ class Mod : public Resource {
bool valid() const override; bool valid() const override;
[[nodiscard]] int compare(const Resource& other, SortType type) const override; [[nodiscard]] int compare(const Resource& other, SortType type) const override;
[[nodiscard]] bool applyFilter(QRegularExpression filter) const override; [[nodiscard]] bool applyFilter(const QRegularExpression& filter) const override;
// Delete all the files of this mod // Delete all the files of this mod
auto destroy(QDir& index_dir, bool preserve_metadata = false, bool attempt_trash = true) -> bool; auto destroy(QDir& index_dir, bool preserve_metadata = false, bool attempt_trash = true) -> bool;

View file

@ -13,14 +13,14 @@
#include "minecraft/MinecraftInstance.h" #include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h" #include "minecraft/PackProfile.h"
Resource::Resource(QFileInfo file_info) Resource::Resource(const QFileInfo& fileInfo)
{ {
setFile(fileInfo); setFile(fileInfo);
} }
void Resource::setFile(QFileInfo fileInfo) void Resource::setFile(QFileInfo fileInfo)
{ {
m_file_info = std::move(fileInfo); m_fileInfo = std::move(fileInfo);
parseFile(); parseFile();
} }
@ -37,23 +37,23 @@ std::tuple<QString, qint64> calculateFileSize(const QFileInfo& file)
} }
return { QString("%1 %2").arg(QString::number(count), str), count }; return { QString("%1 %2").arg(QString::number(count), str), count };
} }
return { StringUtils::humanReadableFileSize(file.size(), true), file.size() }; return { StringUtils::humanReadableFileSize(static_cast<double>(file.size()), true), file.size() };
} }
} // namespace } // namespace
void Resource::parseFile() void Resource::parseFile()
{ {
QString fileName{ m_file_info.fileName() }; QString fileName{ m_fileInfo.fileName() };
m_type = ResourceType::UNKNOWN; m_type = ResourceType::UNKNOWN;
m_internal_id = fileName; m_internalId = fileName;
std::tie(m_size_str, m_size_info) = calculateFileSize(m_file_info); std::tie(m_sizeStr, m_sizeInfo) = calculateFileSize(m_fileInfo);
if (m_file_info.isDir()) { if (m_fileInfo.isDir()) {
m_type = ResourceType::FOLDER; m_type = ResourceType::FOLDER;
m_name = fileName; m_name = fileName;
} else if (m_file_info.isFile()) { } else if (m_fileInfo.isFile()) {
if (fileName.endsWith(".disabled")) { if (fileName.endsWith(".disabled")) {
fileName.chop(9); fileName.chop(9);
m_enabled = false; m_enabled = false;
@ -75,7 +75,7 @@ void Resource::parseFile()
m_name = fileName; m_name = fileName;
} }
m_changed_date_time = m_file_info.lastModified(); m_changedDateTime = m_fileInfo.lastModified();
} }
auto Resource::name() const -> QString auto Resource::name() const -> QString
@ -120,7 +120,7 @@ void Resource::setMetadata(std::shared_ptr<Metadata::ModStruct>&& metadata)
setStatus(ResourceStatus::Installed); setStatus(ResourceStatus::Installed);
} }
m_metadata = metadata; m_metadata = std::move(metadata);
} }
QStringList Resource::issues() const QStringList Resource::issues() const
@ -221,7 +221,7 @@ int Resource::compare(const Resource& other, SortType type) const
return 0; return 0;
} }
bool Resource::applyFilter(QRegularExpression filter) const bool Resource::applyFilter(const QRegularExpression& filter) const
{ {
if (filter.match(name()).hasMatch()) { if (filter.match(name()).hasMatch()) {
return true; return true;
@ -238,7 +238,7 @@ bool Resource::enable(EnableAction action)
return false; return false;
} }
QString path = m_file_info.absoluteFilePath(); QString path = m_fileInfo.absoluteFilePath();
QFile file(path); QFile file(path);
bool enable = true; bool enable = true;
@ -291,7 +291,7 @@ auto Resource::destroy(const QDir& indexDir, bool preserveMetadata, bool attempt
destroyMetadata(indexDir); destroyMetadata(indexDir);
} }
return (attemptTrash && FS::trash(m_file_info.filePath())) || FS::deletePath(m_file_info.filePath()); return (attemptTrash && FS::trash(m_fileInfo.filePath())) || FS::deletePath(m_fileInfo.filePath());
} }
auto Resource::destroyMetadata(const QDir& indexDir) -> void auto Resource::destroyMetadata(const QDir& indexDir) -> void
@ -313,20 +313,20 @@ bool Resource::isSymLinkUnder(const QString& instPath) const
auto instDir = QDir(instPath); auto instDir = QDir(instPath);
auto relAbsPath = instDir.relativeFilePath(m_file_info.absoluteFilePath()); auto relAbsPath = instDir.relativeFilePath(m_fileInfo.absoluteFilePath());
auto relCanonPath = instDir.relativeFilePath(m_file_info.canonicalFilePath()); auto relCanonPath = instDir.relativeFilePath(m_fileInfo.canonicalFilePath());
return relAbsPath != relCanonPath; return relAbsPath != relCanonPath;
} }
bool Resource::isMoreThanOneHardLink() const bool Resource::isMoreThanOneHardLink() const
{ {
return FS::hardLinkCount(m_file_info.absoluteFilePath()) > 1; return FS::hardLinkCount(m_fileInfo.absoluteFilePath()) > 1;
} }
auto Resource::getOriginalFileName() const -> QString auto Resource::getOriginalFileName() const -> QString
{ {
auto fileName = m_file_info.fileName(); auto fileName = m_fileInfo.fileName();
if (!m_enabled) { if (!m_enabled) {
fileName.chop(9); fileName.chop(9);
} }

View file

@ -89,28 +89,29 @@ enum class EnableAction : std::uint8_t { ENABLE, DISABLE, TOGGLE };
* Subclass it to add additional data / behavior, such as Mods or Resource packs. * Subclass it to add additional data / behavior, such as Mods or Resource packs.
*/ */
class Resource { class Resource {
public:
Resource(const Resource&) = delete; Resource(const Resource&) = delete;
Resource& operator=(const Resource&) = delete; Resource& operator=(const Resource&) = delete;
public: public:
using Ptr = std::shared_ptr<Resource>; using Ptr = std::shared_ptr<Resource>;
Resource(const QFileInfo& fileInfo);
Resource(QFileInfo file_info); Resource(const QString& filePath) : Resource(QFileInfo(filePath)) {}
Resource(QString file_path) : Resource(QFileInfo(file_path)) {}
virtual ~Resource() = default; virtual ~Resource() = default;
void setFile(QFileInfo fileInfo); void setFile(QFileInfo fileInfo);
void parseFile(); void parseFile();
auto fileinfo() const -> QFileInfo { return m_file_info; } auto fileinfo() const -> QFileInfo { return m_fileInfo; }
auto dateTimeChanged() const -> QDateTime { return m_changed_date_time; } auto dateTimeChanged() const -> QDateTime { return m_changedDateTime; }
auto internalId() const -> QString { return m_internal_id; } auto internalId() const -> QString { return m_internalId; }
auto type() const -> ResourceType { return m_type; } auto type() const -> ResourceType { return m_type; }
bool enabled() const { return m_enabled; } bool enabled() const { return m_enabled; }
auto getOriginalFileName() const -> QString; auto getOriginalFileName() const -> QString;
QString sizeStr() const { return m_size_str; } QString sizeStr() const { return m_sizeStr; }
qint64 sizeInfo() const { return m_size_info; } qint64 sizeInfo() const { return m_sizeInfo; }
virtual auto name() const -> QString; virtual auto name() const -> QString;
virtual bool valid() const { return m_type != ResourceType::UNKNOWN; } virtual bool valid() const { return m_type != ResourceType::UNKNOWN; }
@ -143,7 +144,7 @@ class Resource {
/** Returns whether the given filter should filter out 'this' (false), /** Returns whether the given filter should filter out 'this' (false),
* or if such filter includes the Resource (true). * or if such filter includes the Resource (true).
*/ */
virtual bool applyFilter(QRegularExpression filter) const; virtual bool applyFilter(const QRegularExpression& filter) const;
/** Changes the enabled property, according to 'action'. /** Changes the enabled property, according to 'action'.
* *
@ -151,15 +152,15 @@ class Resource {
*/ */
bool enable(EnableAction action); bool enable(EnableAction action);
auto shouldResolve() const -> bool { return !m_is_resolving && !m_is_resolved; } auto shouldResolve() const -> bool { return !m_isResolving && !m_isResolved; }
auto isResolving() const -> bool { return m_is_resolving; } auto isResolving() const -> bool { return m_isResolving; }
auto isResolved() const -> bool { return m_is_resolved; } auto isResolved() const -> bool { return m_isResolved; }
auto resolutionTicket() const -> int { return m_resolution_ticket; } auto resolutionTicket() const -> int { return m_resolutionTicket; }
void setResolving(bool resolving, int resolutionTicket) void setResolving(bool resolving, int resolutionTicket)
{ {
m_is_resolving = resolving; m_isResolving = resolving;
m_resolution_ticket = resolutionTicket; m_resolutionTicket = resolutionTicket;
} }
// Delete all files of this resource. // Delete all files of this resource.
@ -167,7 +168,7 @@ class Resource {
// Delete the metadata only. // Delete the metadata only.
auto destroyMetadata(const QDir& indexDir) -> void; auto destroyMetadata(const QDir& indexDir) -> void;
auto isSymLink() const -> bool { return m_file_info.isSymLink(); } auto isSymLink() const -> bool { return m_fileInfo.isSymLink(); }
/** /**
* @brief Take a instance path, checks if the file pointed to by the resource is a symlink or under a symlink in that instance * @brief Take a instance path, checks if the file pointed to by the resource is a symlink or under a symlink in that instance
@ -182,12 +183,12 @@ class Resource {
protected: protected:
/* The file corresponding to this resource. */ /* The file corresponding to this resource. */
QFileInfo m_file_info; QFileInfo m_fileInfo{};
/* The cached date when this file was last changed. */ /* The cached date when this file was last changed. */
QDateTime m_changed_date_time; QDateTime m_changedDateTime;
/* Internal ID for internal purposes. Properties such as human-readability should not be assumed. */ /* Internal ID for internal purposes. Properties such as human-readability should not be assumed. */
QString m_internal_id; QString m_internalId;
/* Name as reported via the file name. In the absence of a better name, this is shown to the user. */ /* Name as reported via the file name. In the absence of a better name, this is shown to the user. */
QString m_name; QString m_name;
@ -205,9 +206,9 @@ class Resource {
QList<const char*> m_issues; QList<const char*> m_issues;
/* Used to keep trach of pending / concluded actions on the resource. */ /* Used to keep trach of pending / concluded actions on the resource. */
bool m_is_resolving = false; bool m_isResolving = false;
bool m_is_resolved = false; bool m_isResolved = false;
int m_resolution_ticket = 0; int m_resolutionTicket = 0;
QString m_size_str; QString m_sizeStr;
qint64 m_size_info; qint64 m_sizeInfo = 0;
}; };

View file

@ -344,9 +344,9 @@ ResourceDownloadDialog* ResourceDownloadDialog::createMod(QWidget* parent,
pages.append(page); pages.append(page);
} }
if (APPLICATION->capabilities() & Application::SupportsFlame && FlameAPI::validateModLoaders(loaders)) { if (APPLICATION->capabilities() & Application::SupportsFlame && FlameAPI::validateModLoaders(loaders)) {
auto* page = Flame::createModPage(dialog, *instance); auto* flamePage = Flame::createModPage(dialog, *instance);
page->setSuppressInitialSearch(suppressInitialSearch); flamePage->setSuppressInitialSearch(suppressInitialSearch);
pages.append(page); pages.append(flamePage);
} }
dialog->initPages(pages); dialog->initPages(pages);
return dialog; return dialog;
@ -364,9 +364,9 @@ ResourceDownloadDialog* ResourceDownloadDialog::createResourcePack(QWidget* pare
page->setSuppressInitialSearch(suppressInitialSearch); page->setSuppressInitialSearch(suppressInitialSearch);
pages.append(page); pages.append(page);
if (APPLICATION->capabilities() & Application::SupportsFlame) { if (APPLICATION->capabilities() & Application::SupportsFlame) {
auto* page = Flame::createResourcePackResourcePage(dialog, *instance); auto* flamePage = Flame::createResourcePackResourcePage(dialog, *instance);
page->setSuppressInitialSearch(suppressInitialSearch); flamePage->setSuppressInitialSearch(suppressInitialSearch);
pages.append(page); pages.append(flamePage);
} }
dialog->initPages(pages); dialog->initPages(pages);
@ -385,9 +385,9 @@ ResourceDownloadDialog* ResourceDownloadDialog::createTexturePack(QWidget* paren
page->setSuppressInitialSearch(suppressInitialSearch); page->setSuppressInitialSearch(suppressInitialSearch);
pages.append(page); pages.append(page);
if (APPLICATION->capabilities() & Application::SupportsFlame) { if (APPLICATION->capabilities() & Application::SupportsFlame) {
auto* page = Flame::createTexturePackResourcePage(dialog, *instance); auto* flamePage = Flame::createTexturePackResourcePage(dialog, *instance);
page->setSuppressInitialSearch(suppressInitialSearch); flamePage->setSuppressInitialSearch(suppressInitialSearch);
pages.append(page); pages.append(flamePage);
} }
dialog->initPages(pages); dialog->initPages(pages);
@ -406,9 +406,9 @@ ResourceDownloadDialog* ResourceDownloadDialog::createShaderPack(QWidget* parent
page->setSuppressInitialSearch(suppressInitialSearch); page->setSuppressInitialSearch(suppressInitialSearch);
pages.append(page); pages.append(page);
if (APPLICATION->capabilities() & Application::SupportsFlame) { if (APPLICATION->capabilities() & Application::SupportsFlame) {
auto* page = Flame::createShaderPackResourcePage(dialog, *instance); auto* flamePage = Flame::createShaderPackResourcePage(dialog, *instance);
page->setSuppressInitialSearch(suppressInitialSearch); flamePage->setSuppressInitialSearch(suppressInitialSearch);
pages.append(page); pages.append(flamePage);
} }
dialog->initPages(pages); dialog->initPages(pages);
@ -427,9 +427,9 @@ ResourceDownloadDialog* ResourceDownloadDialog::createDataPack(QWidget* parent,
page->setSuppressInitialSearch(suppressInitialSearch); page->setSuppressInitialSearch(suppressInitialSearch);
pages.append(page); pages.append(page);
if (APPLICATION->capabilities() & Application::SupportsFlame) { if (APPLICATION->capabilities() & Application::SupportsFlame) {
auto* page = Flame::createDataPackResourcePage(dialog, *instance); auto* flamePage = Flame::createDataPackResourcePage(dialog, *instance);
page->setSuppressInitialSearch(suppressInitialSearch); flamePage->setSuppressInitialSearch(suppressInitialSearch);
pages.append(page); pages.append(flamePage);
} }
dialog->initPages(pages); dialog->initPages(pages);

View file

@ -68,6 +68,7 @@ ResourceDownload::ResourceDescriptor prepareModDescriptor()
} }
} // namespace } // namespace
namespace ResourceDownload {
ModPage::ModPage(ResourceDownloadDialog* dialog, ModPage::ModPage(ResourceDownloadDialog* dialog,
BaseInstance& instance, BaseInstance& instance,
ResourceProviderData p, ResourceProviderData p,