aboutsummaryrefslogtreecommitdiff
path: root/src/content/content.cpp
blob: 66ef83d42bbfec76362f5512d7426bde565b39b3 (plain)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
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 modpack2_is((spec.path + DIR_DELIM + "modpack.conf").c_str());
	if (modpack2_is.good()) {
		modpack2_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 + "modpack.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 (conf.exists("release"))
			spec.release = conf.getS32("release");
	}

	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>());
	}
}
c">std::wstring::npos || plop == L"") { //std::cout<<"\t\tn == string::npos || plop == \"\""<<std::endl; n = tek.size(); } else { //std::cout<<"\t\tn != string::npos"<<std::endl; } palautus = tek.substr(p, n-p); p = n + plop.length(); } //else //std::cout<<"\tp>=tek.size()"<<std::endl; //std::cout<<"palautus=\""<<palautus<<"\""<<std::endl; return palautus; } bool atend(){ if(p>=tek.size()) return true; return false; } WStrfnd(std::wstring s){ start(s); } }; inline std::string trim(const std::string &s) { std::string str = s; while( str.length()>0 && ( str.substr(0, 1)==" " || str.substr(0, 1)=="\t" || str.substr(0, 1)=="\r" || str.substr(0, 1)=="\n" || str.substr(str.length()-1, 1)==" " || str.substr(str.length()-1, 1)=="\t" || str.substr(str.length()-1, 1)=="\r" || str.substr(str.length()-1, 1)=="\n" ) ) { if (str.substr(0, 1)==" ") str = str.substr(1,str.length()-1); else if (str.substr(0, 1)=="\t") str = str.substr(1,str.length()-1); else if (str.substr(0, 1)=="\r") str = str.substr(1,str.length()-1); else if (str.substr(0, 1)=="\n") str = str.substr(1,str.length()-1); else if (str.substr(str.length()-1, 1)==" ") str = str.substr(0,str.length()-1); else if (str.substr(str.length()-1, 1)=="\t") str = str.substr(0,str.length()-1); else if (str.substr(str.length()-1, 1)=="\r") str = str.substr(0,str.length()-1); else if (str.substr(str.length()-1, 1)=="\n") str = str.substr(0,str.length()-1);