2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-01-11 03:01:49 +00:00

chore: pass ZoneLoading error as result

This commit is contained in:
Jan Laupetin
2025-10-11 15:28:19 +01:00
parent 098be53559
commit b27b7e77bd
9 changed files with 181 additions and 121 deletions

View File

@@ -2,7 +2,6 @@
#include "Loading/IZoneLoaderFactory.h"
#include "Loading/ZoneLoader.h"
#include "Utils/Logging/Log.h"
#include "Utils/ObjFileStream.h"
#include <filesystem>
@@ -12,24 +11,18 @@
namespace fs = std::filesystem;
std::unique_ptr<Zone> ZoneLoading::LoadZone(const std::string& path)
result::Expected<std::unique_ptr<Zone>, std::string> ZoneLoading::LoadZone(const std::string& path)
{
auto zoneName = fs::path(path).filename().replace_extension().string();
std::ifstream file(path, std::fstream::in | std::fstream::binary);
if (!file.is_open())
{
con::error("Could not open file '{}'.", path);
return nullptr;
}
return result::Unexpected(std::format("Could not open file '{}'.", path));
ZoneHeader header{};
file.read(reinterpret_cast<char*>(&header), sizeof(header));
if (file.gcount() != sizeof(header))
{
con::error("Failed to read zone header from file '{}'.", path);
return nullptr;
}
return result::Unexpected(std::format("Failed to read zone header from file '{}'.", path));
std::unique_ptr<ZoneLoader> zoneLoader;
for (auto game = 0u; game < static_cast<unsigned>(GameId::COUNT); game++)
@@ -42,10 +35,7 @@ std::unique_ptr<Zone> ZoneLoading::LoadZone(const std::string& path)
}
if (!zoneLoader)
{
con::error("Could not create factory for zone '{}'.", zoneName);
return nullptr;
}
return result::Unexpected(std::format("Could not create factory for zone '{}'.", zoneName));
auto loadedZone = zoneLoader->LoadZone(file);

View File

@@ -1,4 +1,6 @@
#pragma once
#include "Utils/Result.h"
#include "Zone/Zone.h"
#include <string>
@@ -6,5 +8,5 @@
class ZoneLoading
{
public:
static std::unique_ptr<Zone> LoadZone(const std::string& path);
static result::Expected<std::unique_ptr<Zone>, std::string> LoadZone(const std::string& path);
};