28 #include "eng3d/io.hpp"
29 #include "eng3d/state.hpp"
30 #include "eng3d/utils.hpp"
31 #include "eng3d/log.hpp"
46 this->fp = std::fopen(abs_path.c_str(),
"rb");
52 std::fclose(this->fp);
57 std::fread(buf, 1, n, this->fp);
61 std::fwrite(buf, 1, n, this->fp);
66 std::fseek(this->fp, offset, SEEK_CUR);
68 std::fseek(this->fp, offset, SEEK_SET);
70 std::fseek(this->fp, offset, SEEK_END);
75 FILE* cfp =
const_cast<FILE*
>(this->fp);
77 std::fgetpos(cfp, &pos);
78 std::fseek(cfp, 0, SEEK_END);
79 long size = ::ftell(cfp);
80 std::fsetpos(cfp, &pos);
81 return static_cast<size_t>(size);
89 for(
const auto& entry : std::filesystem::recursive_directory_iterator(current)) {
90 if(entry.is_directory())
continue;
91 auto asset = std::make_shared<Eng3D::IO::Asset::File>();
92 asset->path = entry.path().lexically_relative(root).string();
93 asset->abs_path = entry.path().string();
94 #ifdef E3D_TARGET_WINDOWS
95 std::replace(asset->path.begin(), asset->path.end(),
'\\',
'/');
96 std::replace(asset->abs_path.begin(), asset->abs_path.end(),
'\\',
'/');
98 package.
assets.push_back(asset);
102 static inline std::string get_full_path() {
103 #ifndef E3D_TARGET_SWITCH
120 if(pkg_paths.empty()) {
121 const std::string asset_path = get_full_path();
123 for(
const auto& entry : std::filesystem::directory_iterator(asset_path)) {
124 if(!entry.is_directory())
continue;
126 package.
name = entry.path().lexically_relative(asset_path).string();
127 package.abs_path = entry.path().string();
133 for(
const auto& entry : pkg_paths) {
135 package.
name = entry;
136 package.abs_path = entry;
147 std::vector<std::shared_ptr<Eng3D::IO::Asset::Base>> list = this->get_multiple(path);
149 return std::shared_ptr<Eng3D::IO::Asset::Base>(
nullptr);
158 std::vector<std::shared_ptr<Eng3D::IO::Asset::Base>> list;
159 for(
const auto& package : this->packages)
160 for(
const auto& asset : package.assets)
161 if(asset->path == path.
str)
162 list.push_back(asset);
170 std::vector<std::shared_ptr<Eng3D::IO::Asset::Base>> list;
171 for(
const auto& package : this->packages)
172 for(
const auto& asset : package.assets)
173 if(asset->path.substr(0, prefix.
str.length()) == prefix.
str)
174 list.push_back(asset);
182 std::vector<std::string> paths;
183 for(
const auto& package : this->packages)
184 paths.push_back(package.abs_path);
std::vector< std::shared_ptr< Eng3D::IO::Asset::Base > > get_multiple(const Eng3D::IO::Path &path)
Obtains multiple assets iff they share a common path (useful for concating files that might clash,...
void recursive_filesystem_walk(Eng3D::IO::Package &package, const std::string &root, const std::string ¤t)
std::vector< Package > packages
std::vector< std::shared_ptr< Eng3D::IO::Asset::Base > > get_multiple_prefix(const Eng3D::IO::Path &path)
Obtains all assets starting with a given prefix.
std::vector< std::string > get_paths(void) const
Obtain all the paths that are currently under the management of a package, that is return the absolut...
std::shared_ptr< Eng3D::IO::Asset::Base > get_unique(const Eng3D::IO::Path &path)
Obtaining an unique asset means the "first-found" policy applies.
std::string translate_format(const std::string_view format, Args &&... args)
String formatter, with translation.
std::string get_abs_path() const
Get the abs path object in a safe manner, such as that the access does not occur on null pointers....
virtual void write(const void *buf, size_t n)
virtual void seek(Eng3D::IO::SeekType type, int offset)
virtual void read(void *buf, size_t n)
virtual size_t get_size(void) const
A package containing a set of assets.
std::vector< std::shared_ptr< Eng3D::IO::Asset::Base > > assets
The path class abstracts away most of the burden from handling system-dependant filesystem paths.
#define CXX_THROW(class,...)