1 | package net.oni2.aeinstaller.backend.mods;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.io.FileFilter;
|
---|
5 | import java.util.Collection;
|
---|
6 | import java.util.HashMap;
|
---|
7 | import java.util.Vector;
|
---|
8 |
|
---|
9 | import net.oni2.aeinstaller.backend.Paths;
|
---|
10 | import net.oni2.aeinstaller.backend.depot.DepotManager;
|
---|
11 | import net.oni2.aeinstaller.backend.depot.model.NodeMod;
|
---|
12 | import net.oni2.aeinstaller.backend.depot.model.TaxonomyTerm;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * @author Christian Illy
|
---|
16 | */
|
---|
17 | public class ModManager {
|
---|
18 | // Download mods
|
---|
19 | // Update mods
|
---|
20 |
|
---|
21 | private static ModManager instance = new ModManager();
|
---|
22 |
|
---|
23 | private HashMap<String, Type> types = new HashMap<String, Type>();
|
---|
24 | private HashMap<Integer, Mod> mods = new HashMap<Integer, Mod>();
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * First initialization of ModManager
|
---|
28 | */
|
---|
29 | public void init() {
|
---|
30 | types = new HashMap<String, Type>();
|
---|
31 | mods = new HashMap<Integer, Mod>();
|
---|
32 |
|
---|
33 | types.put("-Local-", new Type("-Local-", null));
|
---|
34 |
|
---|
35 | for (TaxonomyTerm tt : DepotManager.getInstance()
|
---|
36 | .getTaxonomyTermsByVocabulary(
|
---|
37 | DepotManager.getInstance().getVocabIdType())) {
|
---|
38 | types.put(tt.getName(), new Type(tt.getName(), tt));
|
---|
39 | }
|
---|
40 |
|
---|
41 | HashMap<Integer, Mod> modFolders = new HashMap<Integer, Mod>();
|
---|
42 | if (Paths.getModsPath().exists()) {
|
---|
43 | for (File f : Paths.getModsPath().listFiles(new FileFilter() {
|
---|
44 | @Override
|
---|
45 | public boolean accept(File pathname) {
|
---|
46 | return pathname.isDirectory();
|
---|
47 | }
|
---|
48 | })) {
|
---|
49 | Mod m = new Mod(f);
|
---|
50 | modFolders.put(m.getPackageNumber(), m);
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | for (NodeMod nm : DepotManager.getInstance().getModPackageNodes()) {
|
---|
55 | if (nm.getUploads().size() == 1) {
|
---|
56 | Mod m = new Mod(nm);
|
---|
57 | mods.put(m.getPackageNumber(), m);
|
---|
58 | modFolders.remove(m.getPackageNumber());
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | for (Mod m : modFolders.values()) {
|
---|
63 | mods.put(m.getPackageNumber(), m);
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | public void refreshLocalMods() {
|
---|
68 | // TODO: evtl nur private e.g. als listener für downloads?
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * @return Singleton instance
|
---|
73 | */
|
---|
74 | public static ModManager getInstance() {
|
---|
75 | return instance;
|
---|
76 | }
|
---|
77 |
|
---|
78 | Type getTypeByName(String name) {
|
---|
79 | return types.get(name);
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * @return Collection of types which do have mods associated
|
---|
84 | */
|
---|
85 | public Collection<Type> getTypesWithContent() {
|
---|
86 | Vector<Type> res = new Vector<Type>();
|
---|
87 | for (Type t : types.values()) {
|
---|
88 | if (t.getEntries().size() > 0)
|
---|
89 | res.add(t);
|
---|
90 | }
|
---|
91 | return res;
|
---|
92 | }
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * @return Collection of mods
|
---|
96 | */
|
---|
97 | public Collection<Mod> getMods() {
|
---|
98 | return mods.values();
|
---|
99 | }
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * @return Mods which are always installed
|
---|
103 | */
|
---|
104 | public Collection<Mod> getDefaultMods() {
|
---|
105 | Vector<Mod> res = new Vector<Mod>();
|
---|
106 | for (Mod m : mods.values()) {
|
---|
107 | if (m.isDefaultMod())
|
---|
108 | res.add(m);
|
---|
109 | }
|
---|
110 | return res;
|
---|
111 | }
|
---|
112 | }
|
---|