You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
693 B
22 lines
693 B
|
3 years ago
|
#include "file.hpp"
|
||
|
|
|
||
|
|
#include "engine/assets.hpp"
|
||
|
|
|
||
|
|
namespace devilution {
|
||
|
|
tl::expected<DataFile, DataFile::Error> DataFile::load(std::string_view path)
|
||
|
|
{
|
||
|
|
AssetRef ref = FindAsset(path);
|
||
|
|
if (!ref.ok())
|
||
|
|
return tl::unexpected { Error::NotFound };
|
||
|
|
const size_t size = ref.size();
|
||
|
|
// TODO: It should be possible to stream the data file contents instead of copying the whole thing into memory
|
||
|
|
std::unique_ptr<char[]> data { new char[size] };
|
||
|
|
{
|
||
|
|
AssetHandle handle = OpenAsset(std::move(ref));
|
||
|
|
if (!handle.ok() || !handle.read(data.get(), size))
|
||
|
|
return tl::unexpected { Error::ReadError };
|
||
|
|
}
|
||
|
|
return DataFile { std::move(data), size };
|
||
|
|
}
|
||
|
|
} // namespace devilution
|