summaryrefslogtreecommitdiffstats
path: root/api/logic/FolderInstanceProvider.h
blob: a8d1a7bf93cfa8116f699bfab79a38dc33f62ed1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once

#include "BaseInstanceProvider.h"
#include <QMap>

class QFileSystemWatcher;

class MULTIMC_LOGIC_EXPORT FolderInstanceProvider : public BaseInstanceProvider
{
	Q_OBJECT
public:
	FolderInstanceProvider(SettingsObjectPtr settings, const QString & instDir);

public:
	/// used by InstanceList to @return a list of plausible IDs to probe for
	QList<InstanceId> discoverInstances() override;

	/// 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);

	// migrate an instance to the current format
	Task * legacyUpgradeTask(const InstancePtr& oldInstance);

	/**
	 * Create a new empty staging area for instance creation and @return a path/key top commit it later.
	 * Used by instance manipulation tasks.
	 */
	QString getStagedInstancePath() override;
	/**
	 * Commit the staging area given by @keyPath to the provider - used when creation succeeds.
	 * Used by instance manipulation tasks.
	 */
	bool commitStagedInstance(const QString & keyPath, const QString& instanceName, const QString & groupName) override;
	/**
	 * Destroy a previously created staging area given by @keyPath - used when creation fails.
	 * Used by instance manipulation tasks.
	 */
	bool destroyStagingPath(const QString & keyPath) override;

public slots:
	void on_InstFolderChanged(const Setting &setting, QVariant value);

private slots:
	void instanceDirContentsChanged(const QString &path);
	void groupChanged();

private: /* methods */
	void loadGroupList() override;
	void saveGroupList() override;

private: /* data */
	QString m_instDir;
	QFileSystemWatcher * m_watcher;
	QMap<QString, QString> groupMap;
	bool m_groupsLoaded = false;
};