mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-12 07:48:16 -05:00
chore: add abstraction for opening output files to be able to mock it
This commit is contained in:
@ -379,17 +379,16 @@ void IPakToCreate::AddImage(std::string imageName)
|
||||
m_image_names.emplace_back(std::move(imageName));
|
||||
}
|
||||
|
||||
void IPakToCreate::Build(ISearchPath& searchPath, const std::filesystem::path& outPath)
|
||||
void IPakToCreate::Build(ISearchPath& searchPath, IOutputPath& outPath)
|
||||
{
|
||||
auto filePath = outPath / std::format("{}.ipak", m_name);
|
||||
std::ofstream file(filePath, std::ios::out | std::ios::binary);
|
||||
if (!file.is_open())
|
||||
const auto file = outPath.Open(std::format("{}.ipak", m_name));
|
||||
if (!file)
|
||||
{
|
||||
std::cerr << std::format("Failed to open file for ipak {}\n", m_name);
|
||||
return;
|
||||
}
|
||||
|
||||
IPakWriter writer(file, searchPath, m_image_names);
|
||||
IPakWriter writer(*file, searchPath, m_image_names);
|
||||
writer.Write();
|
||||
|
||||
std::cout << std::format("Created ipak {} with {} entries\n", m_name, m_image_names.size());
|
||||
@ -421,7 +420,7 @@ IPakToCreate* IPakCreator::GetOrAddIPak(const std::string& ipakName)
|
||||
return result;
|
||||
}
|
||||
|
||||
void IPakCreator::Finalize(ISearchPath& searchPath, const std::filesystem::path& outPath)
|
||||
void IPakCreator::Finalize(ISearchPath& searchPath, IOutputPath& outPath)
|
||||
{
|
||||
for (const auto& ipakToCreate : m_ipaks)
|
||||
ipakToCreate->Build(searchPath, outPath);
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
#include "Asset/IZoneAssetCreationState.h"
|
||||
#include "KeyValuePairs/KeyValuePairsCreator.h"
|
||||
#include "SearchPath/IOutputPath.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@ -15,14 +15,14 @@ public:
|
||||
explicit IPakToCreate(std::string name);
|
||||
|
||||
void AddImage(std::string imageName);
|
||||
void Build(ISearchPath& searchPath, const std::filesystem::path& outPath);
|
||||
void Build(ISearchPath& searchPath, IOutputPath& outPath);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
std::vector<std::string> m_image_names;
|
||||
};
|
||||
|
||||
class IPakCreator : public IZoneAssetCreationState
|
||||
class IPakCreator final : public IZoneAssetCreationState
|
||||
{
|
||||
public:
|
||||
IPakCreator();
|
||||
@ -30,7 +30,7 @@ public:
|
||||
void Inject(ZoneAssetCreationInjection& inject) override;
|
||||
|
||||
IPakToCreate* GetOrAddIPak(const std::string& ipakName);
|
||||
void Finalize(ISearchPath& searchPath, const std::filesystem::path& outPath);
|
||||
void Finalize(ISearchPath& searchPath, IOutputPath& outPath);
|
||||
|
||||
private:
|
||||
KeyValuePairsCreator* m_kvp_creator;
|
||||
|
Reference in New Issue
Block a user