mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 23:53:52 +00:00
Replaced some messy code with some differently messy code, this one at least seems to work
This commit is contained in:
parent
a0c5ccf974
commit
0d163d76ab
1 changed files with 69 additions and 89 deletions
|
@ -45,6 +45,32 @@ struct ciLessBoost : std::binary_function<std::string, std::string, bool>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct mrComparer
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
int m_start, m_size;
|
||||||
|
|
||||||
|
bool comparePortion(std::string file1, std::string file2, int start, int size) const
|
||||||
|
{
|
||||||
|
for(int i = start; i < start+size; i++)
|
||||||
|
{
|
||||||
|
char one = tolower(file1.at(i));
|
||||||
|
char two = tolower(file2.at(i));
|
||||||
|
if(one != two)
|
||||||
|
return (one < two);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
mrComparer(int start, int size) : m_start(start), m_size(size) { }
|
||||||
|
|
||||||
|
bool operator() (const std::string& first, const std::string& other)
|
||||||
|
{
|
||||||
|
return comparePortion(first, other, m_start, m_size);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static bool fsstrict = false;
|
static bool fsstrict = false;
|
||||||
|
|
||||||
/// An OGRE Archive wrapping a BSAFile archive
|
/// An OGRE Archive wrapping a BSAFile archive
|
||||||
|
@ -55,16 +81,46 @@ class DirArchive: public Ogre::FileSystemArchive
|
||||||
std::map<std::string, std::vector<std::string>, ciLessBoost> m;
|
std::map<std::string, std::vector<std::string>, ciLessBoost> m;
|
||||||
unsigned int cutoff;
|
unsigned int cutoff;
|
||||||
|
|
||||||
bool comparePortion(std::string file1, std::string file2, int start, int size) const
|
bool findFile(const String& filename, std::string& copy) const
|
||||||
{
|
{
|
||||||
for(int i = start; i < start+size; i++)
|
copy = filename;
|
||||||
{
|
|
||||||
char one = file1.at(i);
|
std::replace(copy.begin(), copy.end(), '\\', '/');
|
||||||
char two = file2.at(i);
|
|
||||||
if(tolower(one) != tolower(two) )
|
if(copy.at(0) == '/')
|
||||||
return false;
|
copy.erase(0, 1);
|
||||||
}
|
|
||||||
|
if(fsstrict == true)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
std::string folder;
|
||||||
|
int delimiter = 0;
|
||||||
|
size_t lastSlash = copy.rfind('/');
|
||||||
|
if (lastSlash != std::string::npos)
|
||||||
|
{
|
||||||
|
folder = copy.substr(0, lastSlash);
|
||||||
|
delimiter = lastSlash+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> current;
|
||||||
|
{
|
||||||
|
std::map<std::string,std::vector<std::string>,ciLessBoost>::const_iterator found = m.find(folder);
|
||||||
|
if (found == m.end())
|
||||||
|
{
|
||||||
|
std::replace(folder.begin(), folder.end(), '/', '\\');
|
||||||
|
found = m.find(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
current = found->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
mrComparer comp(delimiter, copy.size() - delimiter-1);
|
||||||
|
std::vector<std::string>::iterator found = std::lower_bound(current.begin(), current.end(), copy, comp);
|
||||||
|
|
||||||
|
if (found != current.end() && !(comp(copy, current.front())))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -120,97 +176,21 @@ class DirArchive: public Ogre::FileSystemArchive
|
||||||
void unload() {}
|
void unload() {}
|
||||||
|
|
||||||
bool exists(const String& filename) {
|
bool exists(const String& filename) {
|
||||||
std::string copy = filename;
|
std::string copy;
|
||||||
|
|
||||||
|
if (findFile(filename, copy))
|
||||||
|
|
||||||
for (unsigned int i = 0; i < filename.size(); i++)
|
|
||||||
{
|
|
||||||
if(copy.at(i) == '\\' ){
|
|
||||||
copy.replace(i, 1, "/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(copy.at(0) == '\\' || copy.at(0) == '/')
|
|
||||||
{
|
|
||||||
copy.erase(0, 1);
|
|
||||||
}
|
|
||||||
if(fsstrict == true)
|
|
||||||
{
|
|
||||||
//std::cout << "fsstrict " << copy << "\n";
|
|
||||||
return FileSystemArchive::exists(copy);
|
return FileSystemArchive::exists(copy);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int last = copy.size() - 1;
|
|
||||||
int i = last;
|
|
||||||
|
|
||||||
for (;last >= 0; i--)
|
|
||||||
{
|
|
||||||
if(copy.at(i) == '/' || copy.at(i) == '\\')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string folder = copy.substr(0, i); //folder with no slash
|
|
||||||
|
|
||||||
std::vector<std::string>& current = m[folder];
|
|
||||||
|
|
||||||
for(std::vector<std::string>::iterator iter = current.begin(); iter != current.end(); iter++)
|
|
||||||
{
|
|
||||||
if(comparePortion(*iter, copy, i + 1, copy.size() - i -1) == true){
|
|
||||||
return FileSystemArchive::exists(*iter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataStreamPtr open(const String& filename, bool readonly = true) const
|
DataStreamPtr open(const String& filename, bool readonly = true) const
|
||||||
{
|
{
|
||||||
std::map<std::string, std::vector<std::string>, ciLessBoost> mlocal = m;
|
std::string copy;
|
||||||
std::string copy = filename;
|
|
||||||
|
|
||||||
|
if (findFile(filename, copy))
|
||||||
|
|
||||||
for (unsigned int i = 0; i < filename.size(); i++)
|
|
||||||
{
|
|
||||||
if(copy.at(i) == '\\' ){
|
|
||||||
copy.replace(i, 1, "/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(copy.at(0) == '\\' || copy.at(0) == '/')
|
|
||||||
{
|
|
||||||
copy.erase(0, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(fsstrict == true)
|
|
||||||
{
|
|
||||||
return FileSystemArchive::open(copy, readonly);
|
return FileSystemArchive::open(copy, readonly);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int last = copy.size() - 1;
|
|
||||||
int i = last;
|
|
||||||
|
|
||||||
for (;last >= 0; i--)
|
|
||||||
{
|
|
||||||
if(copy.at(i) == '/' || copy.at(i) == '\\')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string folder = copy.substr(0, i); //folder with no slash
|
|
||||||
std::vector<std::string> current = mlocal[folder];
|
|
||||||
|
|
||||||
for(std::vector<std::string>::iterator iter = current.begin(); iter != current.end(); iter++)
|
|
||||||
{
|
|
||||||
if(comparePortion(*iter, copy, i + 1, copy.size() - i -1) == true){
|
|
||||||
return FileSystemArchive::open(*iter, readonly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DataStreamPtr p;
|
DataStreamPtr p;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue