3 Copyright (C) 2018 rubenwardy <rw@rubenwardy.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.
21 #include "content/content.h"
22 #include "content/subgames.h"
23 #include "content/mods.h"
36 ContentType getContentType(const ContentSpec &spec)
38 std::ifstream modpack_is((spec.path + DIR_DELIM + "modpack.txt").c_str());
39 if (modpack_is.good()) {
44 std::ifstream modpack2_is((spec.path + DIR_DELIM + "modpack.conf").c_str());
45 if (modpack2_is.good()) {
50 std::ifstream init_is((spec.path + DIR_DELIM + "init.lua").c_str());
56 std::ifstream game_is((spec.path + DIR_DELIM + "game.conf").c_str());
62 std::ifstream txp_is((spec.path + DIR_DELIM + "texture_pack.conf").c_str());
71 void parseContentInfo(ContentSpec &spec)
73 std::string conf_path;
75 switch (getContentType(spec)) {
78 conf_path = spec.path + DIR_DELIM + "mod.conf";
81 spec.type = "modpack";
82 conf_path = spec.path + DIR_DELIM + "modpack.conf";
86 conf_path = spec.path + DIR_DELIM + "game.conf";
90 conf_path = spec.path + DIR_DELIM + "texture_pack.conf";
93 spec.type = "unknown";
98 if (!conf_path.empty() && conf.readConfigFile(conf_path.c_str())) {
99 if (conf.exists("title"))
100 spec.title = conf.get("title");
101 else if (spec.type == "game" && conf.exists("name"))
102 spec.title = conf.get("name");
104 if (spec.type != "game" && conf.exists("name"))
105 spec.name = conf.get("name");
107 if (conf.exists("description"))
108 spec.desc = conf.get("description");
110 if (conf.exists("author"))
111 spec.author = conf.get("author");
113 if (conf.exists("release"))
114 spec.release = conf.getS32("release");
117 if (spec.desc.empty()) {
118 std::ifstream is((spec.path + DIR_DELIM + "description.txt").c_str());
119 spec.desc = std::string((std::istreambuf_iterator<char>(is)),
120 std::istreambuf_iterator<char>());