2011-12-03 02:23:14 +01:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2011-12-03 02:23:14 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 16:56:56 +02:00
|
|
|
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
|
2011-12-03 02:23:14 +01:00
|
|
|
(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
|
2012-06-05 16:56:56 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2011-12-03 02:23:14 +01:00
|
|
|
|
2012-06-05 16:56:56 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2011-12-03 02:23:14 +01:00
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2011-12-11 15:49:40 +01:00
|
|
|
|
2011-12-03 02:23:14 +01:00
|
|
|
#include "irrlichttypes.h"
|
2012-12-08 18:10:54 +01:00
|
|
|
#include <list>
|
2011-12-03 02:23:14 +01:00
|
|
|
#include <set>
|
2012-12-08 18:10:54 +01:00
|
|
|
#include <vector>
|
2011-12-03 02:23:14 +01:00
|
|
|
#include <string>
|
2012-12-08 18:10:54 +01:00
|
|
|
#include <map>
|
2016-08-10 12:10:00 +02:00
|
|
|
#include <json/json.h>
|
2017-06-04 21:00:04 +02:00
|
|
|
#include <unordered_set>
|
2018-03-09 08:36:42 +01:00
|
|
|
#include "util/basic_macros.h"
|
2013-06-23 18:30:21 +02:00
|
|
|
#include "config.h"
|
2017-02-08 00:15:55 +01:00
|
|
|
#include "metadata.h"
|
2022-05-07 17:44:46 +02:00
|
|
|
#include "subgames.h"
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2022-01-07 19:28:49 +01:00
|
|
|
class ModMetadataDatabase;
|
|
|
|
|
2013-05-03 23:58:22 +02:00
|
|
|
#define MODNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_"
|
|
|
|
|
2011-12-03 02:23:14 +01:00
|
|
|
struct ModSpec
|
|
|
|
{
|
|
|
|
std::string name;
|
2018-04-17 15:54:50 +02:00
|
|
|
std::string author;
|
2011-12-03 02:23:14 +01:00
|
|
|
std::string path;
|
2018-03-28 23:14:16 +02:00
|
|
|
std::string desc;
|
2018-05-16 22:52:12 +02:00
|
|
|
int release = 0;
|
2018-03-28 23:14:16 +02:00
|
|
|
|
2018-04-17 15:54:50 +02:00
|
|
|
// if normal mod:
|
2017-06-04 21:00:04 +02:00
|
|
|
std::unordered_set<std::string> depends;
|
|
|
|
std::unordered_set<std::string> optdepends;
|
|
|
|
std::unordered_set<std::string> unsatisfied_depends;
|
2013-01-22 17:06:25 +01:00
|
|
|
|
2017-06-18 19:55:15 +02:00
|
|
|
bool part_of_modpack = false;
|
|
|
|
bool is_modpack = false;
|
2018-03-28 23:14:16 +02:00
|
|
|
|
2022-01-30 23:40:53 +01:00
|
|
|
/**
|
|
|
|
* A constructed canonical path to represent this mod's location.
|
|
|
|
* This intended to be used as an identifier for a modpath that tolerates file movement,
|
|
|
|
* and cannot be used to read the mod files.
|
|
|
|
*
|
|
|
|
* Note that `mymod` is the directory name, not the mod name specified in mod.conf.
|
|
|
|
*
|
|
|
|
* Ex:
|
|
|
|
*
|
|
|
|
* - mods/mymod
|
|
|
|
* - mods/mymod (1)
|
|
|
|
* (^ this would have name=mymod in mod.conf)
|
|
|
|
* - mods/modpack1/mymod
|
|
|
|
* - games/mygame/mods/mymod
|
|
|
|
* - worldmods/mymod
|
|
|
|
*/
|
|
|
|
std::string virtual_path;
|
|
|
|
|
2021-07-31 19:54:52 +02:00
|
|
|
// For logging purposes
|
|
|
|
std::vector<const char *> deprecation_msgs;
|
|
|
|
|
2012-12-08 18:10:54 +01:00
|
|
|
// if modpack:
|
2018-04-17 15:54:50 +02:00
|
|
|
std::map<std::string, ModSpec> modpack_content;
|
2022-01-30 23:40:53 +01:00
|
|
|
|
|
|
|
ModSpec()
|
2018-04-17 15:54:50 +02:00
|
|
|
{
|
|
|
|
}
|
2022-01-30 23:40:53 +01:00
|
|
|
|
|
|
|
ModSpec(const std::string &name, const std::string &path, bool part_of_modpack, const std::string &virtual_path) :
|
|
|
|
name(name), path(path), part_of_modpack(part_of_modpack), virtual_path(virtual_path)
|
2018-04-17 15:54:50 +02:00
|
|
|
{
|
|
|
|
}
|
2021-07-31 19:54:52 +02:00
|
|
|
|
|
|
|
void checkAndLog() const;
|
2011-12-03 02:23:14 +01:00
|
|
|
};
|
|
|
|
|
2022-05-07 17:44:46 +02:00
|
|
|
/**
|
|
|
|
* Retrieves depends, optdepends, is_modpack and modpack_content
|
|
|
|
*
|
|
|
|
* @returns false if not a mod
|
|
|
|
*/
|
|
|
|
bool parseModContents(ModSpec &mod);
|
2013-05-03 23:58:22 +02:00
|
|
|
|
2022-01-30 23:40:53 +01:00
|
|
|
/**
|
|
|
|
* Gets a list of all mods and modpacks in path
|
|
|
|
*
|
|
|
|
* @param Path to search, should be absolute
|
|
|
|
* @param part_of_modpack Is this searching within a modpack?
|
|
|
|
* @param virtual_path Virtual path for this directory, see comment in ModSpec
|
|
|
|
* @returns map of mods
|
|
|
|
*/
|
|
|
|
std::map<std::string, ModSpec> getModsInPath(const std::string &path,
|
|
|
|
const std::string &virtual_path, bool part_of_modpack = false);
|
2013-05-03 23:58:22 +02:00
|
|
|
|
2012-12-08 18:10:54 +01:00
|
|
|
// replaces modpack Modspecs with their content
|
2020-05-26 17:38:31 +02:00
|
|
|
std::vector<ModSpec> flattenMods(const std::map<std::string, ModSpec> &mods);
|
2012-12-08 18:10:54 +01:00
|
|
|
|
2017-01-27 07:41:10 +01:00
|
|
|
|
2018-04-17 15:54:50 +02:00
|
|
|
class ModMetadata : public Metadata
|
2017-02-08 00:15:55 +01:00
|
|
|
{
|
|
|
|
public:
|
2018-03-09 08:36:42 +01:00
|
|
|
ModMetadata() = delete;
|
2022-01-07 19:28:49 +01:00
|
|
|
ModMetadata(const std::string &mod_name, ModMetadataDatabase *database);
|
2017-08-18 18:18:25 +02:00
|
|
|
~ModMetadata() = default;
|
2017-02-08 00:15:55 +01:00
|
|
|
|
|
|
|
virtual void clear();
|
|
|
|
|
|
|
|
const std::string &getModName() const { return m_mod_name; }
|
|
|
|
|
|
|
|
virtual bool setString(const std::string &name, const std::string &var);
|
2018-04-17 15:54:50 +02:00
|
|
|
|
2017-02-08 00:15:55 +01:00
|
|
|
private:
|
|
|
|
std::string m_mod_name;
|
2022-01-07 19:28:49 +01:00
|
|
|
ModMetadataDatabase *m_database;
|
2017-02-08 00:15:55 +01:00
|
|
|
};
|