2012-01-21 00:14:35 +00:00
|
|
|
#ifndef COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP
|
|
|
|
#define COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP
|
|
|
|
|
2016-05-11 00:35:17 +00:00
|
|
|
#include <map>
|
2022-01-13 22:10:09 +00:00
|
|
|
#include <optional>
|
|
|
|
#include <stack>
|
2023-01-27 00:07:15 +00:00
|
|
|
#include <string_view>
|
2012-01-21 00:14:35 +00:00
|
|
|
|
2012-01-25 22:55:43 +00:00
|
|
|
#include <components/files/collections.hpp>
|
2012-01-21 00:14:35 +00:00
|
|
|
#include <components/files/fixedpath.hpp>
|
|
|
|
|
2022-06-25 15:51:01 +00:00
|
|
|
namespace boost::program_options
|
|
|
|
{
|
|
|
|
class options_description;
|
|
|
|
class variables_map;
|
|
|
|
}
|
|
|
|
|
2012-01-21 00:14:35 +00:00
|
|
|
/**
|
|
|
|
* \namespace Files
|
|
|
|
*/
|
|
|
|
namespace Files
|
|
|
|
{
|
2023-01-27 00:07:15 +00:00
|
|
|
inline constexpr std::string_view openmwCfgFile = "openmw.cfg";
|
2012-01-21 00:14:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \struct ConfigurationManager
|
|
|
|
*/
|
|
|
|
struct ConfigurationManager
|
|
|
|
{
|
2015-01-30 21:11:26 +00:00
|
|
|
ConfigurationManager(bool silent = false); /// @param silent Emit log messages to cout?
|
2012-01-21 00:14:35 +00:00
|
|
|
virtual ~ConfigurationManager();
|
|
|
|
|
|
|
|
void readConfiguration(boost::program_options::variables_map& variables,
|
2022-04-26 20:36:03 +00:00
|
|
|
const boost::program_options::options_description& description, bool quiet = false);
|
2013-09-08 12:31:20 +00:00
|
|
|
|
2022-04-26 20:36:03 +00:00
|
|
|
void filterOutNonExistingPaths(Files::PathContainer& dataDirs) const;
|
|
|
|
|
|
|
|
// Replaces tokens (`?local?`, `?global?`, etc.) in paths. Adds `basePath` prefix for relative paths.
|
2022-06-08 21:25:50 +00:00
|
|
|
void processPath(std::filesystem::path& path, const std::filesystem::path& basePath) const;
|
|
|
|
void processPaths(Files::PathContainer& dataDirs, const std::filesystem::path& basePath) const;
|
|
|
|
void processPaths(
|
|
|
|
boost::program_options::variables_map& variables, const std::filesystem::path& basePath) const;
|
2012-01-21 00:14:35 +00:00
|
|
|
|
|
|
|
/**< Fixed paths */
|
2022-06-08 21:25:50 +00:00
|
|
|
const std::filesystem::path& getGlobalPath() const;
|
|
|
|
const std::filesystem::path& getLocalPath() const;
|
2012-01-21 00:14:35 +00:00
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
const std::filesystem::path& getGlobalDataPath() const;
|
|
|
|
const std::filesystem::path& getUserConfigPath() const;
|
|
|
|
const std::filesystem::path& getUserDataPath() const;
|
|
|
|
const std::filesystem::path& getLocalDataPath() const;
|
|
|
|
const std::filesystem::path& getInstallPath() const;
|
|
|
|
const std::vector<std::filesystem::path>& getActiveConfigPaths() const { return mActiveConfigPaths; }
|
2012-01-21 00:14:35 +00:00
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
const std::filesystem::path& getCachePath() const;
|
2012-09-02 17:40:26 +00:00
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
const std::filesystem::path& getLogPath() const { return getUserConfigPath(); }
|
|
|
|
const std::filesystem::path& getScreenshotPath() const;
|
2012-01-21 00:14:35 +00:00
|
|
|
|
2022-01-13 22:10:09 +00:00
|
|
|
static void addCommonOptions(boost::program_options::options_description& description);
|
|
|
|
|
2012-01-21 00:14:35 +00:00
|
|
|
private:
|
2012-01-21 16:58:49 +00:00
|
|
|
typedef Files::FixedPath<> FixedPathType;
|
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
typedef const std::filesystem::path& (FixedPathType::*path_type_f)() const;
|
2022-06-30 17:26:14 +00:00
|
|
|
typedef std::map<std::u8string, path_type_f> TokensMappingContainer;
|
2012-01-21 00:14:35 +00:00
|
|
|
|
2022-04-26 20:36:03 +00:00
|
|
|
std::optional<boost::program_options::variables_map> loadConfig(
|
|
|
|
const std::filesystem::path& path, const boost::program_options::options_description& description) const;
|
2012-01-21 00:14:35 +00:00
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
void addExtraConfigDirs(
|
2022-01-13 22:10:09 +00:00
|
|
|
std::stack<std::filesystem::path>& dirs, const boost::program_options::variables_map& variables) const;
|
|
|
|
|
2012-01-21 00:14:35 +00:00
|
|
|
void setupTokensMapping();
|
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
std::vector<std::filesystem::path> mActiveConfigPaths;
|
2022-01-13 22:10:09 +00:00
|
|
|
|
2012-01-21 16:58:49 +00:00
|
|
|
FixedPathType mFixedPath;
|
2012-01-21 00:14:35 +00:00
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
std::filesystem::path mUserDataPath;
|
|
|
|
std::filesystem::path mScreenshotPath;
|
2012-01-21 00:14:35 +00:00
|
|
|
|
|
|
|
TokensMappingContainer mTokensMapping;
|
2015-01-30 21:11:26 +00:00
|
|
|
|
|
|
|
bool mSilent;
|
2012-01-21 00:14:35 +00:00
|
|
|
};
|
2021-09-30 01:48:47 +00:00
|
|
|
|
|
|
|
boost::program_options::variables_map separateComposingVariables(boost::program_options::variables_map& variables,
|
2022-04-26 20:36:03 +00:00
|
|
|
const boost::program_options::options_description& description);
|
2021-09-30 01:48:47 +00:00
|
|
|
|
|
|
|
void mergeComposingVariables(boost::program_options::variables_map& first,
|
2022-04-26 20:36:03 +00:00
|
|
|
boost::program_options::variables_map& second, const boost::program_options::options_description& description);
|
2021-09-30 01:48:47 +00:00
|
|
|
|
|
|
|
void parseArgs(int argc, const char* const argv[], boost::program_options::variables_map& variables,
|
2022-04-26 20:36:03 +00:00
|
|
|
const boost::program_options::options_description& description);
|
2021-09-30 01:48:47 +00:00
|
|
|
|
|
|
|
void parseConfig(std::istream& stream, boost::program_options::variables_map& variables,
|
2022-04-26 20:36:03 +00:00
|
|
|
const boost::program_options::options_description& description);
|
2021-09-30 01:48:47 +00:00
|
|
|
|
2022-06-08 21:25:50 +00:00
|
|
|
class MaybeQuotedPath : public std::filesystem::path
|
2021-11-14 00:22:44 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2021-11-21 19:51:02 +00:00
|
|
|
std::istream& operator>>(std::istream& istream, MaybeQuotedPath& MaybeQuotedPath);
|
2021-11-14 00:22:44 +00:00
|
|
|
|
2021-11-21 19:51:02 +00:00
|
|
|
typedef std::vector<MaybeQuotedPath> MaybeQuotedPathContainer;
|
2021-11-14 00:22:44 +00:00
|
|
|
|
2021-11-21 19:51:02 +00:00
|
|
|
PathContainer asPathContainer(const MaybeQuotedPathContainer& MaybeQuotedPathContainer);
|
2021-11-14 00:22:44 +00:00
|
|
|
|
2022-04-26 20:36:03 +00:00
|
|
|
} /* namespace Files */
|
2012-01-21 00:14:35 +00:00
|
|
|
|
|
|
|
#endif /* COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP */
|