2012-03-30 18:59:44 +00:00
|
|
|
#ifndef MWINIIMPORTER_IMPORTER
|
|
|
|
#define MWINIIMPORTER_IMPORTER 1
|
|
|
|
|
2012-03-30 20:58:54 +00:00
|
|
|
#include <exception>
|
2022-06-08 21:25:50 +00:00
|
|
|
#include <filesystem>
|
2014-05-19 12:56:41 +00:00
|
|
|
#include <iosfwd>
|
2012-03-30 20:58:54 +00:00
|
|
|
#include <map>
|
2012-03-30 18:59:44 +00:00
|
|
|
#include <string>
|
2012-03-31 19:06:48 +00:00
|
|
|
#include <vector>
|
2012-03-30 20:58:54 +00:00
|
|
|
|
2013-01-02 22:39:21 +00:00
|
|
|
#include <components/to_utf8/to_utf8.hpp>
|
2013-01-01 20:59:30 +00:00
|
|
|
|
2012-03-30 18:59:44 +00:00
|
|
|
class MwIniImporter
|
|
|
|
{
|
|
|
|
public:
|
2012-03-31 20:48:50 +00:00
|
|
|
typedef std::map<std::string, std::string> strmap;
|
|
|
|
typedef std::map<std::string, std::vector<std::string>> multistrmap;
|
2018-05-08 15:32:06 +00:00
|
|
|
typedef std::vector<std::pair<std::string, std::vector<std::string>>> dependencyList;
|
2012-03-31 20:48:50 +00:00
|
|
|
|
2012-03-31 14:54:53 +00:00
|
|
|
MwIniImporter();
|
2013-01-01 20:59:30 +00:00
|
|
|
void setInputEncoding(const ToUTF8::FromType& encoding);
|
2013-06-17 16:47:12 +00:00
|
|
|
void setVerbose(bool verbose);
|
2022-06-08 21:25:50 +00:00
|
|
|
multistrmap loadIniFile(const std::filesystem::path& filename) const;
|
|
|
|
static multistrmap loadCfgFile(const std::filesystem::path& filename);
|
2013-06-17 01:11:26 +00:00
|
|
|
void merge(multistrmap& cfg, const multistrmap& ini) const;
|
|
|
|
void mergeFallback(multistrmap& cfg, const multistrmap& ini) const;
|
2018-04-23 19:21:23 +00:00
|
|
|
void importGameFiles(multistrmap& cfg, const multistrmap& ini, const std::filesystem::path& iniFilename) const;
|
2013-06-17 01:11:26 +00:00
|
|
|
void importArchives(multistrmap& cfg, const multistrmap& ini) const;
|
2014-05-19 12:56:41 +00:00
|
|
|
static void writeToFile(std::ostream& out, const multistrmap& cfg);
|
2013-06-17 01:11:26 +00:00
|
|
|
|
2018-05-08 15:32:06 +00:00
|
|
|
static std::vector<std::string> dependencySort(MwIniImporter::dependencyList source);
|
2018-04-23 19:21:23 +00:00
|
|
|
|
2012-03-30 18:59:44 +00:00
|
|
|
private:
|
2018-05-08 15:32:06 +00:00
|
|
|
static void dependencySortStep(
|
|
|
|
std::string& element, MwIniImporter::dependencyList& source, std::vector<std::string>& result);
|
|
|
|
static std::vector<std::string>::iterator findString(std::vector<std::string>& source, const std::string& string);
|
2018-04-23 19:21:23 +00:00
|
|
|
|
2013-06-17 01:11:26 +00:00
|
|
|
static void insertMultistrmap(multistrmap& cfg, const std::string& key, const std::string& value);
|
2022-06-08 21:25:50 +00:00
|
|
|
static void addPaths(std::vector<std::filesystem::path>& output, std::vector<std::string> input);
|
2015-02-21 21:02:25 +00:00
|
|
|
|
|
|
|
/// \return file's "last modified time", used in original MW to determine plug-in load order
|
2022-06-08 21:25:50 +00:00
|
|
|
static std::time_t lastWriteTime(const std::filesystem::path& filename, std::time_t defaultTime);
|
2015-02-21 21:02:25 +00:00
|
|
|
|
2012-03-30 20:58:54 +00:00
|
|
|
bool mVerbose;
|
2012-03-31 12:28:19 +00:00
|
|
|
strmap mMergeMap;
|
2012-04-02 22:44:26 +00:00
|
|
|
std::vector<std::string> mMergeFallback;
|
2013-01-01 20:59:30 +00:00
|
|
|
ToUTF8::FromType mEncoding;
|
2012-03-30 18:59:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|