3 Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "irrlichttypes.h"
32 class ModError : public std::exception
35 ModError(const std::string &s)
40 virtual ~ModError() throw()
42 virtual const char * what() const throw()
54 std::set<std::string> depends;
55 std::set<std::string> unsatisfied_depends;
57 std::map<std::string,ModSpec> modpack_content;
58 ModSpec(const std::string name_="", const std::string path_="",
59 const std::set<std::string> depends_=std::set<std::string>()):
63 unsatisfied_depends(depends_),
69 std::map<std::string,ModSpec> getModsInPath(std::string path);
71 // expands modpack contents, but does not replace them.
72 std::map<std::string, ModSpec> flattenModTree(std::map<std::string, ModSpec> mods);
74 // replaces modpack Modspecs with their content
75 std::vector<ModSpec> flattenMods(std::map<std::string,ModSpec> mods);
77 // removes Mods mentioned in exclude_mod_names
78 std::vector<ModSpec> filterMods(std::vector<ModSpec> mods,
79 std::set<std::string> exclude_mod_names);
81 // a ModConfiguration is a subset of installed mods, expected to have
82 // all dependencies fullfilled, so it can be used as a list of mods to
83 // load when the game starts.
84 class ModConfiguration
93 ModConfiguration(std::string worldpath);
95 // adds all mods in the given path. used for games, modpacks
96 // and world-specific mods (worldmods-folders)
97 void addModsInPath(std::string path)
99 addMods(flattenMods(getModsInPath(path)));
102 // adds all mods in the given path whose name does not appear
103 // in the exclude_mods set.
104 void addModsInPathFiltered(std::string path, std::set<std::string> exclude_mods);
106 // adds all mods in the set.
107 void addMods(std::vector<ModSpec> mods);
109 // checks if all dependencies are fullfilled.
112 return m_unsatisfied_mods.empty();
115 std::vector<ModSpec> getMods()
117 return m_sorted_mods;
120 std::list<ModSpec> getUnsatisfiedMods()
122 return m_unsatisfied_mods;
127 // mods with unmet dependencies. This is a list and not a
128 // vector because we want easy removal of elements at every
130 std::list<ModSpec> m_unsatisfied_mods;
132 // list of mods sorted such that they can be loaded in the
133 // given order with all dependencies being fullfilled. I.e.,
134 // every mod in this list has only dependencies on mods which
135 // appear earlier in the vector.
136 std::vector<ModSpec> m_sorted_mods;