feat: add export / file packing
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include <charconv>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <fstream>
|
||||
#include <random>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
@@ -19,12 +18,9 @@ namespace {
|
||||
|
||||
[[nodiscard]] std::optional<AssetGuid> ReadMetaFile(const std::filesystem::path& path)
|
||||
{
|
||||
std::ifstream file(path);
|
||||
if (!file) {
|
||||
return std::nullopt;
|
||||
}
|
||||
try {
|
||||
const auto meta = nlohmann::json::parse(file);
|
||||
const std::vector<std::uint8_t> bytes = AssetFS::GetInstance().ReadFile(path);
|
||||
const auto meta = nlohmann::json::parse(bytes.begin(), bytes.end());
|
||||
return AssetGuid::Parse(meta.at("guid").get<std::string>());
|
||||
} catch (const std::exception& exception) {
|
||||
spdlog::warn("Ignoring broken asset meta file {}: {}", path.string(), exception.what());
|
||||
@@ -83,14 +79,14 @@ void AssetDatabase::Clear()
|
||||
void AssetDatabase::Refresh()
|
||||
{
|
||||
Clear();
|
||||
for (const FSMount& mount : AssetFS::GetInstance().GetMounts()) {
|
||||
std::error_code error;
|
||||
for (const auto& entry : std::filesystem::recursive_directory_iterator(mount.root, error)) {
|
||||
if (!entry.is_regular_file(error) || !AssetTypes::IsMeta(entry.path().string())) {
|
||||
const auto& assetFs = AssetFS::GetInstance();
|
||||
for (const FSMount& mount : assetFs.GetMounts()) {
|
||||
for (const std::filesystem::path& file : assetFs.ListFiles(mount)) {
|
||||
if (!AssetTypes::IsMeta(file.string())) {
|
||||
continue;
|
||||
}
|
||||
if (const auto guid = ReadMetaFile(entry.path())) {
|
||||
std::filesystem::path asset = entry.path();
|
||||
if (const auto guid = ReadMetaFile(file)) {
|
||||
std::filesystem::path asset = file;
|
||||
asset.replace_extension();
|
||||
Register(mount.scheme + "://" + asset.lexically_relative(mount.root).generic_string(), *guid);
|
||||
}
|
||||
@@ -131,8 +127,7 @@ std::optional<AssetGuid> AssetDatabase::GuidForSave(std::string_view path)
|
||||
}
|
||||
|
||||
auto& assetFs = AssetFS::GetInstance();
|
||||
std::error_code error;
|
||||
if (!std::filesystem::is_regular_file(assetFs.GetFullPath(path), error)) {
|
||||
if (!assetFs.Exists(assetFs.GetFullPath(path))) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user