summaryrefslogtreecommitdiff
path: root/src/content/content.cpp
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-04-17 14:54:50 +0100
committerrubenwardy <rw@rubenwardy.com>2018-04-19 20:14:53 +0100
commit87ad4d8e7f25210cd28d9f2b372aa00aa3dab929 (patch)
treeddeeed2ddca984f0999437517bfdca120919ecd2 /src/content/content.cpp
parent36eb823b1cebc92cd7802368ab0bdc5b3679a3cd (diff)
downloadminetest-87ad4d8e7f25210cd28d9f2b372aa00aa3dab929.tar.gz
minetest-87ad4d8e7f25210cd28d9f2b372aa00aa3dab929.tar.bz2
minetest-87ad4d8e7f25210cd28d9f2b372aa00aa3dab929.zip
Add online content repository
Replaces mods and texture pack tabs with a single content tab
Diffstat (limited to 'src/content/content.cpp')
-rw-r--r--src/content/content.cpp108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/content/content.cpp b/src/content/content.cpp
new file mode 100644
index 000000000..d45c5feab
--- /dev/null
+++ b/src/content/content.cpp
@@ -0,0 +1,108 @@
+/*
+Minetest
+Copyright (C) 2018 rubenwardy <rw@rubenwardy.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include <fstream>
+#include "content/content.h"
+#include "content/subgames.h"
+#include "content/mods.h"
+#include "filesys.h"
+#include "settings.h"
+
+enum ContentType
+{
+ ECT_UNKNOWN,
+ ECT_MOD,
+ ECT_MODPACK,
+ ECT_GAME,
+ ECT_TXP
+};
+
+ContentType getContentType(const ContentSpec &spec)
+{
+ std::ifstream modpack_is((spec.path + DIR_DELIM + "modpack.txt").c_str());
+ if (modpack_is.good()) {
+ modpack_is.close();
+ return ECT_MODPACK;
+ }
+
+ std::ifstream init_is((spec.path + DIR_DELIM + "init.lua").c_str());
+ if (init_is.good()) {
+ init_is.close();
+ return ECT_MOD;
+ }
+
+ std::ifstream game_is((spec.path + DIR_DELIM + "game.conf").c_str());
+ if (game_is.good()) {
+ game_is.close();
+ return ECT_GAME;
+ }
+
+ std::ifstream txp_is((spec.path + DIR_DELIM + "texture_pack.conf").c_str());
+ if (txp_is.good()) {
+ txp_is.close();
+ return ECT_TXP;
+ }
+
+ return ECT_UNKNOWN;
+}
+
+void parseContentInfo(ContentSpec &spec)
+{
+ std::string conf_path;
+
+ switch (getContentType(spec)) {
+ case ECT_MOD:
+ spec.type = "mod";
+ conf_path = spec.path + DIR_DELIM + "mod.conf";
+ break;
+ case ECT_MODPACK:
+ spec.type = "modpack";
+ conf_path = spec.path + DIR_DELIM + "mod.conf";
+ break;
+ case ECT_GAME:
+ spec.type = "game";
+ conf_path = spec.path + DIR_DELIM + "game.conf";
+ break;
+ case ECT_TXP:
+ spec.type = "txp";
+ conf_path = spec.path + DIR_DELIM + "texture_pack.conf";
+ break;
+ default:
+ spec.type = "unknown";
+ break;
+ }
+
+ Settings conf;
+ if (!conf_path.empty() && conf.readConfigFile(conf_path.c_str())) {
+ if (conf.exists("name"))
+ spec.name = conf.get("name");
+
+ if (conf.exists("description"))
+ spec.desc = conf.get("description");
+
+ if (conf.exists("author"))
+ spec.author = conf.get("author");
+ }
+
+ if (spec.desc.empty()) {
+ std::ifstream is((spec.path + DIR_DELIM + "description.txt").c_str());
+ spec.desc = std::string((std::istreambuf_iterator<char>(is)),
+ std::istreambuf_iterator<char>());
+ }
+}