mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-23 12:26:56 +02:00
58 lines
2.3 KiB
C++
58 lines
2.3 KiB
C++
#ifndef KYTY_COMMON_ARCHIVE_H_
|
|
#define KYTY_COMMON_ARCHIVE_H_
|
|
|
|
#include "common/file.h"
|
|
|
|
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
namespace Common {
|
|
|
|
class ArchiveReader;
|
|
|
|
class ArchiveFile {
|
|
public:
|
|
~ArchiveFile();
|
|
|
|
[[nodiscard]] uint64_t Size() const;
|
|
[[nodiscard]] uint64_t Tell() const;
|
|
bool Seek(uint64_t offset);
|
|
void Read(void* data, uint32_t size, uint32_t* bytes_read);
|
|
|
|
KYTY_CLASS_NO_COPY(ArchiveFile);
|
|
|
|
private:
|
|
struct Private;
|
|
explicit ArchiveFile(std::unique_ptr<Private> p);
|
|
std::unique_ptr<Private> m_p;
|
|
|
|
friend std::unique_ptr<ArchiveFile> OpenArchiveFile(const std::filesystem::path& path);
|
|
};
|
|
|
|
// Virtual paths use "archive.ext!/member" and retain native host-path encoding.
|
|
[[nodiscard]] std::filesystem::path MakeArchivePath(const std::filesystem::path& archive,
|
|
const std::filesystem::path& member = {});
|
|
[[nodiscard]] bool IsSupportedArchive(const std::filesystem::path& path);
|
|
[[nodiscard]] bool IsArchivePath(const std::filesystem::path& path);
|
|
[[nodiscard]] std::optional<File::Info> GetArchiveInfo(const std::filesystem::path& path);
|
|
[[nodiscard]] std::vector<File::DirEntry> GetArchiveDirEntries(const std::filesystem::path& path);
|
|
[[nodiscard]] std::filesystem::path GetArchiveHostPath(const std::filesystem::path& path);
|
|
[[nodiscard]] std::unique_ptr<ArchiveFile> OpenArchiveFile(const std::filesystem::path& path);
|
|
|
|
// Retain this handle while a mount or metadata scan is active to reuse the index and block cache.
|
|
// Accepts either a host archive filename or a virtual path inside the archive.
|
|
[[nodiscard]] std::shared_ptr<ArchiveReader> OpenArchive(const std::filesystem::path& path);
|
|
|
|
// Packs a host directory into a new ZArchive outside it. progress gets 0 < done <= total and
|
|
// returns false to cancel. A failed or cancelled pack removes the partial archive.
|
|
[[nodiscard]] bool PackArchive(const std::filesystem::path& directory,
|
|
const std::filesystem::path& archive,
|
|
const std::function<bool(uint64_t done, uint64_t total)>& progress);
|
|
|
|
} // namespace Common
|
|
|
|
#endif /* KYTY_COMMON_ARCHIVE_H_ */
|