2022-06-16 15:42:08 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
|
|
|
|
#include <hex/helpers/fs.hpp>
|
|
|
|
|
|
|
|
#include <microtar.h>
|
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
|
|
|
class Tar {
|
|
|
|
public:
|
|
|
|
enum class Mode {
|
|
|
|
Read,
|
|
|
|
Write,
|
|
|
|
Create
|
|
|
|
};
|
|
|
|
|
|
|
|
Tar() = default;
|
|
|
|
Tar(const std::fs::path &path, Mode mode);
|
|
|
|
~Tar();
|
2022-08-08 21:23:52 +02:00
|
|
|
Tar(const Tar&) = delete;
|
|
|
|
Tar(Tar&&) noexcept;
|
|
|
|
|
|
|
|
Tar &operator=(Tar &&other) noexcept;
|
|
|
|
|
|
|
|
void close();
|
|
|
|
|
2023-06-21 20:07:36 +02:00
|
|
|
/**
|
|
|
|
* @brief get the error string explaining the error that occured when opening the file.
|
|
|
|
* This error is a combination of the tar error and the native file open error
|
|
|
|
*/
|
|
|
|
std::string getOpenErrorString();
|
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
[[nodiscard]] std::vector<u8> readVector(const std::fs::path &path);
|
2022-08-08 21:23:52 +02:00
|
|
|
[[nodiscard]] std::string readString(const std::fs::path &path);
|
2022-06-16 15:42:08 +02:00
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
void writeVector(const std::fs::path &path, const std::vector<u8> &data);
|
|
|
|
void writeString(const std::fs::path &path, const std::string &data);
|
2022-06-16 15:42:08 +02:00
|
|
|
|
2022-08-08 21:23:52 +02:00
|
|
|
[[nodiscard]] std::vector<std::fs::path> listEntries(const std::fs::path &basePath = "/");
|
|
|
|
[[nodiscard]] bool contains(const std::fs::path &path);
|
2022-06-16 15:42:08 +02:00
|
|
|
|
|
|
|
void extract(const std::fs::path &path, const std::fs::path &outputPath);
|
|
|
|
void extractAll(const std::fs::path &outputPath);
|
|
|
|
|
2022-08-08 21:23:52 +02:00
|
|
|
[[nodiscard]] bool isValid() const { return this->m_valid; }
|
|
|
|
|
2022-06-16 15:42:08 +02:00
|
|
|
private:
|
|
|
|
mtar_t m_ctx = { };
|
2023-05-05 21:57:37 +02:00
|
|
|
std::fs::path m_path;
|
2022-08-08 21:23:52 +02:00
|
|
|
|
|
|
|
bool m_valid = false;
|
2023-06-21 20:07:36 +02:00
|
|
|
|
|
|
|
// these will be updated when the constructor is called
|
|
|
|
int m_tarOpenErrno = MTAR_ESUCCESS;
|
|
|
|
int m_fileOpenErrno = 0;
|
2022-06-16 15:42:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|