mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
chore(clang-tidy): modernize the code
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
2b0b9824a3
commit
3435c6de48
8 changed files with 63 additions and 61 deletions
|
|
@ -230,7 +230,7 @@ int DataPack::compare(const Resource& other, SortType type) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool DataPack::applyFilter(QRegularExpression filter) const
|
||||
bool DataPack::applyFilter(const QRegularExpression& filter) const
|
||||
{
|
||||
if (filter.match(description()).hasMatch()) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class DataPack : public Resource {
|
|||
bool valid() 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;
|
||||
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ int Mod::compare(const Resource& other, SortType type) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool Mod::applyFilter(QRegularExpression filter) const
|
||||
bool Mod::applyFilter(const QRegularExpression& filter) const
|
||||
{
|
||||
if (filter.match(description()).hasMatch())
|
||||
return true;
|
||||
|
|
@ -225,8 +225,8 @@ auto Mod::authors() const -> QStringList
|
|||
|
||||
void Mod::finishResolvingWithDetails(ModDetails&& details)
|
||||
{
|
||||
m_is_resolving = false;
|
||||
m_is_resolved = true;
|
||||
m_isResolving = false;
|
||||
m_isResolved = true;
|
||||
|
||||
m_local_details = std::move(details);
|
||||
if (!iconPath().isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ class Mod : public Resource {
|
|||
bool valid() 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
|
||||
auto destroy(QDir& index_dir, bool preserve_metadata = false, bool attempt_trash = true) -> bool;
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@
|
|||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
|
||||
Resource::Resource(QFileInfo file_info)
|
||||
Resource::Resource(const QFileInfo& fileInfo)
|
||||
{
|
||||
setFile(fileInfo);
|
||||
}
|
||||
|
||||
void Resource::setFile(QFileInfo fileInfo)
|
||||
{
|
||||
m_file_info = std::move(fileInfo);
|
||||
m_fileInfo = std::move(fileInfo);
|
||||
parseFile();
|
||||
}
|
||||
|
||||
|
|
@ -37,23 +37,23 @@ std::tuple<QString, qint64> calculateFileSize(const QFileInfo& file)
|
|||
}
|
||||
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
|
||||
|
||||
void Resource::parseFile()
|
||||
{
|
||||
QString fileName{ m_file_info.fileName() };
|
||||
QString fileName{ m_fileInfo.fileName() };
|
||||
|
||||
m_type = ResourceType::UNKNOWN;
|
||||
|
||||
m_internal_id = fileName;
|
||||
m_internalId = fileName;
|
||||
|
||||
std::tie(m_size_str, m_size_info) = calculateFileSize(m_file_info);
|
||||
if (m_file_info.isDir()) {
|
||||
std::tie(m_sizeStr, m_sizeInfo) = calculateFileSize(m_fileInfo);
|
||||
if (m_fileInfo.isDir()) {
|
||||
m_type = ResourceType::FOLDER;
|
||||
m_name = fileName;
|
||||
} else if (m_file_info.isFile()) {
|
||||
} else if (m_fileInfo.isFile()) {
|
||||
if (fileName.endsWith(".disabled")) {
|
||||
fileName.chop(9);
|
||||
m_enabled = false;
|
||||
|
|
@ -75,7 +75,7 @@ void Resource::parseFile()
|
|||
m_name = fileName;
|
||||
}
|
||||
|
||||
m_changed_date_time = m_file_info.lastModified();
|
||||
m_changedDateTime = m_fileInfo.lastModified();
|
||||
}
|
||||
|
||||
auto Resource::name() const -> QString
|
||||
|
|
@ -120,7 +120,7 @@ void Resource::setMetadata(std::shared_ptr<Metadata::ModStruct>&& metadata)
|
|||
setStatus(ResourceStatus::Installed);
|
||||
}
|
||||
|
||||
m_metadata = metadata;
|
||||
m_metadata = std::move(metadata);
|
||||
}
|
||||
|
||||
QStringList Resource::issues() const
|
||||
|
|
@ -221,7 +221,7 @@ int Resource::compare(const Resource& other, SortType type) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool Resource::applyFilter(QRegularExpression filter) const
|
||||
bool Resource::applyFilter(const QRegularExpression& filter) const
|
||||
{
|
||||
if (filter.match(name()).hasMatch()) {
|
||||
return true;
|
||||
|
|
@ -238,7 +238,7 @@ bool Resource::enable(EnableAction action)
|
|||
return false;
|
||||
}
|
||||
|
||||
QString path = m_file_info.absoluteFilePath();
|
||||
QString path = m_fileInfo.absoluteFilePath();
|
||||
QFile file(path);
|
||||
|
||||
bool enable = true;
|
||||
|
|
@ -291,7 +291,7 @@ auto Resource::destroy(const QDir& indexDir, bool preserveMetadata, bool attempt
|
|||
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
|
||||
|
|
@ -313,20 +313,20 @@ bool Resource::isSymLinkUnder(const QString& instPath) const
|
|||
|
||||
auto instDir = QDir(instPath);
|
||||
|
||||
auto relAbsPath = instDir.relativeFilePath(m_file_info.absoluteFilePath());
|
||||
auto relCanonPath = instDir.relativeFilePath(m_file_info.canonicalFilePath());
|
||||
auto relAbsPath = instDir.relativeFilePath(m_fileInfo.absoluteFilePath());
|
||||
auto relCanonPath = instDir.relativeFilePath(m_fileInfo.canonicalFilePath());
|
||||
|
||||
return relAbsPath != relCanonPath;
|
||||
}
|
||||
|
||||
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 fileName = m_file_info.fileName();
|
||||
auto fileName = m_fileInfo.fileName();
|
||||
if (!m_enabled) {
|
||||
fileName.chop(9);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*/
|
||||
class Resource {
|
||||
public:
|
||||
Resource(const Resource&) = delete;
|
||||
Resource& operator=(const Resource&) = delete;
|
||||
|
||||
public:
|
||||
using Ptr = std::shared_ptr<Resource>;
|
||||
Resource(const QFileInfo& fileInfo);
|
||||
|
||||
Resource(QFileInfo file_info);
|
||||
Resource(QString file_path) : Resource(QFileInfo(file_path)) {}
|
||||
Resource(const QString& filePath) : Resource(QFileInfo(filePath)) {}
|
||||
|
||||
virtual ~Resource() = default;
|
||||
|
||||
void setFile(QFileInfo fileInfo);
|
||||
void parseFile();
|
||||
|
||||
auto fileinfo() const -> QFileInfo { return m_file_info; }
|
||||
auto dateTimeChanged() const -> QDateTime { return m_changed_date_time; }
|
||||
auto internalId() const -> QString { return m_internal_id; }
|
||||
auto fileinfo() const -> QFileInfo { return m_fileInfo; }
|
||||
auto dateTimeChanged() const -> QDateTime { return m_changedDateTime; }
|
||||
auto internalId() const -> QString { return m_internalId; }
|
||||
auto type() const -> ResourceType { return m_type; }
|
||||
bool enabled() const { return m_enabled; }
|
||||
auto getOriginalFileName() const -> QString;
|
||||
QString sizeStr() const { return m_size_str; }
|
||||
qint64 sizeInfo() const { return m_size_info; }
|
||||
QString sizeStr() const { return m_sizeStr; }
|
||||
qint64 sizeInfo() const { return m_sizeInfo; }
|
||||
|
||||
virtual auto name() const -> QString;
|
||||
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),
|
||||
* 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'.
|
||||
*
|
||||
|
|
@ -151,15 +152,15 @@ class Resource {
|
|||
*/
|
||||
bool enable(EnableAction action);
|
||||
|
||||
auto shouldResolve() const -> bool { return !m_is_resolving && !m_is_resolved; }
|
||||
auto isResolving() const -> bool { return m_is_resolving; }
|
||||
auto isResolved() const -> bool { return m_is_resolved; }
|
||||
auto resolutionTicket() const -> int { return m_resolution_ticket; }
|
||||
auto shouldResolve() const -> bool { return !m_isResolving && !m_isResolved; }
|
||||
auto isResolving() const -> bool { return m_isResolving; }
|
||||
auto isResolved() const -> bool { return m_isResolved; }
|
||||
auto resolutionTicket() const -> int { return m_resolutionTicket; }
|
||||
|
||||
void setResolving(bool resolving, int resolutionTicket)
|
||||
{
|
||||
m_is_resolving = resolving;
|
||||
m_resolution_ticket = resolutionTicket;
|
||||
m_isResolving = resolving;
|
||||
m_resolutionTicket = resolutionTicket;
|
||||
}
|
||||
|
||||
// Delete all files of this resource.
|
||||
|
|
@ -167,7 +168,7 @@ class Resource {
|
|||
// Delete the metadata only.
|
||||
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
|
||||
|
|
@ -182,12 +183,12 @@ class Resource {
|
|||
|
||||
protected:
|
||||
/* The file corresponding to this resource. */
|
||||
QFileInfo m_file_info;
|
||||
QFileInfo m_fileInfo{};
|
||||
/* 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. */
|
||||
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. */
|
||||
QString m_name;
|
||||
|
||||
|
|
@ -205,9 +206,9 @@ class Resource {
|
|||
QList<const char*> m_issues;
|
||||
|
||||
/* Used to keep trach of pending / concluded actions on the resource. */
|
||||
bool m_is_resolving = false;
|
||||
bool m_is_resolved = false;
|
||||
int m_resolution_ticket = 0;
|
||||
QString m_size_str;
|
||||
qint64 m_size_info;
|
||||
bool m_isResolving = false;
|
||||
bool m_isResolved = false;
|
||||
int m_resolutionTicket = 0;
|
||||
QString m_sizeStr;
|
||||
qint64 m_sizeInfo = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -344,9 +344,9 @@ ResourceDownloadDialog* ResourceDownloadDialog::createMod(QWidget* parent,
|
|||
pages.append(page);
|
||||
}
|
||||
if (APPLICATION->capabilities() & Application::SupportsFlame && FlameAPI::validateModLoaders(loaders)) {
|
||||
auto* page = Flame::createModPage(dialog, *instance);
|
||||
page->setSuppressInitialSearch(suppressInitialSearch);
|
||||
pages.append(page);
|
||||
auto* flamePage = Flame::createModPage(dialog, *instance);
|
||||
flamePage->setSuppressInitialSearch(suppressInitialSearch);
|
||||
pages.append(flamePage);
|
||||
}
|
||||
dialog->initPages(pages);
|
||||
return dialog;
|
||||
|
|
@ -364,9 +364,9 @@ ResourceDownloadDialog* ResourceDownloadDialog::createResourcePack(QWidget* pare
|
|||
page->setSuppressInitialSearch(suppressInitialSearch);
|
||||
pages.append(page);
|
||||
if (APPLICATION->capabilities() & Application::SupportsFlame) {
|
||||
auto* page = Flame::createResourcePackResourcePage(dialog, *instance);
|
||||
page->setSuppressInitialSearch(suppressInitialSearch);
|
||||
pages.append(page);
|
||||
auto* flamePage = Flame::createResourcePackResourcePage(dialog, *instance);
|
||||
flamePage->setSuppressInitialSearch(suppressInitialSearch);
|
||||
pages.append(flamePage);
|
||||
}
|
||||
dialog->initPages(pages);
|
||||
|
||||
|
|
@ -385,9 +385,9 @@ ResourceDownloadDialog* ResourceDownloadDialog::createTexturePack(QWidget* paren
|
|||
page->setSuppressInitialSearch(suppressInitialSearch);
|
||||
pages.append(page);
|
||||
if (APPLICATION->capabilities() & Application::SupportsFlame) {
|
||||
auto* page = Flame::createTexturePackResourcePage(dialog, *instance);
|
||||
page->setSuppressInitialSearch(suppressInitialSearch);
|
||||
pages.append(page);
|
||||
auto* flamePage = Flame::createTexturePackResourcePage(dialog, *instance);
|
||||
flamePage->setSuppressInitialSearch(suppressInitialSearch);
|
||||
pages.append(flamePage);
|
||||
}
|
||||
dialog->initPages(pages);
|
||||
|
||||
|
|
@ -406,9 +406,9 @@ ResourceDownloadDialog* ResourceDownloadDialog::createShaderPack(QWidget* parent
|
|||
page->setSuppressInitialSearch(suppressInitialSearch);
|
||||
pages.append(page);
|
||||
if (APPLICATION->capabilities() & Application::SupportsFlame) {
|
||||
auto* page = Flame::createShaderPackResourcePage(dialog, *instance);
|
||||
page->setSuppressInitialSearch(suppressInitialSearch);
|
||||
pages.append(page);
|
||||
auto* flamePage = Flame::createShaderPackResourcePage(dialog, *instance);
|
||||
flamePage->setSuppressInitialSearch(suppressInitialSearch);
|
||||
pages.append(flamePage);
|
||||
}
|
||||
dialog->initPages(pages);
|
||||
|
||||
|
|
@ -427,9 +427,9 @@ ResourceDownloadDialog* ResourceDownloadDialog::createDataPack(QWidget* parent,
|
|||
page->setSuppressInitialSearch(suppressInitialSearch);
|
||||
pages.append(page);
|
||||
if (APPLICATION->capabilities() & Application::SupportsFlame) {
|
||||
auto* page = Flame::createDataPackResourcePage(dialog, *instance);
|
||||
page->setSuppressInitialSearch(suppressInitialSearch);
|
||||
pages.append(page);
|
||||
auto* flamePage = Flame::createDataPackResourcePage(dialog, *instance);
|
||||
flamePage->setSuppressInitialSearch(suppressInitialSearch);
|
||||
pages.append(flamePage);
|
||||
}
|
||||
dialog->initPages(pages);
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ ResourceDownload::ResourceDescriptor prepareModDescriptor()
|
|||
}
|
||||
} // namespace
|
||||
|
||||
namespace ResourceDownload {
|
||||
ModPage::ModPage(ResourceDownloadDialog* dialog,
|
||||
BaseInstance& instance,
|
||||
ResourceProviderData p,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue