-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilesystem.cpp
More file actions
41 lines (34 loc) · 1.24 KB
/
filesystem.cpp
File metadata and controls
41 lines (34 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include "include/walafus/filesystem.h"
#include "include/walafus/errors.h"
static bool default_error_handler(WalafusFilesystemErrorCode error_code, const char* error_description, void* error_object) {
std::cout << error_description << std::endl;
return true;
}
bool (*walafus_on_error)(WalafusFilesystemErrorCode error_code, const char* error_description, void* error_object)
= default_error_handler;
Filesystem::Filesystem() {
//
}
void Filesystem::add_source(BaseFilesystemSource* source) {
sources.push_back(source);
}
std::unique_ptr<BaseFileStream> Filesystem::open_file_read(std::string_view filename) {
for (auto i = sources.rbegin(); i != sources.rend(); ++i) {
auto source = *i;
auto file = source->open_file_read(filename);
if (file)
return file;
}
return nullptr;
}
std::vector<ubyte> Filesystem::read_file(std::string_view filename) {
if (auto stream = open_file_read(filename); stream)
return stream->read();
return {};
}
ulong Filesystem::read_file(std::string_view filename, void* dst, ulong available_size) {
if (auto stream = open_file_read(filename); stream)
return stream->read_into(dst, available_size);
return {};
}