mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-01 03:21:41 +00:00
Case insensitive external loader working
This commit is contained in:
parent
f2a0fa8af2
commit
45453fd7a9
@ -118,7 +118,7 @@ namespace MWClass
|
||||
Ogre::Vector3 pos2 = Ogre::Vector3( 0, .5, 75);
|
||||
|
||||
if (groin){
|
||||
cellRender.insertMesh("Meshes\\joker\\bald_MJ_hat.nif"); //w/W_6th_Hammer.NIF
|
||||
cellRender.insertMesh("MeSHes\\1\\red_MJ_hat_org.NIF"); //w/W_6th_Hammer.NIF
|
||||
//bald_MJ_hat.NIF
|
||||
cellRender.insertMesh("meshes\\" + groin->model, pos2, axis, kOgrePi, npcName + "groin", addresses, numbers);
|
||||
addresses2[numbers] = npcName + "groin";
|
||||
|
@ -33,12 +33,21 @@
|
||||
using namespace Ogre;
|
||||
using namespace Mangle::Stream;
|
||||
|
||||
struct ciLessBoost : std::binary_function<std::string, std::string, bool>
|
||||
{
|
||||
bool operator() (const std::string & s1, const std::string & s2) const {
|
||||
//case insensitive version of is_less
|
||||
return lexicographical_compare(s1, s2, boost::algorithm::is_iless());
|
||||
}
|
||||
};
|
||||
|
||||
/// An OGRE Archive wrapping a BSAFile archive
|
||||
class DirArchive: public Ogre::FileSystemArchive
|
||||
{
|
||||
|
||||
boost::filesystem::path currentdir;
|
||||
std::map<std::string, std::vector<std::string> > m;
|
||||
std::map<std::string, std::vector<std::string>, ciLessBoost> m;
|
||||
int cutoff;
|
||||
|
||||
public:
|
||||
|
||||
@ -46,6 +55,9 @@ class DirArchive: public Ogre::FileSystemArchive
|
||||
: FileSystemArchive(name, "Dir")
|
||||
{ mType = "Dir";
|
||||
currentdir = name;
|
||||
std::string s = name;
|
||||
cutoff = s.size() + 1;
|
||||
//std::cout << "Cut off:" << cutoff;
|
||||
|
||||
populateMap(currentdir);
|
||||
|
||||
@ -64,12 +76,26 @@ class DirArchive: public Ogre::FileSystemArchive
|
||||
|
||||
f = *dir_iter;
|
||||
std::string s = f.string();
|
||||
filesind.push_back(s);
|
||||
//std::cout << "File: " << s << "\n";
|
||||
|
||||
std::string small;
|
||||
if(cutoff < s.size())
|
||||
small = s.substr(cutoff, s.size() - cutoff);
|
||||
else
|
||||
small = s.substr(cutoff - 1, s.size() - cutoff);
|
||||
|
||||
filesind.push_back(small);
|
||||
//std::cout << "File: " << small << "f\n";
|
||||
}
|
||||
}
|
||||
m[d.string()] = filesind;
|
||||
std::cout << "Directory: " << d.string() << filesind.size() << "\n";
|
||||
std::string small;
|
||||
std::string original = d.string();
|
||||
if(cutoff < original.size())
|
||||
small = original.substr(cutoff, original.size() - cutoff);
|
||||
else
|
||||
small = original.substr(cutoff - 1, original.size() - cutoff);
|
||||
boost::filesystem::path smallp = small;
|
||||
m[smallp.string()] = filesind;
|
||||
//std::cout << "Directory: " << smallp.string() << " " << filesind.size() << "\n";
|
||||
|
||||
}
|
||||
|
||||
@ -80,6 +106,7 @@ class DirArchive: public Ogre::FileSystemArchive
|
||||
void unload() {}
|
||||
|
||||
bool exists(const String& filename) {
|
||||
//std::cout << "exists\n";
|
||||
//String s = filename;
|
||||
//FileSystemArchive::findFiles(s, true, false, filenames.getPointer(), f.getPointer());
|
||||
// std::cout << "Filenames" << filenames.useCount() << "\n";
|
||||
@ -106,21 +133,40 @@ class DirArchive: public Ogre::FileSystemArchive
|
||||
if(copy.at(i) == '/' || copy.at(i) == '\\')
|
||||
break;
|
||||
}
|
||||
std::string folder;
|
||||
|
||||
folder = copy.substr(0, i);
|
||||
std::string file = copy.substr(i + 1, copy.size() - i); //filename with no slash
|
||||
std::string folder = copy.substr(0, i); //folder with no slash
|
||||
|
||||
std::transform(file.begin(), file.end(), file.begin(), tolower);
|
||||
boost::filesystem::path folderpath = folder;
|
||||
std::cout << "\nFull:" << p.string() << "\n"<< "Part:" << folderpath.string();
|
||||
std::vector<std::string> current = m[folderpath.string()];
|
||||
|
||||
for(std::vector<std::string>::iterator iter = current.begin(); iter != current.end(); iter++)
|
||||
{
|
||||
std::string loopfile = iter->substr(i + 1, copy.size() - i); //filename with no slash
|
||||
std::transform(loopfile.begin(), loopfile.end(), loopfile.begin(), tolower);
|
||||
if(file.compare(loopfile) == 0){
|
||||
std::cout << "Loopfile:" << loopfile << "\n";
|
||||
return FileSystemArchive::exists(*iter);
|
||||
}
|
||||
}
|
||||
|
||||
//std::cout << "Filename:" << file << "\n";
|
||||
//std::cout << "Full:" << p.string() << "\n";
|
||||
//std::cout << "Current:" << folder << "size: " << current.size() << "\n";
|
||||
//std::cout << "\nFull:" << p.string() << "\n"<< "Part:" << folderpath.string();
|
||||
|
||||
return FileSystemArchive::exists(copy);
|
||||
}
|
||||
|
||||
DataStreamPtr open(const String& filename, bool readonly = true) const
|
||||
{
|
||||
std::string copy = filename;
|
||||
if(OGRE_PLATFORM != OGRE_PLATFORM_WIN32){
|
||||
//std::cout << "In Open\n";
|
||||
std::map<std::string, std::vector<std::string>, ciLessBoost> mlocal = m;
|
||||
//std::cout << "Open\n";
|
||||
std::string copy = filename;
|
||||
if(OGRE_PLATFORM != OGRE_PLATFORM_WIN32)
|
||||
{
|
||||
|
||||
for (int i = 0; i < filename.size(); i++)
|
||||
{
|
||||
if(copy.at(i) == '\\' ){
|
||||
@ -128,6 +174,39 @@ class DirArchive: public Ogre::FileSystemArchive
|
||||
}
|
||||
}
|
||||
}
|
||||
boost::filesystem::path p = copy;
|
||||
|
||||
int last = copy.size() - 1;
|
||||
int i = last;
|
||||
|
||||
for (;last >= 0; i--)
|
||||
{
|
||||
if(copy.at(i) == '/' || copy.at(i) == '\\')
|
||||
break;
|
||||
}
|
||||
|
||||
std::string file = copy.substr(i + 1, copy.size() - i); //filename with no slash
|
||||
std::string folder = copy.substr(0, i); //folder with no slash
|
||||
|
||||
std::transform(file.begin(), file.end(), file.begin(), tolower);
|
||||
boost::filesystem::path folderpath = folder;
|
||||
std::vector<std::string> current = mlocal[folderpath.string()];
|
||||
|
||||
for(std::vector<std::string>::iterator iter = current.begin(); iter != current.end(); iter++)
|
||||
{
|
||||
std::string loopfile = iter->substr(i + 1, copy.size() - i); //filename with no slash
|
||||
std::transform(loopfile.begin(), loopfile.end(), loopfile.begin(), tolower);
|
||||
if(file.compare(loopfile) == 0){
|
||||
std::cout << "Loopfile:" << loopfile << "\n";
|
||||
return FileSystemArchive::open(*iter, readonly);
|
||||
}
|
||||
}
|
||||
|
||||
//std::cout << "Filename:" << file << "\n";
|
||||
//std::cout << "Full:" << p.string() << "\n";
|
||||
//std::cout << "Current:" << folder << "size: " << current.size() << "\n";
|
||||
//std::cout << "\nFull:" << p.string() << "\n"<< "Part:" << folderpath.string();
|
||||
|
||||
return FileSystemArchive::open(copy, readonly);
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
#include <string>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
#ifndef _BSA_ARCHIVE_H_
|
||||
#define _BSA_ARCHIVE_H_
|
||||
|
Loading…
Reference in New Issue
Block a user