-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodmanager.cpp
More file actions
97 lines (76 loc) · 1.75 KB
/
modmanager.cpp
File metadata and controls
97 lines (76 loc) · 1.75 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "modmanager.h"
ModManager::ModManager(const QString &path)
{
_mod_path = path;
}
ModManager::~ModManager()
{
clear();
}
void ModManager::clear()
{
foreach(auto *mod, _mod_list)
delete mod;
_mod_list.clear();
}
void ModManager::update()
{
clear();
QDir dir(_mod_path);
QStringList file_name_list = dir.entryList(QStringList() << "*.jar" << "*.zip",
QDir::Files);
foreach(auto file_name, file_name_list)
append(_mod_path + "/" + file_name);
}
void ModManager::setPath(const QString &path)
{
_mod_path = path;
}
void ModManager::append(const QString &path)
{
if (ForgeMod::check(path))
{
ForgeMod *mod = new ForgeMod(path);
_mod_list.append(mod);
}
else
{
UnknownMod *mod = new UnknownMod(path);
_mod_list.append(mod);
}
}
QPixmap ModManager::logo(const int index)
{
return _mod_list.at(index)->logo();
}
bool ModManager::install(const QString &path)
{
if (!QFile::exists(path))
return false;
//??
QFileInfo fi(path);
QString new_path = _mod_path + "/" + fi.fileName();
//??
if (!QFile::copy(path, new_path))
return false;
append(new_path);
return true;
}
bool ModManager::remove(const int index)
{
QString path = _mod_list.at(index)->value("path");
if (!QFile::remove(path))
return false;
//
delete _mod_list.at(index);
_mod_list.removeAt(index);
return true;
}
QString ModManager::at(const int index, const QString &name)
{
return _mod_list.at(index)->value(name);
}
int ModManager::count()
{
return _mod_list.count();
}