mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-18 16:32:32 +02:00
clang-format files in rwlib/source/platform
This commit is contained in:
parent
c4bb714e54
commit
8a19f9b5d0
@ -6,15 +6,11 @@
|
||||
/**
|
||||
* @brief Contains a pointer to a file's contents.
|
||||
*/
|
||||
struct FileContentsInfo
|
||||
{
|
||||
struct FileContentsInfo {
|
||||
char* data;
|
||||
size_t length;
|
||||
|
||||
FileContentsInfo(char* mem, size_t len)
|
||||
: data(mem), length(len)
|
||||
{
|
||||
|
||||
FileContentsInfo(char* mem, size_t len) : data(mem), length(len) {
|
||||
}
|
||||
|
||||
~FileContentsInfo() {
|
||||
|
@ -1,16 +1,16 @@
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
#include <platform/FileIndex.hpp>
|
||||
#include <fstream>
|
||||
#include <loaders/LoaderIMG.hpp>
|
||||
#include <platform/FileIndex.hpp>
|
||||
|
||||
using namespace boost::filesystem;
|
||||
|
||||
void FileIndex::indexGameDirectory(const fs::path& base_path)
|
||||
{
|
||||
void FileIndex::indexGameDirectory(const fs::path& base_path) {
|
||||
gamedatapath_ = base_path;
|
||||
|
||||
for(const path& entry : boost::make_iterator_range(recursive_directory_iterator(base_path), {})) {
|
||||
for (const path& entry : boost::make_iterator_range(
|
||||
recursive_directory_iterator(base_path), {})) {
|
||||
if (is_regular_file(entry)) {
|
||||
std::string name = entry.string();
|
||||
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
|
||||
@ -20,10 +20,10 @@ void FileIndex::indexGameDirectory(const fs::path& base_path)
|
||||
}
|
||||
}
|
||||
|
||||
FileHandle FileIndex::openFilePath(const std::string &file_path)
|
||||
{
|
||||
FileHandle FileIndex::openFilePath(const std::string& file_path) {
|
||||
auto datapath = findFilePath(file_path);
|
||||
std::ifstream dfile(datapath.string(), std::ios_base::binary | std::ios_base::ate);
|
||||
std::ifstream dfile(datapath.string(),
|
||||
std::ios_base::binary | std::ios_base::ate);
|
||||
if (!dfile.is_open()) {
|
||||
throw std::runtime_error("Unable to open file: " + file_path);
|
||||
}
|
||||
@ -36,13 +36,14 @@ FileHandle FileIndex::openFilePath(const std::string &file_path)
|
||||
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), {})) {
|
||||
void FileIndex::indexTree(const std::string& root) {
|
||||
for (const path& entry :
|
||||
boost::make_iterator_range(recursive_directory_iterator(root), {})) {
|
||||
std::string directory = entry.parent_path().string();
|
||||
std::string realName = entry.filename().string();
|
||||
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)) {
|
||||
files[lowerName] = {lowerName, realName, directory, ""};
|
||||
@ -50,8 +51,7 @@ void FileIndex::indexTree(const std::string& root)
|
||||
}
|
||||
}
|
||||
|
||||
void FileIndex::indexArchive(const std::string& archive)
|
||||
{
|
||||
void FileIndex::indexArchive(const std::string& archive) {
|
||||
// Split directory from archive name
|
||||
path archive_path = path(archive);
|
||||
path directory = archive_path.parent_path();
|
||||
@ -60,7 +60,8 @@ void FileIndex::indexArchive(const std::string& archive)
|
||||
|
||||
LoaderIMG img;
|
||||
if (!img.load(archive_full_path.string())) {
|
||||
throw std::runtime_error("Failed to load IMG archive: " + archive_full_path.string());
|
||||
throw std::runtime_error("Failed to load IMG archive: " +
|
||||
archive_full_path.string());
|
||||
}
|
||||
|
||||
std::string lowerName;
|
||||
@ -70,14 +71,15 @@ void FileIndex::indexArchive(const std::string& archive)
|
||||
if (asset.size == 0) continue;
|
||||
|
||||
lowerName = asset.name;
|
||||
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower);
|
||||
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(),
|
||||
::tolower);
|
||||
|
||||
files[lowerName] = {lowerName, asset.name, directory.string(), archive_basename.string()};
|
||||
files[lowerName] = {lowerName, asset.name, directory.string(),
|
||||
archive_basename.string()};
|
||||
}
|
||||
}
|
||||
|
||||
FileHandle FileIndex::openFile(const std::string& filename)
|
||||
{
|
||||
FileHandle FileIndex::openFile(const std::string& filename) {
|
||||
auto iterator = files.find(filename);
|
||||
if (iterator == files.end()) {
|
||||
return nullptr;
|
||||
@ -105,8 +107,7 @@ FileHandle FileIndex::openFile(const std::string& filename)
|
||||
length = file.size * 2048;
|
||||
data = img.loadToMemory(f.originalName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
std::ifstream dfile(fsName.c_str(), std::ios_base::binary);
|
||||
if (!dfile.is_open()) {
|
||||
throw std::runtime_error("Unable to open file: " + fsName);
|
||||
|
@ -4,25 +4,22 @@
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<> struct hash<fs::path>
|
||||
{
|
||||
size_t operator()(const fs::path& p) const
|
||||
{
|
||||
namespace std {
|
||||
template <>
|
||||
struct hash<fs::path> {
|
||||
size_t operator()(const fs::path& p) const {
|
||||
return fs::hash_value(p);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
class FileIndex
|
||||
{
|
||||
class FileIndex {
|
||||
private:
|
||||
/**
|
||||
* Mapping type (lower case name) => (on disk name)
|
||||
@ -33,7 +30,6 @@ private:
|
||||
FileSystemMap filesystemfiles_;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief indexDirectory finds the true case for each file in the tree
|
||||
* @param base_path
|
||||
@ -49,8 +45,7 @@ public:
|
||||
* @param path
|
||||
* @return The file path as it exists on disk
|
||||
*/
|
||||
fs::path findFilePath(std::string path)
|
||||
{
|
||||
fs::path findFilePath(std::string path) {
|
||||
auto backslash = std::string::npos;
|
||||
while ((backslash = path.find("\\")) != std::string::npos) {
|
||||
path.replace(backslash, 1, "/");
|
||||
@ -69,8 +64,7 @@ public:
|
||||
*/
|
||||
FileHandle openFilePath(const std::string& file_path);
|
||||
|
||||
struct IndexData
|
||||
{
|
||||
struct IndexData {
|
||||
/// Lowercase identifying filename
|
||||
std::string filename;
|
||||
/// Original filename
|
||||
|
Loading…
Reference in New Issue
Block a user