mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-07-20 15:00:36 +00:00
chore: parse includes and assetlists while parsing zone definition
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
#include "SearchPathFilesystem.h"
|
||||
|
||||
#include "Utils/ObjFileStream.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
SearchPathFilesystem::SearchPathFilesystem(std::string path)
|
||||
: m_path(std::move(path))
|
||||
{
|
||||
}
|
||||
|
||||
const std::string& SearchPathFilesystem::GetPath()
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
SearchPathOpenFile SearchPathFilesystem::Open(const std::string& fileName)
|
||||
{
|
||||
const auto filePath = fs::path(m_path).append(fileName);
|
||||
std::ifstream file(filePath.string(), std::fstream::in | std::fstream::binary);
|
||||
|
||||
if (file.is_open())
|
||||
return SearchPathOpenFile(std::make_unique<std::ifstream>(std::move(file)), static_cast<int64_t>(file_size(filePath)));
|
||||
|
||||
return SearchPathOpenFile();
|
||||
}
|
||||
|
||||
void SearchPathFilesystem::Find(const SearchPathSearchOptions& options, const std::function<void(const std::string&)>& callback)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (options.m_should_include_subdirectories)
|
||||
{
|
||||
std::filesystem::recursive_directory_iterator iterator(m_path);
|
||||
for (const auto entry = begin(iterator); iterator != end(iterator); ++iterator)
|
||||
{
|
||||
auto path = entry->path();
|
||||
if (options.m_filter_extensions && path.extension().string() != options.m_extension)
|
||||
continue;
|
||||
callback(options.m_absolute_paths ? absolute(path).string() : path.string());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::filesystem::directory_iterator iterator(m_path);
|
||||
for (const auto entry = begin(iterator); iterator != end(iterator); ++iterator)
|
||||
{
|
||||
auto path = entry->path();
|
||||
if (options.m_filter_extensions && path.extension().string() != options.m_extension)
|
||||
continue;
|
||||
callback(options.m_absolute_paths ? absolute(path).string() : path.string());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::filesystem::filesystem_error& e)
|
||||
{
|
||||
std::cerr << std::format("Directory Iterator threw error when trying to find files: \"{}\"\n", e.what());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user