void Init(const char *gameCode) { textureMap.clear(); CFileSearch::XStringVector Directories; //Directories.push_back(File::GetUserPath(D_HIRESTEXTURES_IDX)); char szDir[MAX_PATH]; sprintf(szDir, "%s%s", File::GetUserPath(D_HIRESTEXTURES_IDX).c_str(), gameCode); Directories.push_back(std::string(szDir)); for (u32 i = 0; i < Directories.size(); i++) { File::FSTEntry FST_Temp; File::ScanDirectoryTree(Directories[i], FST_Temp); for (u32 j = 0; j < FST_Temp.children.size(); j++) { if (FST_Temp.children.at(j).isDirectory) { bool duplicate = false; for (u32 k = 0; k < Directories.size(); k++) { if (strcmp(Directories[k].c_str(), FST_Temp.children.at(j).physicalName.c_str()) == 0) { duplicate = true; break; } } if (!duplicate) Directories.push_back(FST_Temp.children.at(j).physicalName.c_str()); } } } CFileSearch::XStringVector Extensions; Extensions.push_back("*.png"); Extensions.push_back("*.bmp"); Extensions.push_back("*.tga"); Extensions.push_back("*.dds"); Extensions.push_back("*.jpg"); // Why not? Could be useful for large photo-like textures CFileSearch FileSearch(Extensions, Directories); const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames(); char code[MAX_PATH]; sprintf(code, "%s_", gameCode); if (rFilenames.size() > 0) { for (u32 i = 0; i < rFilenames.size(); i++) { std::string FileName; SplitPath(rFilenames[i], NULL, &FileName, NULL); if (FileName.substr(0, strlen(code)).compare(code) == 0 && textureMap.find(FileName) == textureMap.end()) textureMap.insert(std::map<std::string, std::string>::value_type(FileName, rFilenames[i])); } } }
CFileSearch::CFileSearch(const CFileSearch::XStringVector& _rSearchStrings, const CFileSearch::XStringVector& _rDirectories) { // Reverse the loop order for speed? for (size_t j = 0; j < _rSearchStrings.size(); j++) { for (size_t i = 0; i < _rDirectories.size(); i++) { FindFiles(_rSearchStrings[j], _rDirectories[i]); } } }
void Init(const std::string& gameCode) { textureMap.clear(); CFileSearch::XStringVector Directories; std::string szDir = StringFromFormat("%s%s", File::GetUserPath(D_HIRESTEXTURES_IDX).c_str(), gameCode.c_str()); Directories.push_back(szDir); for (u32 i = 0; i < Directories.size(); i++) { File::FSTEntry FST_Temp; File::ScanDirectoryTree(Directories[i], FST_Temp); for (auto& entry : FST_Temp.children) { if (entry.isDirectory) { bool duplicate = false; for (auto& Directory : Directories) { if (Directory == entry.physicalName) { duplicate = true; break; } } if (!duplicate) Directories.push_back(entry.physicalName); } } } CFileSearch::XStringVector Extensions = { "*.png", "*.bmp", "*.tga", "*.dds", "*.jpg" // Why not? Could be useful for large photo-like textures }; CFileSearch FileSearch(Extensions, Directories); const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames(); const std::string code = StringFromFormat("%s_", gameCode.c_str()); if (rFilenames.size() > 0) { for (auto& rFilename : rFilenames) { std::string FileName; SplitPath(rFilename, nullptr, &FileName, nullptr); if (FileName.substr(0, code.length()).compare(code) == 0 && textureMap.find(FileName) == textureMap.end()) textureMap.insert(std::map<std::string, std::string>::value_type(FileName, rFilename)); } } }
void Init(const char *gameCode) { textureMap.clear(); texturecount = 0; CFileSearch::XStringVector Directories; //Directories.push_back(File::GetUserPath(D_HIRESTEXTURES_IDX)); char szDir[MAX_PATH]; sprintf(szDir, "%s%s", File::GetUserPath(D_HIRESTEXTURES_IDX).c_str(), gameCode); Directories.push_back(std::string(szDir)); for (u32 i = 0; i < Directories.size(); i++) { File::FSTEntry FST_Temp; File::ScanDirectoryTree(Directories[i], FST_Temp); for (u32 j = 0; j < FST_Temp.children.size(); j++) { if (FST_Temp.children.at(j).isDirectory) { bool duplicate = false; for (u32 k = 0; k < Directories.size(); k++) { if (strcmp(Directories[k].c_str(), FST_Temp.children.at(j).physicalName.c_str()) == 0) { duplicate = true; break; } } if (!duplicate) Directories.push_back(FST_Temp.children.at(j).physicalName.c_str()); } } } CFileSearch::XStringVector Extensions; Extensions.push_back("*.png"); Extensions.push_back("*.PNG"); Extensions.push_back("*.bmp"); Extensions.push_back("*.BMP"); Extensions.push_back("*.tga"); Extensions.push_back("*.TGA"); Extensions.push_back("*.dds"); Extensions.push_back("*.DDS"); Extensions.push_back("*.jpg"); // Why not? Could be useful for large photo-like textures Extensions.push_back("*.JPG"); CFileSearch FileSearch(Extensions, Directories); const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames(); std::string code(gameCode); if (rFilenames.size() > 0) { for (u32 i = 0; i < rFilenames.size(); i++) { std::string FileName; std::string Extension; SplitPath(rFilenames[i], NULL, &FileName, &Extension); std::pair<std::string, std::string> Pair(rFilenames[i], Extension); std::vector<std::string> nameparts; std::istringstream issfilename(FileName); std::string nameitem; while (std::getline(issfilename, nameitem, '_')) { nameparts.push_back(nameitem); } if (nameparts.size() >= 3) { u32 hash = 0; u32 format = 0; u32 mip = 0; sscanf(nameparts[1].c_str(), "%x", &hash); sscanf(nameparts[2].c_str(), "%i", &format); if (nameparts.size() > 3 && nameparts[3].size() > 3) { sscanf(nameparts[3].substr(3, std::string::npos).c_str(), "%i", &mip); } u64 key = ((u64)hash) | (((u64)format) << 32) | (((u64)mip) << 48); if (nameparts[0].compare(code) == 0 && textureMap.find(key) == textureMap.end()) { texturecount++; textureMap.insert(std::map<u64, std::pair<std::string, std::string>>::value_type(key, Pair)); } } } } }