2011-12-02 17:23:14 -08:00
|
|
|
/*
|
2013-02-24 09:40:43 -08:00
|
|
|
Minetest
|
2013-02-24 10:38:45 -08:00
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2011-12-02 17:23:14 -08:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 07:56:56 -07: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-02 17:23:14 -08: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 07:56:56 -07:00
|
|
|
GNU Lesser General Public License for more details.
|
2011-12-02 17:23:14 -08:00
|
|
|
|
2012-06-05 07:56:56 -07:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2011-12-02 17:23:14 -08: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 13:19:39 -07:00
|
|
|
#pragma once
|
2011-12-11 06:49:40 -08:00
|
|
|
|
2011-12-02 17:23:14 -08:00
|
|
|
#include "irrlichttypes.h"
|
2012-12-08 09:10:54 -08:00
|
|
|
#include <list>
|
2011-12-02 17:23:14 -08:00
|
|
|
#include <set>
|
2012-12-08 09:10:54 -08:00
|
|
|
#include <vector>
|
2011-12-02 17:23:14 -08:00
|
|
|
#include <string>
|
2012-12-08 09:10:54 -08:00
|
|
|
#include <map>
|
2016-08-10 03:10:00 -07:00
|
|
|
#include <json/json.h>
|
2017-06-04 12:00:04 -07:00
|
|
|
#include <unordered_set>
|
2018-03-08 23:36:42 -08:00
|
|
|
#include "util/basic_macros.h"
|
2013-06-23 09:30:21 -07:00
|
|
|
#include "config.h"
|
2017-02-07 15:15:55 -08:00
|
|
|
#include "metadata.h"
|
2022-05-07 08:44:46 -07:00
|
|
|
#include "subgames.h"
|
2013-06-23 09:30:21 -07:00
|
|
|
|
2022-01-07 10:28:49 -08:00
|
|
|
class ModMetadataDatabase;
|
|
|
|
|
2013-05-03 14:58:22 -07:00
|
|
|
#define MODNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_"
|
|
|
|
|
2011-12-02 17:23:14 -08:00
|
|
|
struct ModSpec
|
|
|
|
{
|
|
|
|
std::string name;
|
2018-04-17 06:54:50 -07:00
|
|
|
std::string author;
|
2011-12-02 17:23:14 -08:00
|
|
|
std::string path;
|
2018-03-28 14:14:16 -07:00
|
|
|
std::string desc;
|
2018-05-16 13:52:12 -07:00
|
|
|
int release = 0;
|
2018-03-28 14:14:16 -07:00
|
|
|
|
2018-04-17 06:54:50 -07:00
|
|
|
// if normal mod:
|
2017-06-04 12:00:04 -07:00
|
|
|
std::unordered_set<std::string> depends;
|
|
|
|
std::unordered_set<std::string> optdepends;
|
|
|
|
std::unordered_set<std::string> unsatisfied_depends;
|
2013-01-22 08:06:25 -08:00
|
|
|
|
2017-06-18 10:55:15 -07:00
|
|
|
bool part_of_modpack = false;
|
|
|
|
bool is_modpack = false;
|
2018-03-28 14:14:16 -07:00
|
|
|
|
2022-01-30 14:40:53 -08: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 10:54:52 -07:00
|
|
|
// For logging purposes
|
|
|
|
std::vector<const char *> deprecation_msgs;
|
|
|
|
|
2012-12-08 09:10:54 -08:00
|
|
|
// if modpack:
|
2018-04-17 06:54:50 -07:00
|
|
|
std::map<std::string, ModSpec> modpack_content;
|
2022-01-30 14:40:53 -08:00
|
|
|
|
|
|
|
ModSpec()
|
2018-04-17 06:54:50 -07:00
|
|
|
{
|
|
|
|
}
|
2022-01-30 14:40:53 -08: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 06:54:50 -07:00
|
|
|
{
|
|
|
|
}
|
2021-07-31 10:54:52 -07:00
|
|
|
|
|
|
|
void checkAndLog() const;
|
2011-12-02 17:23:14 -08:00
|
|
|
};
|
|
|
|
|
2022-05-07 08:44:46 -07:00
|
|
|
/**
|
|
|
|
* Retrieves depends, optdepends, is_modpack and modpack_content
|
|
|
|
*
|
|
|
|
* @returns false if not a mod
|
|
|
|
*/
|
|
|
|
bool parseModContents(ModSpec &mod);
|
2013-05-03 14:58:22 -07:00
|
|
|
|
2022-01-30 14:40:53 -08: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 14:58:22 -07:00
|
|
|
|
2012-12-08 09:10:54 -08:00
|
|
|
// replaces modpack Modspecs with their content
|
2020-05-26 08:38:31 -07:00
|
|
|
std::vector<ModSpec> flattenMods(const std::map<std::string, ModSpec> &mods);
|
2012-12-08 09:10:54 -08:00
|
|
|
|
2017-01-26 22:41:10 -08:00
|
|
|
|
2018-04-17 06:54:50 -07:00
|
|
|
class ModMetadata : public Metadata
|
2017-02-07 15:15:55 -08:00
|
|
|
{
|
|
|
|
public:
|
2018-03-08 23:36:42 -08:00
|
|
|
ModMetadata() = delete;
|
2022-01-07 10:28:49 -08:00
|
|
|
ModMetadata(const std::string &mod_name, ModMetadataDatabase *database);
|
2017-08-18 09:18:25 -07:00
|
|
|
~ModMetadata() = default;
|
2017-02-07 15:15:55 -08: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 06:54:50 -07:00
|
|
|
|
2017-02-07 15:15:55 -08:00
|
|
|
private:
|
|
|
|
std::string m_mod_name;
|
2022-01-07 10:28:49 -08:00
|
|
|
ModMetadataDatabase *m_database;
|
2017-02-07 15:15:55 -08:00
|
|
|
};
|