mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 08:15:38 +07:00
Merge pull request #19 from enduro2d/hotfix/vfs_write
vfs write support
This commit is contained in:
@@ -20,7 +20,7 @@ namespace e2d
|
||||
class vfs final : public module<vfs> {
|
||||
public:
|
||||
vfs();
|
||||
~vfs() noexcept;
|
||||
~vfs() noexcept final;
|
||||
|
||||
class file_source : private e2d::noncopyable {
|
||||
public:
|
||||
@@ -29,6 +29,7 @@ namespace e2d
|
||||
virtual bool exists(str_view path) const = 0;
|
||||
virtual input_stream_uptr open(str_view path) const = 0;
|
||||
virtual std::pair<buffer,bool> load(str_view path) const = 0;
|
||||
virtual output_stream_uptr write(str_view path, bool append) const = 0;
|
||||
};
|
||||
using file_source_uptr = std::unique_ptr<file_source>;
|
||||
|
||||
@@ -43,6 +44,7 @@ namespace e2d
|
||||
bool exists(const url& url) const;
|
||||
input_stream_uptr open(const url& url) const;
|
||||
std::pair<buffer,bool> load(const url& url) const;
|
||||
output_stream_uptr write(const url& url, bool append) const;
|
||||
std::future<std::pair<buffer,bool>> load_async(const url& url) const;
|
||||
|
||||
url resolve_scheme_aliases(const url& url) const;
|
||||
@@ -59,6 +61,7 @@ namespace e2d
|
||||
bool exists(str_view path) const final;
|
||||
input_stream_uptr open(str_view path) const final;
|
||||
std::pair<buffer,bool> load(str_view path) const final;
|
||||
output_stream_uptr write(str_view path, bool append) const final;
|
||||
private:
|
||||
class state;
|
||||
std::unique_ptr<state> state_;
|
||||
@@ -72,6 +75,7 @@ namespace e2d
|
||||
bool exists(str_view path) const final;
|
||||
input_stream_uptr open(str_view path) const final;
|
||||
std::pair<buffer,bool> load(str_view path) const final;
|
||||
output_stream_uptr write(str_view path, bool append) const final;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -156,6 +156,14 @@ namespace e2d
|
||||
}, std::make_pair(buffer(), false));
|
||||
}
|
||||
|
||||
output_stream_uptr vfs::write(const url& url, bool append) const {
|
||||
std::lock_guard<std::mutex> guard(state_->mutex);
|
||||
return state_->with_file_source(url,
|
||||
[&append](const file_source_uptr& source, const str& path) {
|
||||
return source->write(path, append);
|
||||
}, output_stream_uptr());
|
||||
}
|
||||
|
||||
std::future<std::pair<buffer,bool>> vfs::load_async(const url& url) const {
|
||||
return state_->worker.async([](input_stream_uptr stream){
|
||||
buffer buf;
|
||||
@@ -182,9 +190,9 @@ namespace e2d
|
||||
stream_ptr stream;
|
||||
jobber worker{1};
|
||||
public:
|
||||
state(input_stream_uptr stream)
|
||||
: archive(open_archive_(stream))
|
||||
, stream(std::move(stream)) {}
|
||||
state(input_stream_uptr nstream)
|
||||
: archive(open_archive_(nstream))
|
||||
, stream(std::move(nstream)) {}
|
||||
~state() noexcept = default;
|
||||
private:
|
||||
static archive_ptr open_archive_(const input_stream_uptr& stream) noexcept {
|
||||
@@ -263,6 +271,11 @@ namespace e2d
|
||||
: std::make_pair(buffer(), false);
|
||||
}
|
||||
|
||||
output_stream_uptr archive_file_source::write(str_view path, bool append) const {
|
||||
E2D_UNUSED(path, append);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//
|
||||
// filesystem_file_source
|
||||
//
|
||||
@@ -288,4 +301,8 @@ namespace e2d
|
||||
? std::make_pair(std::move(buf), true)
|
||||
: std::make_pair(buffer(), false);
|
||||
}
|
||||
|
||||
output_stream_uptr filesystem_file_source::write(str_view path, bool append) const {
|
||||
return make_write_file(path, append);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user