chore: reformat code

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2022-10-01 22:45:28 +02:00
parent 65b960f904
commit ff7e984198
No known key found for this signature in database
GPG Key ID: C10411294912A422
2 changed files with 87 additions and 115 deletions

View File

@ -40,8 +40,8 @@
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
#include <QMimeData> #include <QMimeData>
#include <QSet>
#include <QPair> #include <QPair>
#include <QSet>
#include <QThread> #include <QThread>
#include <QTimer> #include <QTimer>
#include <QUuid> #include <QUuid>
@ -51,11 +51,11 @@
#include "FileSystem.h" #include "FileSystem.h"
#include "InstanceList.h" #include "InstanceList.h"
#include "InstanceTask.h" #include "InstanceTask.h"
#include "MMCTime.h"
#include "NullInstance.h" #include "NullInstance.h"
#include "WatchLock.h" #include "WatchLock.h"
#include "minecraft/MinecraftInstance.h" #include "minecraft/MinecraftInstance.h"
#include "settings/INISettingsObject.h" #include "settings/INISettingsObject.h"
#include "MMCTime.h"
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
#include <Windows.h> #include <Windows.h>
@ -132,7 +132,7 @@ int InstanceList::rowCount(const QModelIndex& parent) const
return m_instances.count(); return m_instances.count();
} }
int InstanceList::columnCount(const QModelIndex &parent) const int InstanceList::columnCount(const QModelIndex& parent) const
{ {
return ColumnCount; return ColumnCount;
} }
@ -301,7 +301,7 @@ void InstanceList::setInstanceGroup(const InstanceId& id, const GroupId& name)
if (changed) { if (changed) {
m_groupNameCache.insert(name); m_groupNameCache.insert(name);
auto idx = getInstIndex(inst.get()); auto idx = getInstIndex(inst.get());
emit dataChanged(index(idx, NameColumn), index(idx, NameColumn), {GroupRole }); emit dataChanged(index(idx, NameColumn), index(idx, NameColumn), { GroupRole });
saveGroupList(); saveGroupList();
} }
} }
@ -324,7 +324,7 @@ void InstanceList::deleteGroup(const QString& name)
removed = true; removed = true;
auto idx = getInstIndex(instance.get()); auto idx = getInstIndex(instance.get());
if (idx > 0) { if (idx > 0) {
emit dataChanged(index(idx, NameColumn), index(idx, NameColumn), {GroupRole }); emit dataChanged(index(idx, NameColumn), index(idx, NameColumn), { GroupRole });
} }
} }
} }
@ -361,16 +361,18 @@ bool InstanceList::trashInstance(const InstanceId& id)
} }
qDebug() << "Instance" << id << "has been trashed by the launcher."; qDebug() << "Instance" << id << "has been trashed by the launcher.";
m_trashHistory.push({id, inst->instanceRoot(), trashedLoc, cachedGroupId}); m_trashHistory.push({ id, inst->instanceRoot(), trashedLoc, cachedGroupId });
return true; return true;
} }
bool InstanceList::trashedSomething() { bool InstanceList::trashedSomething()
{
return !m_trashHistory.empty(); return !m_trashHistory.empty();
} }
void InstanceList::undoTrashInstance() { void InstanceList::undoTrashInstance()
{
if (m_trashHistory.empty()) { if (m_trashHistory.empty()) {
qWarning() << "Nothing to recover from trash."; qWarning() << "Nothing to recover from trash.";
return; return;
@ -599,7 +601,7 @@ InstancePtr InstanceList::getInstanceByManagedName(const QString& managed_name)
return {}; return {};
} }
QModelIndex InstanceList::getInstanceIndexById(const QString &id) const QModelIndex InstanceList::getInstanceIndexById(const QString& id) const
{ {
return index(getInstIndex(getInstanceById(id).get()), NameColumn); return index(getInstIndex(getInstanceById(id).get()), NameColumn);
} }
@ -638,13 +640,11 @@ InstancePtr InstanceList::loadInstance(const InstanceId& id)
QString inst_type = instanceSettings->get("InstanceType").toString(); QString inst_type = instanceSettings->get("InstanceType").toString();
// NOTE: Some PolyMC versions didn't save the InstanceType properly. We will just bank on the probability that this is probably a OneSix instance // NOTE: Some PolyMC versions didn't save the InstanceType properly. We will just bank on the probability that this is probably a OneSix
if (inst_type == "OneSix" || inst_type.isEmpty()) // instance
{ if (inst_type == "OneSix" || inst_type.isEmpty()) {
inst.reset(new MinecraftInstance(m_globalSettings, instanceSettings, instanceRoot)); inst.reset(new MinecraftInstance(m_globalSettings, instanceSettings, instanceRoot));
} } else {
else
{
inst.reset(new NullInstance(m_globalSettings, instanceSettings, instanceRoot)); inst.reset(new NullInstance(m_globalSettings, instanceSettings, instanceRoot));
} }
qDebug() << "Loaded instance " << inst->name() << " from " << inst->instanceRoot(); qDebug() << "Loaded instance " << inst->name() << " from " << inst->instanceRoot();
@ -828,9 +828,14 @@ class InstanceStaging : public Task {
Q_OBJECT Q_OBJECT
const unsigned minBackoff = 1; const unsigned minBackoff = 1;
const unsigned maxBackoff = 16; const unsigned maxBackoff = 16;
public: public:
InstanceStaging(InstanceList* parent, InstanceTask* child, QString stagingPath, InstanceName const& instanceName, QString groupName) InstanceStaging(InstanceList* parent, InstanceTask* child, QString stagingPath, InstanceName const& instanceName, QString groupName)
: m_parent(parent), backoff(minBackoff, maxBackoff), m_stagingPath(std::move(stagingPath)), m_instance_name(std::move(instanceName)), m_groupName(std::move(groupName)) : m_parent(parent)
, backoff(minBackoff, maxBackoff)
, m_stagingPath(std::move(stagingPath))
, m_instance_name(std::move(instanceName))
, m_groupName(std::move(groupName))
{ {
m_child.reset(child); m_child.reset(child);
connect(child, &Task::succeeded, this, &InstanceStaging::childSucceded); connect(child, &Task::succeeded, this, &InstanceStaging::childSucceded);
@ -854,10 +859,7 @@ class InstanceStaging : public Task {
return Task::abort(); return Task::abort();
} }
bool canAbort() const override bool canAbort() const override { return (m_child && m_child->canAbort()); }
{
return (m_child && m_child->canAbort());
}
protected: protected:
virtual void executeTask() override { m_child->start(); } virtual void executeTask() override { m_child->start(); }
@ -867,8 +869,7 @@ class InstanceStaging : public Task {
void childSucceded() void childSucceded()
{ {
unsigned sleepTime = backoff(); unsigned sleepTime = backoff();
if (m_parent->commitStagedInstance(m_stagingPath, m_instance_name, m_groupName, m_child->shouldOverride())) if (m_parent->commitStagedInstance(m_stagingPath, m_instance_name, m_groupName, m_child->shouldOverride())) {
{
emitSucceeded(); emitSucceeded();
return; return;
} }
@ -886,13 +887,10 @@ class InstanceStaging : public Task {
emitFailed(reason); emitFailed(reason);
} }
void childAborted() void childAborted() { emitAborted(); }
{
emitAborted();
}
private: private:
InstanceList * m_parent; InstanceList* m_parent;
/* /*
* WHY: the whole reason why this uses an exponential backoff retry scheme is antivirus on Windows. * WHY: the whole reason why this uses an exponential backoff retry scheme is antivirus on Windows.
* Basically, it starts messing things up while the launcher is extracting/creating instances * Basically, it starts messing things up while the launcher is extracting/creating instances
@ -931,7 +929,10 @@ QString InstanceList::getStagedInstancePath()
return path; return path;
} }
bool InstanceList::commitStagedInstance(const QString& path, InstanceName const& instanceName, const QString& groupName, bool should_override) bool InstanceList::commitStagedInstance(const QString& path,
InstanceName const& instanceName,
const QString& groupName,
bool should_override)
{ {
QDir dir; QDir dir;
QString instID; QString instID;

View File

@ -15,12 +15,12 @@
#pragma once #pragma once
#include <QObject>
#include <QAbstractTableModel> #include <QAbstractTableModel>
#include <QSet>
#include <QList> #include <QList>
#include <QStack> #include <QObject>
#include <QPair> #include <QPair>
#include <QSet>
#include <QStack>
#include "BaseInstance.h" #include "BaseInstance.h"
@ -32,21 +32,9 @@ using InstanceId = QString;
using GroupId = QString; using GroupId = QString;
using InstanceLocator = std::pair<InstancePtr, int>; using InstanceLocator = std::pair<InstancePtr, int>;
enum class InstCreateError enum class InstCreateError { NoCreateError = 0, NoSuchVersion, UnknownCreateError, InstExists, CantCreateDir };
{
NoCreateError = 0,
NoSuchVersion,
UnknownCreateError,
InstExists,
CantCreateDir
};
enum class GroupsState enum class GroupsState { NotLoaded, Steady, Dirty };
{
NotLoaded,
Steady,
Dirty
};
struct TrashHistoryItem { struct TrashHistoryItem {
QString id; QString id;
@ -55,26 +43,24 @@ struct TrashHistoryItem {
QString groupName; QString groupName;
}; };
class InstanceList : public QAbstractTableModel class InstanceList : public QAbstractTableModel {
{
Q_OBJECT Q_OBJECT
public: public:
explicit InstanceList(SettingsObjectPtr settings, const QString & instDir, QObject *parent = 0); explicit InstanceList(SettingsObjectPtr settings, const QString& instDir, QObject* parent = 0);
virtual ~InstanceList(); virtual ~InstanceList();
public: public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex& index, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override; Qt::ItemFlags flags(const QModelIndex& index) const override;
bool setData(const QModelIndex & index, const QVariant & value, int role) override; bool setData(const QModelIndex& index, const QVariant& value, int role) override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex& parent = QModelIndex()) const override;
enum Column enum Column {
{
IconColumn = 0, IconColumn = 0,
NameColumn, NameColumn,
GameVersionColumn, GameVersionColumn,
@ -84,32 +70,17 @@ public:
ColumnCount ColumnCount
}; };
enum AdditionalRoles enum AdditionalRoles { SortRole = Qt::UserRole + 1, GroupRole, InstanceIDRole };
{
SortRole = Qt::UserRole + 1,
GroupRole,
InstanceIDRole
};
/*! /*!
* \brief Error codes returned by functions in the InstanceList class. * \brief Error codes returned by functions in the InstanceList class.
* NoError Indicates that no error occurred. * NoError Indicates that no error occurred.
* UnknownError indicates that an unspecified error occurred. * UnknownError indicates that an unspecified error occurred.
*/ */
enum InstListError enum InstListError { NoError = 0, UnknownError };
{
NoError = 0,
UnknownError
};
InstancePtr at(int i) const InstancePtr at(int i) const { return m_instances.at(i); }
{
return m_instances.at(i);
}
int count() const int count() const { return m_instances.count(); }
{
return m_instances.count();
}
InstListError loadList(); InstListError loadList();
void saveNow(); void saveNow();
@ -118,21 +89,21 @@ public:
InstancePtr getInstanceById(QString id) const; InstancePtr getInstanceById(QString id) const;
/* O(n) */ /* O(n) */
InstancePtr getInstanceByManagedName(const QString& managed_name) const; InstancePtr getInstanceByManagedName(const QString& managed_name) const;
QModelIndex getInstanceIndexById(const QString &id) const; QModelIndex getInstanceIndexById(const QString& id) const;
QStringList getGroups(); QStringList getGroups();
bool isGroupCollapsed(const QString &groupName); bool isGroupCollapsed(const QString& groupName);
GroupId getInstanceGroup(const InstanceId & id) const; GroupId getInstanceGroup(const InstanceId& id) const;
void setInstanceGroup(const InstanceId & id, const GroupId& name); void setInstanceGroup(const InstanceId& id, const GroupId& name);
void deleteGroup(const GroupId & name); void deleteGroup(const GroupId& name);
bool trashInstance(const InstanceId &id); bool trashInstance(const InstanceId& id);
bool trashedSomething(); bool trashedSomething();
void undoTrashInstance(); void undoTrashInstance();
void deleteInstance(const InstanceId & id); void deleteInstance(const InstanceId& id);
// Wrap an instance creation task in some more task machinery and make it ready to be used // Wrap an instance creation task in some more task machinery and make it ready to be used
Task * wrapInstanceTask(InstanceTask * task); Task* wrapInstanceTask(InstanceTask* task);
/** /**
* Create a new empty staging area for instance creation and @return a path/key top commit it later. * Create a new empty staging area for instance creation and @return a path/key top commit it later.
@ -152,7 +123,7 @@ public:
* Destroy a previously created staging area given by @keyPath - used when creation fails. * Destroy a previously created staging area given by @keyPath - used when creation fails.
* Used by instance manipulation tasks. * Used by instance manipulation tasks.
*/ */
bool destroyStagingPath(const QString & keyPath); bool destroyStagingPath(const QString& keyPath);
int getTotalPlayTime(); int getTotalPlayTime();
@ -160,39 +131,39 @@ public:
Qt::DropActions supportedDropActions() const override; Qt::DropActions supportedDropActions() const override;
bool canDropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) const override; bool canDropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) const override;
bool dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) override; bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) override;
QStringList mimeTypes() const override; QStringList mimeTypes() const override;
QMimeData *mimeData(const QModelIndexList &indexes) const override; QMimeData* mimeData(const QModelIndexList& indexes) const override;
signals: signals:
void dataIsInvalid(); void dataIsInvalid();
void instancesChanged(); void instancesChanged();
void instanceSelectRequest(QString instanceId); void instanceSelectRequest(QString instanceId);
void groupsChanged(QSet<QString> groups); void groupsChanged(QSet<QString> groups);
public slots: public slots:
void on_InstFolderChanged(const Setting &setting, QVariant value); void on_InstFolderChanged(const Setting& setting, QVariant value);
void on_GroupStateChanged(const QString &group, bool collapsed); void on_GroupStateChanged(const QString& group, bool collapsed);
private slots: private slots:
void propertiesChanged(BaseInstance *inst); void propertiesChanged(BaseInstance* inst);
void providerUpdated(); void providerUpdated();
void instanceDirContentsChanged(const QString &path); void instanceDirContentsChanged(const QString& path);
private: private:
int getInstIndex(BaseInstance *inst) const; int getInstIndex(BaseInstance* inst) const;
void updateTotalPlayTime(); void updateTotalPlayTime();
void suspendWatch(); void suspendWatch();
void resumeWatch(); void resumeWatch();
void add(const QList<InstancePtr> &list); void add(const QList<InstancePtr>& list);
void loadGroupList(); void loadGroupList();
void saveGroupList(); void saveGroupList();
QList<InstanceId> discoverInstances(); QList<InstanceId> discoverInstances();
InstancePtr loadInstance(const InstanceId& id); InstancePtr loadInstance(const InstanceId& id);
private: private:
int m_watchLevel = 0; int m_watchLevel = 0;
int totalPlayTime = 0; int totalPlayTime = 0;
bool m_dirty = false; bool m_dirty = false;
@ -201,7 +172,7 @@ private:
SettingsObjectPtr m_globalSettings; SettingsObjectPtr m_globalSettings;
QString m_instDir; QString m_instDir;
QFileSystemWatcher * m_watcher; QFileSystemWatcher* m_watcher;
// FIXME: this is so inefficient that looking at it is almost painful. // FIXME: this is so inefficient that looking at it is almost painful.
QSet<QString> m_collapsedGroups; QSet<QString> m_collapsedGroups;
QMap<InstanceId, GroupId> m_instanceGroupIndex; QMap<InstanceId, GroupId> m_instanceGroupIndex;