chore: reformat code
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
parent
65b960f904
commit
ff7e984198
@ -40,8 +40,8 @@
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QMimeData>
|
||||
#include <QSet>
|
||||
#include <QPair>
|
||||
#include <QSet>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
#include <QUuid>
|
||||
@ -51,11 +51,11 @@
|
||||
#include "FileSystem.h"
|
||||
#include "InstanceList.h"
|
||||
#include "InstanceTask.h"
|
||||
#include "MMCTime.h"
|
||||
#include "NullInstance.h"
|
||||
#include "WatchLock.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "settings/INISettingsObject.h"
|
||||
#include "MMCTime.h"
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
#include <Windows.h>
|
||||
@ -64,7 +64,7 @@
|
||||
const static int GROUP_FILE_FORMAT_VERSION = 1;
|
||||
|
||||
InstanceList::InstanceList(SettingsObjectPtr settings, const QString& instDir, QObject* parent)
|
||||
: QAbstractTableModel(parent), m_globalSettings(settings)
|
||||
: QAbstractTableModel(parent), m_globalSettings(settings)
|
||||
{
|
||||
resumeWatch();
|
||||
// Create aand normalize path
|
||||
@ -111,14 +111,14 @@ bool InstanceList::dropMimeData(const QMimeData* data, Qt::DropAction action, in
|
||||
|
||||
QStringList InstanceList::mimeTypes() const
|
||||
{
|
||||
auto types = QAbstractTableModel::mimeTypes();
|
||||
auto types = QAbstractTableModel::mimeTypes();
|
||||
types.push_back("application/x-instanceid");
|
||||
return types;
|
||||
}
|
||||
|
||||
QMimeData* InstanceList::mimeData(const QModelIndexList& indexes) const
|
||||
{
|
||||
auto mimeData = QAbstractTableModel::mimeData(indexes);
|
||||
auto mimeData = QAbstractTableModel::mimeData(indexes);
|
||||
if (indexes.size() == 1) {
|
||||
auto instanceId = data(indexes[0], InstanceIDRole).toString();
|
||||
mimeData->setData("application/x-instanceid", instanceId.toUtf8());
|
||||
@ -132,7 +132,7 @@ int InstanceList::rowCount(const QModelIndex& parent) const
|
||||
return m_instances.count();
|
||||
}
|
||||
|
||||
int InstanceList::columnCount(const QModelIndex &parent) const
|
||||
int InstanceList::columnCount(const QModelIndex& parent) const
|
||||
{
|
||||
return ColumnCount;
|
||||
}
|
||||
@ -249,7 +249,7 @@ bool InstanceList::setData(const QModelIndex& index, const QVariant& value, int
|
||||
return true;
|
||||
}
|
||||
inst->setName(newName);
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
Qt::ItemFlags InstanceList::flags(const QModelIndex& index) const
|
||||
@ -301,7 +301,7 @@ void InstanceList::setInstanceGroup(const InstanceId& id, const GroupId& name)
|
||||
if (changed) {
|
||||
m_groupNameCache.insert(name);
|
||||
auto idx = getInstIndex(inst.get());
|
||||
emit dataChanged(index(idx, NameColumn), index(idx, NameColumn), {GroupRole });
|
||||
emit dataChanged(index(idx, NameColumn), index(idx, NameColumn), { GroupRole });
|
||||
saveGroupList();
|
||||
}
|
||||
}
|
||||
@ -324,7 +324,7 @@ void InstanceList::deleteGroup(const QString& name)
|
||||
removed = true;
|
||||
auto idx = getInstIndex(instance.get());
|
||||
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.";
|
||||
m_trashHistory.push({id, inst->instanceRoot(), trashedLoc, cachedGroupId});
|
||||
m_trashHistory.push({ id, inst->instanceRoot(), trashedLoc, cachedGroupId });
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InstanceList::trashedSomething() {
|
||||
bool InstanceList::trashedSomething()
|
||||
{
|
||||
return !m_trashHistory.empty();
|
||||
}
|
||||
|
||||
void InstanceList::undoTrashInstance() {
|
||||
void InstanceList::undoTrashInstance()
|
||||
{
|
||||
if (m_trashHistory.empty()) {
|
||||
qWarning() << "Nothing to recover from trash.";
|
||||
return;
|
||||
@ -599,9 +601,9 @@ InstancePtr InstanceList::getInstanceByManagedName(const QString& managed_name)
|
||||
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);
|
||||
}
|
||||
|
||||
int InstanceList::getInstIndex(BaseInstance* inst) const
|
||||
@ -619,7 +621,7 @@ void InstanceList::propertiesChanged(BaseInstance* inst)
|
||||
{
|
||||
int i = getInstIndex(inst);
|
||||
if (i != -1) {
|
||||
emit dataChanged(index(i, IconColumn), index(i, ColumnCount - 1));
|
||||
emit dataChanged(index(i, IconColumn), index(i, ColumnCount - 1));
|
||||
updateTotalPlayTime();
|
||||
}
|
||||
}
|
||||
@ -638,13 +640,11 @@ InstancePtr InstanceList::loadInstance(const InstanceId& id)
|
||||
|
||||
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
|
||||
if (inst_type == "OneSix" || inst_type.isEmpty())
|
||||
{
|
||||
// NOTE: Some PolyMC versions didn't save the InstanceType properly. We will just bank on the probability that this is probably a OneSix
|
||||
// instance
|
||||
if (inst_type == "OneSix" || inst_type.isEmpty()) {
|
||||
inst.reset(new MinecraftInstance(m_globalSettings, instanceSettings, instanceRoot));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
inst.reset(new NullInstance(m_globalSettings, instanceSettings, instanceRoot));
|
||||
}
|
||||
qDebug() << "Loaded instance " << inst->name() << " from " << inst->instanceRoot();
|
||||
@ -828,9 +828,14 @@ class InstanceStaging : public Task {
|
||||
Q_OBJECT
|
||||
const unsigned minBackoff = 1;
|
||||
const unsigned maxBackoff = 16;
|
||||
|
||||
public:
|
||||
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);
|
||||
connect(child, &Task::succeeded, this, &InstanceStaging::childSucceded);
|
||||
@ -854,10 +859,7 @@ class InstanceStaging : public Task {
|
||||
|
||||
return Task::abort();
|
||||
}
|
||||
bool canAbort() const override
|
||||
{
|
||||
return (m_child && m_child->canAbort());
|
||||
}
|
||||
bool canAbort() const override { return (m_child && m_child->canAbort()); }
|
||||
|
||||
protected:
|
||||
virtual void executeTask() override { m_child->start(); }
|
||||
@ -867,8 +869,7 @@ class InstanceStaging : public Task {
|
||||
void childSucceded()
|
||||
{
|
||||
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();
|
||||
return;
|
||||
}
|
||||
@ -886,13 +887,10 @@ class InstanceStaging : public Task {
|
||||
emitFailed(reason);
|
||||
}
|
||||
|
||||
void childAborted()
|
||||
{
|
||||
emitAborted();
|
||||
}
|
||||
void childAborted() { emitAborted(); }
|
||||
|
||||
private:
|
||||
InstanceList * m_parent;
|
||||
private:
|
||||
InstanceList* m_parent;
|
||||
/*
|
||||
* 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
|
||||
@ -931,7 +929,10 @@ QString InstanceList::getStagedInstancePath()
|
||||
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;
|
||||
QString instID;
|
||||
|
@ -15,12 +15,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QAbstractTableModel>
|
||||
#include <QSet>
|
||||
#include <QList>
|
||||
#include <QStack>
|
||||
#include <QObject>
|
||||
#include <QPair>
|
||||
#include <QSet>
|
||||
#include <QStack>
|
||||
|
||||
#include "BaseInstance.h"
|
||||
|
||||
@ -32,21 +32,9 @@ using InstanceId = QString;
|
||||
using GroupId = QString;
|
||||
using InstanceLocator = std::pair<InstancePtr, int>;
|
||||
|
||||
enum class InstCreateError
|
||||
{
|
||||
NoCreateError = 0,
|
||||
NoSuchVersion,
|
||||
UnknownCreateError,
|
||||
InstExists,
|
||||
CantCreateDir
|
||||
};
|
||||
enum class InstCreateError { NoCreateError = 0, NoSuchVersion, UnknownCreateError, InstExists, CantCreateDir };
|
||||
|
||||
enum class GroupsState
|
||||
{
|
||||
NotLoaded,
|
||||
Steady,
|
||||
Dirty
|
||||
};
|
||||
enum class GroupsState { NotLoaded, Steady, Dirty };
|
||||
|
||||
struct TrashHistoryItem {
|
||||
QString id;
|
||||
@ -55,61 +43,44 @@ struct TrashHistoryItem {
|
||||
QString groupName;
|
||||
};
|
||||
|
||||
class InstanceList : public QAbstractTableModel
|
||||
{
|
||||
class InstanceList : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InstanceList(SettingsObjectPtr settings, const QString & instDir, QObject *parent = 0);
|
||||
public:
|
||||
explicit InstanceList(SettingsObjectPtr settings, const QString& instDir, QObject* parent = 0);
|
||||
virtual ~InstanceList();
|
||||
|
||||
public:
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
public:
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
QVariant data(const QModelIndex& index, int role) 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
|
||||
{
|
||||
IconColumn = 0,
|
||||
NameColumn,
|
||||
GameVersionColumn,
|
||||
PlayTimeColumn,
|
||||
LastPlayedColumn,
|
||||
enum Column {
|
||||
IconColumn = 0,
|
||||
NameColumn,
|
||||
GameVersionColumn,
|
||||
PlayTimeColumn,
|
||||
LastPlayedColumn,
|
||||
|
||||
ColumnCount
|
||||
};
|
||||
|
||||
enum AdditionalRoles
|
||||
{
|
||||
SortRole = Qt::UserRole + 1,
|
||||
GroupRole,
|
||||
InstanceIDRole
|
||||
ColumnCount
|
||||
};
|
||||
|
||||
enum AdditionalRoles { SortRole = Qt::UserRole + 1, GroupRole, InstanceIDRole };
|
||||
/*!
|
||||
* \brief Error codes returned by functions in the InstanceList class.
|
||||
* NoError Indicates that no error occurred.
|
||||
* UnknownError indicates that an unspecified error occurred.
|
||||
*/
|
||||
enum InstListError
|
||||
{
|
||||
NoError = 0,
|
||||
UnknownError
|
||||
};
|
||||
enum InstListError { NoError = 0, UnknownError };
|
||||
|
||||
InstancePtr at(int i) const
|
||||
{
|
||||
return m_instances.at(i);
|
||||
}
|
||||
InstancePtr at(int i) const { return m_instances.at(i); }
|
||||
|
||||
int count() const
|
||||
{
|
||||
return m_instances.count();
|
||||
}
|
||||
int count() const { return m_instances.count(); }
|
||||
|
||||
InstListError loadList();
|
||||
void saveNow();
|
||||
@ -118,21 +89,21 @@ public:
|
||||
InstancePtr getInstanceById(QString id) const;
|
||||
/* O(n) */
|
||||
InstancePtr getInstanceByManagedName(const QString& managed_name) const;
|
||||
QModelIndex getInstanceIndexById(const QString &id) const;
|
||||
QModelIndex getInstanceIndexById(const QString& id) const;
|
||||
QStringList getGroups();
|
||||
bool isGroupCollapsed(const QString &groupName);
|
||||
bool isGroupCollapsed(const QString& groupName);
|
||||
|
||||
GroupId getInstanceGroup(const InstanceId & id) const;
|
||||
void setInstanceGroup(const InstanceId & id, const GroupId& name);
|
||||
GroupId getInstanceGroup(const InstanceId& id) const;
|
||||
void setInstanceGroup(const InstanceId& id, const GroupId& name);
|
||||
|
||||
void deleteGroup(const GroupId & name);
|
||||
bool trashInstance(const InstanceId &id);
|
||||
void deleteGroup(const GroupId& name);
|
||||
bool trashInstance(const InstanceId& id);
|
||||
bool trashedSomething();
|
||||
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
|
||||
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.
|
||||
@ -152,7 +123,7 @@ public:
|
||||
* Destroy a previously created staging area given by @keyPath - used when creation fails.
|
||||
* Used by instance manipulation tasks.
|
||||
*/
|
||||
bool destroyStagingPath(const QString & keyPath);
|
||||
bool destroyStagingPath(const QString& keyPath);
|
||||
|
||||
int getTotalPlayTime();
|
||||
|
||||
@ -160,39 +131,39 @@ public:
|
||||
|
||||
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;
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const override;
|
||||
signals:
|
||||
QMimeData* mimeData(const QModelIndexList& indexes) const override;
|
||||
signals:
|
||||
void dataIsInvalid();
|
||||
void instancesChanged();
|
||||
void instanceSelectRequest(QString instanceId);
|
||||
void groupsChanged(QSet<QString> groups);
|
||||
|
||||
public slots:
|
||||
void on_InstFolderChanged(const Setting &setting, QVariant value);
|
||||
void on_GroupStateChanged(const QString &group, bool collapsed);
|
||||
public slots:
|
||||
void on_InstFolderChanged(const Setting& setting, QVariant value);
|
||||
void on_GroupStateChanged(const QString& group, bool collapsed);
|
||||
|
||||
private slots:
|
||||
void propertiesChanged(BaseInstance *inst);
|
||||
private slots:
|
||||
void propertiesChanged(BaseInstance* inst);
|
||||
void providerUpdated();
|
||||
void instanceDirContentsChanged(const QString &path);
|
||||
void instanceDirContentsChanged(const QString& path);
|
||||
|
||||
private:
|
||||
int getInstIndex(BaseInstance *inst) const;
|
||||
private:
|
||||
int getInstIndex(BaseInstance* inst) const;
|
||||
void updateTotalPlayTime();
|
||||
void suspendWatch();
|
||||
void resumeWatch();
|
||||
void add(const QList<InstancePtr> &list);
|
||||
void add(const QList<InstancePtr>& list);
|
||||
void loadGroupList();
|
||||
void saveGroupList();
|
||||
QList<InstanceId> discoverInstances();
|
||||
InstancePtr loadInstance(const InstanceId& id);
|
||||
|
||||
private:
|
||||
private:
|
||||
int m_watchLevel = 0;
|
||||
int totalPlayTime = 0;
|
||||
bool m_dirty = false;
|
||||
@ -201,7 +172,7 @@ private:
|
||||
|
||||
SettingsObjectPtr m_globalSettings;
|
||||
QString m_instDir;
|
||||
QFileSystemWatcher * m_watcher;
|
||||
QFileSystemWatcher* m_watcher;
|
||||
// FIXME: this is so inefficient that looking at it is almost painful.
|
||||
QSet<QString> m_collapsedGroups;
|
||||
QMap<InstanceId, GroupId> m_instanceGroupIndex;
|
||||
|
Loading…
x
Reference in New Issue
Block a user