SCRATCH things and stuff, related to grou saving
This commit is contained in:
@ -99,16 +99,11 @@ void BaseInstance::iconUpdated(QString key)
|
||||
void BaseInstance::invalidate()
|
||||
{
|
||||
changeStatus(Status::Gone);
|
||||
m_group = QString();
|
||||
emit groupChanged();
|
||||
qDebug() << "Instance" << id() << "has been invalidated.";
|
||||
}
|
||||
|
||||
void BaseInstance::nuke()
|
||||
{
|
||||
changeStatus(Status::Gone);
|
||||
qDebug() << "Instance" << id() << "has been deleted by MultiMC.";
|
||||
FS::deletePath(instanceRoot());
|
||||
}
|
||||
|
||||
void BaseInstance::changeStatus(BaseInstance::Status newStatus)
|
||||
{
|
||||
Status status = currentStatus();
|
||||
|
@ -72,10 +72,6 @@ public:
|
||||
virtual void init() = 0;
|
||||
virtual void saveNow() = 0;
|
||||
|
||||
/// nuke thoroughly - deletes the instance contents, notifies the list/model which is
|
||||
/// responsible of cleaning up the husk
|
||||
void nuke();
|
||||
|
||||
/***
|
||||
* the instance has been invalidated - it is no longer tracked by MultiMC for some reason,
|
||||
* but it has not necessarily been deleted.
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "multimc_logic_export.h"
|
||||
|
||||
using InstanceId = QString;
|
||||
using GroupId = QString;
|
||||
using InstanceLocator = std::pair<InstancePtr, int>;
|
||||
|
||||
enum class InstCreateError
|
||||
|
@ -48,6 +48,7 @@ FolderInstanceProvider::FolderInstanceProvider(SettingsObjectPtr settings, const
|
||||
|
||||
QList< InstanceId > FolderInstanceProvider::discoverInstances()
|
||||
{
|
||||
qDebug() << "Discovering instances in" << m_instDir;
|
||||
QList<InstanceId> out;
|
||||
QDirIterator iter(m_instDir, QDir::Dirs | QDir::NoDot | QDir::NoDotDot | QDir::Readable | QDir::Hidden, QDirIterator::FollowSymlinks);
|
||||
while (iter.hasNext())
|
||||
@ -71,6 +72,8 @@ QList< InstanceId > FolderInstanceProvider::discoverInstances()
|
||||
out.append(id);
|
||||
qDebug() << "Found instance ID" << id;
|
||||
}
|
||||
instanceSet = out.toSet();
|
||||
m_instancesProbed = true;
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -115,6 +118,12 @@ InstancePtr FolderInstanceProvider::loadInstance(const InstanceId& id)
|
||||
|
||||
void FolderInstanceProvider::saveGroupList()
|
||||
{
|
||||
qDebug() << "Will save group list now.";
|
||||
if(!m_instancesProbed)
|
||||
{
|
||||
qDebug() << "Group saving prevented because we don't know the full list of instances yet.";
|
||||
return;
|
||||
}
|
||||
WatchLock foo(m_watcher, m_instDir);
|
||||
QString groupFileName = m_instDir + "/instgroups.json";
|
||||
QMap<QString, QSet<QString>> reverseGroupMap;
|
||||
@ -124,6 +133,11 @@ void FolderInstanceProvider::saveGroupList()
|
||||
QString group = iter.value();
|
||||
if (group.isEmpty())
|
||||
continue;
|
||||
if(!instanceSet.contains(id))
|
||||
{
|
||||
qDebug() << "Skipping saving missing instance" << id << "to groups list.";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!reverseGroupMap.count(group))
|
||||
{
|
||||
@ -159,6 +173,7 @@ void FolderInstanceProvider::saveGroupList()
|
||||
try
|
||||
{
|
||||
FS::write(groupFileName, doc.toJson());
|
||||
qDebug() << "Group list saved.";
|
||||
}
|
||||
catch (const FS::FileSystemException &e)
|
||||
{
|
||||
@ -168,6 +183,7 @@ void FolderInstanceProvider::saveGroupList()
|
||||
|
||||
void FolderInstanceProvider::loadGroupList()
|
||||
{
|
||||
qDebug() << "Will load group list now.";
|
||||
QSet<QString> groupSet;
|
||||
|
||||
QString groupFileName = m_instDir + "/instgroups.json";
|
||||
@ -262,6 +278,7 @@ void FolderInstanceProvider::loadGroupList()
|
||||
}
|
||||
m_groupsLoaded = true;
|
||||
emit groupsChanged(groupSet);
|
||||
qDebug() << "Group list loaded.";
|
||||
}
|
||||
|
||||
void FolderInstanceProvider::groupChanged()
|
||||
@ -309,6 +326,7 @@ static void clamp(T& current, T min, T max)
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
// List of numbers from min to max. Next is exponent times bigger than previous.
|
||||
class ExponentialSeries
|
||||
{
|
||||
@ -335,12 +353,8 @@ public:
|
||||
unsigned m_max;
|
||||
unsigned m_exponent;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* WHY: the whole reason why this uses an exponential backoff retry scheme is antivirus on Windows.
|
||||
* Basically, it starts messing things up while MultiMC is extracting/creating instances
|
||||
* and causes that horrible failure that is NTFS to lock files in place because they are open.
|
||||
*/
|
||||
class FolderInstanceStaging : public Task
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -405,6 +419,11 @@ private slots:
|
||||
}
|
||||
|
||||
private:
|
||||
/*
|
||||
* WHY: the whole reason why this uses an exponential backoff retry scheme is antivirus on Windows.
|
||||
* Basically, it starts messing things up while MultiMC is extracting/creating instances
|
||||
* and causes that horrible failure that is NTFS to lock files in place because they are open.
|
||||
*/
|
||||
ExponentialSeries backoff;
|
||||
QString m_stagingPath;
|
||||
FolderInstanceProvider * m_parent;
|
||||
@ -449,6 +468,7 @@ bool FolderInstanceProvider::commitStagedInstance(const QString& path, const QSt
|
||||
return false;
|
||||
}
|
||||
groupMap[instID] = groupName;
|
||||
instanceSet.insert(instID);
|
||||
emit groupsChanged({groupName});
|
||||
emit instancesChanged();
|
||||
}
|
||||
|
@ -19,24 +19,6 @@ public:
|
||||
/// used by InstanceList to (re)load an instance with the given @id.
|
||||
InstancePtr loadInstance(const InstanceId& id) override;
|
||||
|
||||
|
||||
/*
|
||||
// create instance in this provider
|
||||
Task * creationTask(BaseVersionPtr version, const QString &instName, const QString &instGroup, const QString &instIcon);
|
||||
|
||||
// copy instance to this provider
|
||||
Task * copyTask(const InstancePtr &oldInstance, const QString& instName, const QString& instGroup, const QString& instIcon, bool copySaves);
|
||||
|
||||
// import zipped instance into this provider
|
||||
Task * zipImportTask(const QUrl sourceUrl, const QString &instName, const QString &instGroup, const QString &instIcon);
|
||||
|
||||
//create FtbInstance
|
||||
Task * ftbCreationTask(FtbPackDownloader *downloader, const QString &instName, const QString &instGroup, const QString &instIcon);
|
||||
|
||||
// migrate an instance to the current format
|
||||
Task * legacyUpgradeTask(const InstancePtr& oldInstance);
|
||||
*/
|
||||
|
||||
// Wrap an instance creation task in some more task machinery and make it ready to be used
|
||||
Task * wrapInstanceTask(InstanceTask * task);
|
||||
|
||||
@ -70,6 +52,8 @@ private: /* methods */
|
||||
private: /* data */
|
||||
QString m_instDir;
|
||||
QFileSystemWatcher * m_watcher;
|
||||
QMap<QString, QString> groupMap;
|
||||
QMap<InstanceId, GroupId> groupMap;
|
||||
QSet<InstanceId> instanceSet;
|
||||
bool m_groupsLoaded = false;
|
||||
bool m_instancesProbed = false;
|
||||
};
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "BaseInstance.h"
|
||||
|
||||
#include "FolderInstanceProvider.h"
|
||||
#include "FileSystem.h"
|
||||
|
||||
InstanceList::InstanceList(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
@ -118,6 +119,25 @@ void InstanceList::deleteGroup(const QString& name)
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceList::deleteInstance(const InstanceId& id)
|
||||
{
|
||||
auto inst = getInstanceById(id);
|
||||
if(!inst)
|
||||
{
|
||||
qDebug() << "Cannot delete instance" << id << " No such instance is present.";
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "Will delete instance" << id;
|
||||
if(!FS::deletePath(inst->instanceRoot()))
|
||||
{
|
||||
qWarning() << "Deletion of instance" << id << "has not been completely successful ...";
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "Instance" << id << "has been deleted by MultiMC.";
|
||||
}
|
||||
|
||||
static QMap<InstanceId, InstanceLocator> getIdMapping(const QList<InstancePtr> &list)
|
||||
{
|
||||
QMap<InstanceId, InstanceLocator> out;
|
||||
|
@ -80,7 +80,8 @@ public:
|
||||
QModelIndex getInstanceIndexById(const QString &id) const;
|
||||
QStringList getGroups();
|
||||
|
||||
void deleteGroup(const QString & name);
|
||||
void deleteGroup(const GroupId & name);
|
||||
void deleteInstance(const InstanceId & id);
|
||||
|
||||
signals:
|
||||
void dataIsInvalid();
|
||||
|
Reference in New Issue
Block a user