|
|
|
@ -41,13 +41,15 @@ struct ciLessBoost : std::binary_function<std::string, std::string, bool>
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static bool fsstrict = false;
|
|
|
|
|
|
|
|
|
|
/// An OGRE Archive wrapping a BSAFile archive
|
|
|
|
|
class DirArchive: public Ogre::FileSystemArchive
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
boost::filesystem::path currentdir;
|
|
|
|
|
std::map<std::string, std::vector<std::string>, ciLessBoost> m;
|
|
|
|
|
int cutoff;
|
|
|
|
|
unsigned int cutoff;
|
|
|
|
|
|
|
|
|
|
bool comparePortion(std::string file1, std::string file2, int start, int size) const
|
|
|
|
|
{
|
|
|
|
@ -65,13 +67,13 @@ class DirArchive: public Ogre::FileSystemArchive
|
|
|
|
|
|
|
|
|
|
DirArchive(const String& name)
|
|
|
|
|
: FileSystemArchive(name, "Dir")
|
|
|
|
|
{ mType = "Dir";
|
|
|
|
|
{
|
|
|
|
|
mType = "Dir";
|
|
|
|
|
currentdir = name;
|
|
|
|
|
std::string s = name;
|
|
|
|
|
cutoff = s.size() + 1;
|
|
|
|
|
//std::cout << "Cut off:" << cutoff;
|
|
|
|
|
|
|
|
|
|
populateMap(currentdir);
|
|
|
|
|
if(fsstrict == false)
|
|
|
|
|
populateMap(currentdir);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
void populateMap(boost::filesystem::path d){
|
|
|
|
@ -96,7 +98,6 @@ class DirArchive: public Ogre::FileSystemArchive
|
|
|
|
|
small = s.substr(cutoff - 1, s.size() - cutoff);
|
|
|
|
|
|
|
|
|
|
filesind.push_back(small);
|
|
|
|
|
//std::cout << "File: " << small << "f\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
std::string small;
|
|
|
|
@ -105,30 +106,22 @@ class DirArchive: public Ogre::FileSystemArchive
|
|
|
|
|
small = original.substr(cutoff, original.size() - cutoff);
|
|
|
|
|
else
|
|
|
|
|
small = original.substr(cutoff - 1, original.size() - cutoff);
|
|
|
|
|
//boost::filesystem::path smallp = small;
|
|
|
|
|
m[small] = filesind;
|
|
|
|
|
//std::cout << "Directory: " << small << " " << filesind.size() << "\n";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isCaseSensitive() const { return false; }
|
|
|
|
|
bool isCaseSensitive() const { return fsstrict; }
|
|
|
|
|
|
|
|
|
|
// The archive is loaded in the constructor, and never unloaded.
|
|
|
|
|
void load() {}
|
|
|
|
|
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";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string copy = filename;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < filename.size(); i++)
|
|
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < filename.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
if(copy.at(i) == '\\' ){
|
|
|
|
|
copy.replace(i, 1, "/");
|
|
|
|
@ -138,14 +131,15 @@ class DirArchive: public Ogre::FileSystemArchive
|
|
|
|
|
|
|
|
|
|
if(copy.at(0) == '\\' || copy.at(0) == '/')
|
|
|
|
|
{
|
|
|
|
|
//std::cout << "Before:" << copy.size() << "\n";
|
|
|
|
|
copy.erase(0, 1);
|
|
|
|
|
//std::cout << "The copy" << copy << "\n";
|
|
|
|
|
//std::cout << "After:" << copy.size();
|
|
|
|
|
}
|
|
|
|
|
if(fsstrict == true)
|
|
|
|
|
{
|
|
|
|
|
//std::cout << "fsstrict " << copy << "\n";
|
|
|
|
|
return FileSystemArchive::exists(copy);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//boost::filesystem::path p = copy;
|
|
|
|
|
|
|
|
|
|
int last = copy.size() - 1;
|
|
|
|
|
int i = last;
|
|
|
|
@ -156,41 +150,29 @@ class DirArchive: public Ogre::FileSystemArchive
|
|
|
|
|
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 = m[folder];
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
//std::string now = *iter;
|
|
|
|
|
if(comparePortion(*iter, copy, i + 1, copy.size() - i -1) == true){
|
|
|
|
|
//std::cout << "Loopfile:" << copy << "\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 false;//FileSystemArchive::exists(copy);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DataStreamPtr open(const String& filename, bool readonly = true) const
|
|
|
|
|
{
|
|
|
|
|
std::map<std::string, std::vector<std::string>, ciLessBoost> mlocal = m;
|
|
|
|
|
//std::cout << "Open\n";
|
|
|
|
|
std::string copy = filename;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < filename.size(); i++)
|
|
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < filename.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
if(copy.at(i) == '\\' ){
|
|
|
|
|
copy.replace(i, 1, "/");
|
|
|
|
@ -200,12 +182,13 @@ class DirArchive: public Ogre::FileSystemArchive
|
|
|
|
|
|
|
|
|
|
if(copy.at(0) == '\\' || copy.at(0) == '/')
|
|
|
|
|
{
|
|
|
|
|
//std::cout << "Before:" << copy.size() << "\n";
|
|
|
|
|
copy.erase(0, 1);
|
|
|
|
|
//std::cout << "The copy" << copy << "\n";
|
|
|
|
|
//std::cout << "After:" << copy.size();
|
|
|
|
|
}
|
|
|
|
|
//boost::filesystem::path p = copy;
|
|
|
|
|
|
|
|
|
|
if(fsstrict == true){
|
|
|
|
|
return FileSystemArchive::open(copy, readonly);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int last = copy.size() - 1;
|
|
|
|
|
int i = last;
|
|
|
|
@ -216,28 +199,17 @@ class DirArchive: public Ogre::FileSystemArchive
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string folder = copy.substr(0, i); //folder with no slash //folder with no slash
|
|
|
|
|
|
|
|
|
|
//std::transform(file.begin(), file.end(), file.begin(), tolower);
|
|
|
|
|
//boost::filesystem::path folderpath = folder;
|
|
|
|
|
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++)
|
|
|
|
|
{
|
|
|
|
|
//std::string loopfile = iter->substr(i + 1, copy.size() - i); //filename with no slash
|
|
|
|
|
//std::transform(loopfile.begin(), loopfile.end(), loopfile.begin(), tolower);
|
|
|
|
|
if(comparePortion(*iter, copy, i + 1, copy.size() - i -1) == true){
|
|
|
|
|
//std::cout << "Loopfile:" << copy << "\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();
|
|
|
|
|
DataStreamPtr p;
|
|
|
|
|
return p;//FileSystemArchive::open(copy, readonly);
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
@ -374,6 +346,7 @@ public:
|
|
|
|
|
|
|
|
|
|
static bool init = false;
|
|
|
|
|
static bool init2 = false;
|
|
|
|
|
|
|
|
|
|
static void insertBSAFactory()
|
|
|
|
|
{
|
|
|
|
|
if(!init)
|
|
|
|
@ -400,9 +373,11 @@ void addBSA(const std::string& name, const std::string& group)
|
|
|
|
|
ResourceGroupManager::getSingleton().
|
|
|
|
|
addResourceLocation(name, "BSA", group);
|
|
|
|
|
}
|
|
|
|
|
void addDir(const std::string& name, const std::string& group)
|
|
|
|
|
void addDir(const std::string& name, const bool& fs, const std::string& group)
|
|
|
|
|
{
|
|
|
|
|
fsstrict = fs;
|
|
|
|
|
insertDirFactory();
|
|
|
|
|
|
|
|
|
|
ResourceGroupManager::getSingleton().
|
|
|
|
|
addResourceLocation(name, "Dir", group);
|
|
|
|
|
}
|
|
|
|
|