forked from teamnwah/openmw-tes3coop
Remove unused code
This commit is contained in:
parent
39eea24dc3
commit
530d06ab54
5 changed files with 2 additions and 329 deletions
|
@ -47,8 +47,8 @@ add_component_dir (misc
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir (files
|
add_component_dir (files
|
||||||
linuxpath windowspath macospath fixedpath multidircollection collections fileops configurationmanager
|
linuxpath windowspath macospath fixedpath multidircollection collections configurationmanager
|
||||||
filelibrary constrainedfiledatastream lowlevelfile
|
constrainedfiledatastream lowlevelfile
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir (compiler
|
add_component_dir (compiler
|
||||||
|
|
|
@ -1,120 +0,0 @@
|
||||||
#include "filelibrary.hpp"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
#include <../components/misc/stringops.hpp>
|
|
||||||
|
|
||||||
namespace Files
|
|
||||||
{
|
|
||||||
// Looks for a string in a vector of strings
|
|
||||||
bool containsVectorString(const StringVector& list, const std::string& str)
|
|
||||||
{
|
|
||||||
for (StringVector::const_iterator iter = list.begin();
|
|
||||||
iter != list.end(); ++iter)
|
|
||||||
{
|
|
||||||
if (*iter == str)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Searches a path and adds the results to the library
|
|
||||||
void FileLibrary::add(const boost::filesystem::path &root, bool recursive, bool strict,
|
|
||||||
const StringVector &acceptableExtensions)
|
|
||||||
{
|
|
||||||
if (!boost::filesystem::exists(root))
|
|
||||||
{
|
|
||||||
std::cout << "Warning " << root.string() << " does not exist.\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string fileExtension;
|
|
||||||
std::string type;
|
|
||||||
|
|
||||||
// remember the last location of the priority list when listing new items
|
|
||||||
int length = mPriorityList.size();
|
|
||||||
|
|
||||||
// First makes a list of all candidate files
|
|
||||||
FileLister(root, mPriorityList, recursive);
|
|
||||||
|
|
||||||
// Then sort these files into sections according to the folder they belong to
|
|
||||||
for (PathContainer::iterator listIter = mPriorityList.begin() + length;
|
|
||||||
listIter != mPriorityList.end(); ++listIter)
|
|
||||||
{
|
|
||||||
if( !acceptableExtensions.empty() )
|
|
||||||
{
|
|
||||||
fileExtension = boost::filesystem::path (listIter->extension()).string();
|
|
||||||
Misc::StringUtils::toLower(fileExtension);
|
|
||||||
if(!containsVectorString(acceptableExtensions, fileExtension))
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
type = boost::filesystem::path (listIter->parent_path().leaf()).string();
|
|
||||||
if (!strict)
|
|
||||||
Misc::StringUtils::toLower(type);
|
|
||||||
|
|
||||||
mMap[type].push_back(*listIter);
|
|
||||||
// std::cout << "Added path: " << listIter->string() << " in section "<< type <<std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true if the named section exists
|
|
||||||
bool FileLibrary::containsSection(std::string sectionName, bool strict)
|
|
||||||
{
|
|
||||||
if (!strict)
|
|
||||||
Misc::StringUtils::toLower(sectionName);
|
|
||||||
StringPathContMap::const_iterator mapIter = mMap.find(sectionName);
|
|
||||||
if (mapIter == mMap.end())
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns a pointer to const for a section of the library
|
|
||||||
const PathContainer* FileLibrary::section(std::string sectionName, bool strict)
|
|
||||||
{
|
|
||||||
if (!strict)
|
|
||||||
Misc::StringUtils::toLower(sectionName);
|
|
||||||
StringPathContMap::const_iterator mapIter = mMap.find(sectionName);
|
|
||||||
if (mapIter == mMap.end())
|
|
||||||
{
|
|
||||||
//std::cout << "Empty\n";
|
|
||||||
return &mEmptyPath;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return &(mapIter->second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Searches the library for an item and returns a boost path to it
|
|
||||||
boost::filesystem::path FileLibrary::locate(std::string item, bool strict, bool ignoreExtensions, std::string sectionName)
|
|
||||||
{
|
|
||||||
boost::filesystem::path result("");
|
|
||||||
if (sectionName == "")
|
|
||||||
{
|
|
||||||
return FileListLocator(mPriorityList, boost::filesystem::path(item), strict, ignoreExtensions);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!containsSection(sectionName, strict))
|
|
||||||
{
|
|
||||||
std::cout << "Warning: There is no section named " << sectionName << "\n";
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
result = FileListLocator(mMap[sectionName], boost::filesystem::path(item), strict, ignoreExtensions);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prints all the available sections, used for debugging
|
|
||||||
void FileLibrary::printSections()
|
|
||||||
{
|
|
||||||
for(StringPathContMap::const_iterator mapIter = mMap.begin();
|
|
||||||
mapIter != mMap.end(); ++mapIter)
|
|
||||||
{
|
|
||||||
std::cout << mapIter->first <<std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
#ifndef COMPONENTS_FILES_FILELIBRARY_HPP
|
|
||||||
#define COMPONENTS_FILES_FILELIBRARY_HPP
|
|
||||||
|
|
||||||
#include <components/files/fileops.hpp>
|
|
||||||
|
|
||||||
namespace Files
|
|
||||||
{
|
|
||||||
typedef std::map<std::string, PathContainer> StringPathContMap;
|
|
||||||
typedef std::vector<std::string> StringVector;
|
|
||||||
|
|
||||||
/// Looks for a string in a vector of strings
|
|
||||||
bool containsVectorString(const StringVector& list, const std::string& str);
|
|
||||||
|
|
||||||
/// \brief Searches directories and makes lists of files according to folder name
|
|
||||||
class FileLibrary
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
StringPathContMap mMap;
|
|
||||||
PathContainer mEmptyPath;
|
|
||||||
PathContainer mPriorityList;
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Searches a path and adds the results to the library
|
|
||||||
/// Recursive search and fs strict options are available
|
|
||||||
/// Takes a vector of acceptable files extensions, if none is given it lists everything.
|
|
||||||
void add(const boost::filesystem::path &root, bool recursive, bool strict,
|
|
||||||
const StringVector &acceptableExtensions);
|
|
||||||
|
|
||||||
/// Returns true if the named section exists
|
|
||||||
/// You can run this check before running section()
|
|
||||||
bool containsSection(std::string sectionName, bool strict);
|
|
||||||
|
|
||||||
/// Returns a pointer to const for a section of the library
|
|
||||||
/// which is essentially a PathContainer.
|
|
||||||
/// If the section does not exists it returns a pointer to an empty path.
|
|
||||||
const PathContainer* section(std::string sectionName, bool strict);
|
|
||||||
|
|
||||||
/// Searches the library for an item and returns a boost path to it
|
|
||||||
/// Optionally you can provide a specific section
|
|
||||||
/// The result is the first that comes up according to alphabetical
|
|
||||||
/// section naming
|
|
||||||
boost::filesystem::path locate(std::string item, bool strict, bool ignoreExtensions, std::string sectionName="");
|
|
||||||
|
|
||||||
/// Prints all the available sections, used for debugging
|
|
||||||
void printSections();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,120 +0,0 @@
|
||||||
#include "fileops.hpp"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
#include <boost/algorithm/string.hpp>
|
|
||||||
#include <../components/misc/stringops.hpp>
|
|
||||||
|
|
||||||
namespace Files
|
|
||||||
{
|
|
||||||
|
|
||||||
bool isFile(const char *name)
|
|
||||||
{
|
|
||||||
return boost::filesystem::exists(boost::filesystem::path(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true if the last part of the superset matches the subset
|
|
||||||
bool endingMatches(const std::string& superset, const std::string& subset)
|
|
||||||
{
|
|
||||||
if (subset.length() > superset.length())
|
|
||||||
return false;
|
|
||||||
return superset.substr(superset.length() - subset.length()) == subset;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Makes a list of files from a directory
|
|
||||||
void FileLister( boost::filesystem::path currentPath, Files::PathContainer& list, bool recursive)
|
|
||||||
{
|
|
||||||
if (!boost::filesystem::exists(currentPath))
|
|
||||||
{
|
|
||||||
std::cout << "WARNING: " << currentPath.string() << " does not exist.\n";
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
if (recursive)
|
|
||||||
{
|
|
||||||
for ( boost::filesystem::recursive_directory_iterator end, itr(currentPath.string());
|
|
||||||
itr != end; ++itr )
|
|
||||||
{
|
|
||||||
if ( boost::filesystem::is_regular_file(*itr))
|
|
||||||
list.push_back(itr->path());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for ( boost::filesystem::directory_iterator end, itr(currentPath.string());
|
|
||||||
itr != end; ++itr )
|
|
||||||
{
|
|
||||||
if ( boost::filesystem::is_regular_file(*itr))
|
|
||||||
list.push_back(itr->path());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Locates path in path container
|
|
||||||
boost::filesystem::path FileListLocator (const Files::PathContainer& list, const boost::filesystem::path& toFind,
|
|
||||||
bool strict, bool ignoreExtensions)
|
|
||||||
{
|
|
||||||
boost::filesystem::path result("");
|
|
||||||
if (list.empty())
|
|
||||||
return result;
|
|
||||||
|
|
||||||
std::string toFindStr;
|
|
||||||
if (ignoreExtensions)
|
|
||||||
toFindStr = boost::filesystem::basename(toFind);
|
|
||||||
else
|
|
||||||
toFindStr = toFind.string();
|
|
||||||
|
|
||||||
std::string fullPath;
|
|
||||||
|
|
||||||
// The filesystems slash sets the default slash
|
|
||||||
std::string slash;
|
|
||||||
std::string wrongslash;
|
|
||||||
if(list[0].string().find("\\") != std::string::npos)
|
|
||||||
{
|
|
||||||
slash = "\\";
|
|
||||||
wrongslash = "/";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
slash = "/";
|
|
||||||
wrongslash = "\\";
|
|
||||||
}
|
|
||||||
|
|
||||||
// The file being looked for is converted to the new slash
|
|
||||||
if(toFindStr.find(wrongslash) != std::string::npos )
|
|
||||||
{
|
|
||||||
boost::replace_all(toFindStr, wrongslash, slash);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strict)
|
|
||||||
{
|
|
||||||
Misc::StringUtils::toLower(toFindStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Files::PathContainer::const_iterator it = list.begin(); it != list.end(); ++it)
|
|
||||||
{
|
|
||||||
fullPath = it->string();
|
|
||||||
if (ignoreExtensions)
|
|
||||||
fullPath.erase(fullPath.length() -
|
|
||||||
boost::filesystem::path (it->extension()).string().length());
|
|
||||||
|
|
||||||
if (!strict)
|
|
||||||
{
|
|
||||||
Misc::StringUtils::toLower(fullPath);
|
|
||||||
}
|
|
||||||
if(endingMatches(fullPath, toFindStr))
|
|
||||||
{
|
|
||||||
result = *it;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Overloaded form of the locator that takes a string and returns a string
|
|
||||||
std::string FileListLocator (const Files::PathContainer& list,const std::string& toFind, bool strict, bool ignoreExtensions)
|
|
||||||
{
|
|
||||||
return FileListLocator(list, boost::filesystem::path(toFind), strict, ignoreExtensions).string();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
#ifndef COMPONENTS_FILES_FILEOPS_HPP
|
|
||||||
#define COMPONENTS_FILES_FILEOPS_HPP
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <boost/filesystem/path.hpp>
|
|
||||||
|
|
||||||
namespace Files
|
|
||||||
{
|
|
||||||
|
|
||||||
///\brief Check if a given path is an existing file (not a directory)
|
|
||||||
///\param [in] name - filename
|
|
||||||
bool isFile(const char *name);
|
|
||||||
|
|
||||||
/// A vector of Boost Paths, very handy
|
|
||||||
typedef std::vector<boost::filesystem::path> PathContainer;
|
|
||||||
|
|
||||||
/// Makes a list of files from a directory by taking a boost
|
|
||||||
/// path and a Path Container and adds to the Path container
|
|
||||||
/// all files in the path. It has a recursive option.
|
|
||||||
void FileLister( boost::filesystem::path currentPath, Files::PathContainer& list, bool recursive);
|
|
||||||
|
|
||||||
/// Locates boost path in path container
|
|
||||||
/// returns the path from the container
|
|
||||||
/// that contains the searched path.
|
|
||||||
/// If it's not found it returns and empty path
|
|
||||||
/// Takes care of slashes, backslashes and it has a strict option.
|
|
||||||
boost::filesystem::path FileListLocator (const Files::PathContainer& list, const boost::filesystem::path& toFind,
|
|
||||||
bool strict, bool ignoreExtensions);
|
|
||||||
|
|
||||||
/// Overloaded form of the locator that takes a string and returns a string
|
|
||||||
std::string FileListLocator (const Files::PathContainer& list,const std::string& toFind, bool strict, bool ignoreExtensions);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* COMPONENTS_FILES_FILEOPS_HPP */
|
|
Loading…
Reference in a new issue