summaryrefslogtreecommitdiffstats
path: root/backend/ModList.h
blob: bf65a080dabee5e7cef5a188c1afb3002633e311 (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
67
68
69
70
71
72
73
74
75
// 
//  Copyright 2012 MultiMC Contributors
// 
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
// 
//        http://www.apache.org/licenses/LICENSE-2.0
// 
#pragma once

class LegacyInstance;
class BaseInstance;
#include <QList>
#include <QString>
#include <QDir>

#include "Mod.h"

/**
 * A basic mod list.
 * Backed by a folder.
 */
class ModList : public QObject
{
	Q_OBJECT
public:
	ModList(const QString& dir = QString());

	size_t size() { return mods.size(); };
	Mod& operator[](size_t index) { return mods[index]; };
	
	/// Reloads the mod list and returns true if the list changed.
	virtual bool update();

	/// Adds the given mod to the list at the given index.
	virtual bool installMod(const QFileInfo& filename, size_t index = 0);

	/// Deletes the mod at the given index.
	virtual bool deleteMod(size_t index);
	
	/**
	 * move the mod at index to the position N
	 * 0 is the beginning of the list, length() is the end of the list.
	 */
	virtual bool moveMod(size_t from, size_t to) { return false; };
	
	virtual bool isValid();
	
signals:
	virtual void changed();
protected:
	QDir m_dir;
	QList<Mod> mods;
};

/**
 * A jar mod list.
 * Backed by a folder and a file which specifies the load order.
 */
class JarModList : public ModList
{
	Q_OBJECT
public:
	JarModList(const QString& dir, const QString& list_file, LegacyInstance * inst)
		: ModList(dir), m_listfile(list_file), m_inst(inst) {}

	virtual bool update();
	virtual bool installMod(const QString &filename, size_t index);
	virtual bool deleteMod(size_t index);
	virtual bool moveMod(size_t from, size_t to);
protected:
	QString m_listfile;
	LegacyInstance * m_inst;
};