playground-sdk/core/vfs.h

26 lines
931 B
C++

#pragma once
#include <filesystem>
#include <memory>
#include <string>
#include <vector>
#include "core/inflate.h"
namespace playground {
// Read-only virtual file system: a PFPK archive or a plain directory tree.
// Paths use '/' separators and are matched case-insensitively.
class Vfs {
public:
virtual ~Vfs() = default;
virtual const std::vector<std::string>& list() const = 0;
virtual bool read(const std::string& path, Bytes& out) const = 0;
bool exists(const std::string& path) const;
};
std::filesystem::path pathFromUtf8(const std::string& s);
std::string pathToUtf8(const std::filesystem::path& p);
bool readFile(const std::string& path, Bytes& out);
std::string normalizePath(const std::string& p);
// Opens `path` as a PFPK archive (if it is a file) or loose directory. nullptr on failure.
std::unique_ptr<Vfs> openVfs(const std::string& path, std::string* err = nullptr);
} // namespace playground