mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-18 16:32:32 +02:00
Add new openFilePath method to FileIndex
This commit is contained in:
parent
03309d76d9
commit
23e25ed751
@ -11,11 +11,17 @@ struct FileContentsInfo
|
||||
char* data;
|
||||
size_t length;
|
||||
|
||||
FileContentsInfo(char* mem, size_t len)
|
||||
: data(mem), length(len)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
~FileContentsInfo() {
|
||||
delete[] data;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<FileContentsInfo> FileHandle;
|
||||
using FileHandle = std::shared_ptr<FileContentsInfo>;
|
||||
|
||||
#endif
|
||||
|
@ -20,6 +20,22 @@ void FileIndex::indexGameDirectory(const fs::path& base_path)
|
||||
}
|
||||
}
|
||||
|
||||
FileHandle FileIndex::openFilePath(const std::string &file_path)
|
||||
{
|
||||
auto datapath = findFilePath(file_path);
|
||||
std::ifstream dfile(datapath.c_str(), std::ios_base::binary | std::ios_base::ate);
|
||||
if ( ! dfile.is_open()) {
|
||||
throw std::runtime_error("Unable to open file: " + file_path);
|
||||
}
|
||||
|
||||
auto length = dfile.tellg();
|
||||
dfile.seekg(0);
|
||||
auto data = new char[length];
|
||||
dfile.read(data, length);
|
||||
|
||||
return std::make_shared<FileContentsInfo> ( data, length );
|
||||
}
|
||||
|
||||
void FileIndex::indexTree(const std::string& root)
|
||||
{
|
||||
for(const path& entry : boost::make_iterator_range(recursive_directory_iterator(root), {})) {
|
||||
|
@ -62,6 +62,13 @@ public:
|
||||
return filesystemfiles_[name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief openFilePath opens a file on the disk
|
||||
* @param file_path
|
||||
* @return A handle for the file on the disk
|
||||
*/
|
||||
FileHandle openFilePath(const std::string& file_path);
|
||||
|
||||
struct IndexData
|
||||
{
|
||||
/// Lowercase identifying filename
|
||||
|
Loading…
Reference in New Issue
Block a user