From 4d31ca2c865f84883692077951b539bec7ecc99f Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 7 Jun 2011 17:17:25 -0400 Subject: [PATCH] Leading slashes now work, efficiency changes --- apps/openmw/mwclass/npc.cpp | 2 +- components/bsa/bsa_archive.cpp | 80 ++++++++++++++++++++++++---------- 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 8eaa9d614c..285da5c5a2 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -118,7 +118,7 @@ namespace MWClass Ogre::Vector3 pos2 = Ogre::Vector3( 0, .5, 75); if (groin){ - cellRender.insertMesh("MeSHes\\1\\red_MJ_hat_org.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"; diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index 13858d4050..ba7be5bfd3 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -49,6 +49,18 @@ class DirArchive: public Ogre::FileSystemArchive std::map, ciLessBoost> m; int cutoff; + bool comparePortion(std::string file1, std::string file2, int start, int size) const + { + for(int i = start; i < start+size; i++) + { + char one = file1.at(i); + char two = file2.at(i); + if(tolower(one) != tolower(two) ) + return false; + } + return true; + } + public: DirArchive(const String& name) @@ -93,8 +105,8 @@ 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[smallp.string()] = filesind; + //boost::filesystem::path smallp = small; + m[small] = filesind; //std::cout << "Directory: " << smallp.string() << " " << filesind.size() << "\n"; } @@ -113,6 +125,7 @@ class DirArchive: public Ogre::FileSystemArchive std::string copy = filename; + if(OGRE_PLATFORM != OGRE_PLATFORM_WIN32) { @@ -123,7 +136,17 @@ class DirArchive: public Ogre::FileSystemArchive } } } - boost::filesystem::path p = copy; + + 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; int last = copy.size() - 1; int i = last; @@ -134,19 +157,20 @@ class DirArchive: public Ogre::FileSystemArchive break; } - std::string file = copy.substr(i + 1, copy.size() - i); //filename with no slash + //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 current = m[folderpath.string()]; + //std::transform(file.begin(), file.end(), file.begin(), tolower); + //boost::filesystem::path folderpath = folder; + std::vector current = m[folder]; for(std::vector::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"; + //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); } } @@ -156,7 +180,7 @@ class DirArchive: public Ogre::FileSystemArchive //std::cout << "Current:" << folder << "size: " << current.size() << "\n"; //std::cout << "\nFull:" << p.string() << "\n"<< "Part:" << folderpath.string(); - return FileSystemArchive::exists(copy); + return false;//FileSystemArchive::exists(copy); } DataStreamPtr open(const String& filename, bool readonly = true) const @@ -164,6 +188,7 @@ class DirArchive: public Ogre::FileSystemArchive std::map, ciLessBoost> mlocal = m; //std::cout << "Open\n"; std::string copy = filename; + if(OGRE_PLATFORM != OGRE_PLATFORM_WIN32) { @@ -174,7 +199,15 @@ class DirArchive: public Ogre::FileSystemArchive } } } - boost::filesystem::path p = copy; + + 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; int last = copy.size() - 1; int i = last; @@ -185,19 +218,18 @@ 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::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::vector current = mlocal[folderpath.string()]; + //std::transform(file.begin(), file.end(), file.begin(), tolower); + //boost::filesystem::path folderpath = folder; + std::vector current = mlocal[folder]; for(std::vector::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"; + //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); } } @@ -206,8 +238,8 @@ class DirArchive: public Ogre::FileSystemArchive //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); + DataStreamPtr p; + return p;//FileSystemArchive::open(copy, readonly); } };