1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 18:32:44 +01:00

Use boost::make_iterator_range, as older boost lacks ranges in filesystem iterators

This commit is contained in:
darkf 2016-08-04 05:07:11 -07:00
parent 95a38e1604
commit 0242868caa
2 changed files with 15 additions and 15 deletions

View File

@ -14,6 +14,7 @@
#include <iconv.h> #include <iconv.h>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/range/iterator_range.hpp>
// Original save game file data structures // Original save game file data structures
typedef uint16_t BlockWord; typedef uint16_t BlockWord;
@ -1275,9 +1276,7 @@ std::vector<SaveGameInfo> SaveGame::getAllSaveGameInfo()
return {}; return {};
std::vector<SaveGameInfo> infos; std::vector<SaveGameInfo> infos;
for(const auto& entry : directory_iterator(gamePath)) { for(const path& save_path : boost::make_iterator_range(directory_iterator(gamePath), {})) {
path save_path = entry.path();
if(save_path.extension() == ".b") { if(save_path.extension() == ".b") {
std::cout << save_path.string() << std::endl; std::cout << save_path.string() << std::endl;
infos.emplace_back(SaveGameInfo {save_path.string(), false, BasicState()}); infos.emplace_back(SaveGameInfo {save_path.string(), false, BasicState()});

View File

@ -1,6 +1,7 @@
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/range/iterator_range.hpp>
#include <platform/FileIndex.hpp> #include <platform/FileIndex.hpp>
#include <loaders/LoaderIMG.hpp> #include <loaders/LoaderIMG.hpp>
@ -17,19 +18,19 @@ std::string findPathRealCase(const std::string& base_src, const std::string& pat
path searchpath(path_src); path searchpath(path_src);
// Iterate over each component of the path // Iterate over each component of the path
for(const path& path_component : searchpath) { for(const path& path_component : boost::make_iterator_range(searchpath.begin(), searchpath.end())) {
std::string cmp_lower = path_component.string(); std::string cmpLower = path_component.string();
std::transform(cmp_lower.begin(), cmp_lower.end(), cmp_lower.begin(), ::tolower); std::transform(cmpLower.begin(), cmpLower.end(), cmpLower.begin(), ::tolower);
// Search the current base path for a filename matching the component we're searching for // Search the current base path for a filename matching the component we're searching for
bool found = false; bool found = false;
for(const directory_entry& entry : directory_iterator(base)) { for(const path& entry : boost::make_iterator_range(directory_iterator(base), {})) {
std::string lowerName = entry.path().filename().string(); std::string lowerName = entry.filename().string();
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower); std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower);
if(lowerName == cmp_lower) { if(lowerName == cmpLower) {
// We got a match, so add it to base and continue // We got a match, so add it to base and continue
base /= lowerName; base /= entry.filename();
found = true; found = true;
break; break;
} }
@ -45,13 +46,13 @@ std::string findPathRealCase(const std::string& base_src, const std::string& pat
void FileIndex::indexTree(const std::string& root) void FileIndex::indexTree(const std::string& root)
{ {
for(const auto& entry : recursive_directory_iterator(root)) { for(const path& entry : boost::make_iterator_range(recursive_directory_iterator(root), {})) {
std::string directory = entry.path().parent_path().string(); std::string directory = entry.parent_path().string();
std::string realName = entry.path().filename().string(); std::string realName = entry.filename().string();
std::string lowerName = realName; std::string lowerName = realName;
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower); std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower);
if(is_regular_file(entry.path())) { if(is_regular_file(entry)) {
files[lowerName] = {lowerName, realName, directory, ""}; files[lowerName] = {lowerName, realName, directory, ""};
} }
} }
@ -62,7 +63,7 @@ void FileIndex::indexArchive(const std::string& archive)
// Split directory from archive name // Split directory from archive name
path archive_path = path(archive); path archive_path = path(archive);
path directory = archive_path.parent_path(); path directory = archive_path.parent_path();
path archive_basename = archive_path.stem(); path archive_basename = archive_path.filename();
path archive_full_path = directory/archive_basename; path archive_full_path = directory/archive_basename;
LoaderIMG img; LoaderIMG img;