forked from teamnwah/openmw-tes3coop
Less cryptic abbreviations
This commit is contained in:
parent
905cde10db
commit
103a07b744
2 changed files with 42 additions and 38 deletions
|
@ -825,39 +825,43 @@ void MwIniImporter::importArchives(multistrmap &cfg, const multistrmap &ini) con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MwIniImporter::dependencySortStep(std::string& el, MwIniImporter::deplist& src, std::vector<std::string>& ret)
|
void MwIniImporter::dependencySortStep(std::string& element, MwIniImporter::dependencyList& source, std::vector<std::string>& result)
|
||||||
{
|
{
|
||||||
auto it = std::find_if(src.begin(), src.end(), [&el](std::pair< std::string, std::vector<std::string> >& o)
|
auto iter = std::find_if(
|
||||||
{
|
source.begin(),
|
||||||
return o.first == el;
|
source.end(),
|
||||||
});
|
[&element](std::pair< std::string, std::vector<std::string> >& sourceElement)
|
||||||
if (it != src.end())
|
|
||||||
{
|
|
||||||
auto o = std::move(*it);
|
|
||||||
src.erase(it);
|
|
||||||
for (auto name : o.second)
|
|
||||||
{
|
{
|
||||||
MwIniImporter::dependencySortStep(name, src, ret);
|
return sourceElement.first == element;
|
||||||
}
|
}
|
||||||
ret.push_back(std::move(o.first));
|
);
|
||||||
|
if (iter != source.end())
|
||||||
|
{
|
||||||
|
auto foundElement = std::move(*iter);
|
||||||
|
source.erase(iter);
|
||||||
|
for (auto name : foundElement.second)
|
||||||
|
{
|
||||||
|
MwIniImporter::dependencySortStep(name, source, result);
|
||||||
|
}
|
||||||
|
result.push_back(std::move(foundElement.first));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> MwIniImporter::dependencySort(MwIniImporter::deplist src)
|
std::vector<std::string> MwIniImporter::dependencySort(MwIniImporter::dependencyList source)
|
||||||
{
|
{
|
||||||
std::vector<std::string> ret;
|
std::vector<std::string> result;
|
||||||
while (!src.empty())
|
while (!source.empty())
|
||||||
{
|
{
|
||||||
MwIniImporter::dependencySortStep(src.begin()->first, src, ret);
|
MwIniImporter::dependencySortStep(source.begin()->first, source, result);
|
||||||
}
|
}
|
||||||
return ret;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string>::iterator MwIniImporter::findString(std::vector<std::string>& v, const std::string& s)
|
std::vector<std::string>::iterator MwIniImporter::findString(std::vector<std::string>& source, const std::string& string)
|
||||||
{
|
{
|
||||||
return std::find_if(v.begin(), v.end(), [&s](const std::string& str)
|
return std::find_if(source.begin(), source.end(), [&string](const std::string& sourceString)
|
||||||
{
|
{
|
||||||
return Misc::StringUtils::ciEqual(str, s);
|
return Misc::StringUtils::ciEqual(sourceString, string);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -902,19 +906,19 @@ void MwIniImporter::importGameFiles(multistrmap &cfg, const multistrmap &ini, co
|
||||||
// sort by timestamp
|
// sort by timestamp
|
||||||
sort(contentFiles.begin(), contentFiles.end());
|
sort(contentFiles.begin(), contentFiles.end());
|
||||||
|
|
||||||
MwIniImporter::deplist unsortedFiles;
|
MwIniImporter::dependencyList unsortedFiles;
|
||||||
|
|
||||||
ESM::ESMReader reader;
|
ESM::ESMReader reader;
|
||||||
reader.setEncoder(&encoder);
|
reader.setEncoder(&encoder);
|
||||||
for (auto& file : contentFiles)
|
for (auto& file : contentFiles)
|
||||||
{
|
{
|
||||||
reader.open(file.second.string());
|
reader.open(file.second.string());
|
||||||
std::vector<std::string> deps;
|
std::vector<std::string> dependencies;
|
||||||
for (auto& depFile : reader.getGameFiles())
|
for (auto& gameFile : reader.getGameFiles())
|
||||||
{
|
{
|
||||||
deps.push_back(depFile.name);
|
dependencies.push_back(gameFile.name);
|
||||||
}
|
}
|
||||||
unsortedFiles.emplace_back(boost::filesystem::path(reader.getName()).filename().string(), deps);
|
unsortedFiles.emplace_back(boost::filesystem::path(reader.getName()).filename().string(), dependencies);
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -923,17 +927,17 @@ void MwIniImporter::importGameFiles(multistrmap &cfg, const multistrmap &ini, co
|
||||||
// hard-coded dependency Morrowind - Tribunal - Bloodmoon
|
// hard-coded dependency Morrowind - Tribunal - Bloodmoon
|
||||||
if(findString(sortedFiles, "Morrowind.esm") != sortedFiles.end())
|
if(findString(sortedFiles, "Morrowind.esm") != sortedFiles.end())
|
||||||
{
|
{
|
||||||
auto foundTribunal = findString(sortedFiles, "Tribunal.esm");
|
auto tribunalIter = findString(sortedFiles, "Tribunal.esm");
|
||||||
auto foundBloodmoon = findString(sortedFiles, "Bloodmoon.esm");
|
auto bloodmoonIter = findString(sortedFiles, "Bloodmoon.esm");
|
||||||
|
|
||||||
if (foundBloodmoon != sortedFiles.end() && foundTribunal != sortedFiles.end())
|
if (bloodmoonIter != sortedFiles.end() && tribunalIter != sortedFiles.end())
|
||||||
{
|
{
|
||||||
size_t dstBloodmoon = std::distance(sortedFiles.begin(), foundBloodmoon);
|
size_t bloodmoonIndex = std::distance(sortedFiles.begin(), bloodmoonIter);
|
||||||
size_t dstTribunal = std::distance(sortedFiles.begin(), foundTribunal);
|
size_t tribunalIndex = std::distance(sortedFiles.begin(), tribunalIter);
|
||||||
if (dstBloodmoon < dstTribunal)
|
if (bloodmoonIndex < tribunalIndex)
|
||||||
dstTribunal++;
|
tribunalIndex++;
|
||||||
sortedFiles.insert(foundBloodmoon, *foundTribunal);
|
sortedFiles.insert(bloodmoonIter, *tribunalIter);
|
||||||
sortedFiles.erase(sortedFiles.begin() + dstTribunal);
|
sortedFiles.erase(sortedFiles.begin() + tribunalIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ class MwIniImporter {
|
||||||
public:
|
public:
|
||||||
typedef std::map<std::string, std::string> strmap;
|
typedef std::map<std::string, std::string> strmap;
|
||||||
typedef std::map<std::string, std::vector<std::string> > multistrmap;
|
typedef std::map<std::string, std::vector<std::string> > multistrmap;
|
||||||
typedef std::vector< std::pair< std::string, std::vector<std::string> > > deplist;
|
typedef std::vector< std::pair< std::string, std::vector<std::string> > > dependencyList;
|
||||||
|
|
||||||
MwIniImporter();
|
MwIniImporter();
|
||||||
void setInputEncoding(const ToUTF8::FromType& encoding);
|
void setInputEncoding(const ToUTF8::FromType& encoding);
|
||||||
|
@ -28,11 +28,11 @@ class MwIniImporter {
|
||||||
void importArchives(multistrmap &cfg, const multistrmap &ini) const;
|
void importArchives(multistrmap &cfg, const multistrmap &ini) const;
|
||||||
static void writeToFile(std::ostream &out, const multistrmap &cfg);
|
static void writeToFile(std::ostream &out, const multistrmap &cfg);
|
||||||
|
|
||||||
static std::vector<std::string> dependencySort(MwIniImporter::deplist src);
|
static std::vector<std::string> dependencySort(MwIniImporter::dependencyList source);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void dependencySortStep(std::string& el, MwIniImporter::deplist& src, std::vector<std::string>& ret);
|
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>& v, const std::string& s);
|
static std::vector<std::string>::iterator findString(std::vector<std::string>& source, const std::string& string);
|
||||||
|
|
||||||
static void insertMultistrmap(multistrmap &cfg, const std::string& key, const std::string& value);
|
static void insertMultistrmap(multistrmap &cfg, const std::string& key, const std::string& value);
|
||||||
static std::string numberToString(int n);
|
static std::string numberToString(int n);
|
||||||
|
|
Loading…
Reference in a new issue