2017-02-16 03:15:00 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2023-11-15 20:07:42 +01:00
|
|
|
#include "util/types.hpp"
|
|
|
|
|
|
2017-02-16 03:15:00 +01:00
|
|
|
#include <map>
|
|
|
|
|
|
2017-02-22 14:08:53 +01:00
|
|
|
struct TARHeader
|
|
|
|
|
{
|
2017-02-16 03:15:00 +01:00
|
|
|
char name[100];
|
|
|
|
|
char dontcare[24];
|
|
|
|
|
char size[12];
|
|
|
|
|
char mtime[12];
|
|
|
|
|
char chksum[8];
|
|
|
|
|
char filetype;
|
|
|
|
|
char linkname[100];
|
|
|
|
|
char magic[6];
|
|
|
|
|
char dontcare2[82];
|
|
|
|
|
char prefix[155];
|
2021-07-09 19:28:38 +02:00
|
|
|
char padding[12]; // atime for RPCS3
|
2023-11-15 20:07:42 +01:00
|
|
|
|
|
|
|
|
ENABLE_BITWISE_SERIALIZATION;
|
2017-02-22 14:08:53 +01:00
|
|
|
};
|
2017-02-16 03:15:00 +01:00
|
|
|
|
2021-07-09 19:28:38 +02:00
|
|
|
namespace fs
|
|
|
|
|
{
|
|
|
|
|
class file;
|
2023-11-15 20:07:42 +01:00
|
|
|
struct dir_entry;
|
2025-04-05 21:50:45 +02:00
|
|
|
} // namespace fs
|
2021-07-09 19:28:38 +02:00
|
|
|
|
2023-10-29 01:46:52 +02:00
|
|
|
namespace utils
|
|
|
|
|
{
|
|
|
|
|
struct serial;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-16 03:15:00 +01:00
|
|
|
class tar_object
|
|
|
|
|
{
|
2023-11-15 20:07:42 +01:00
|
|
|
const fs::file* m_file;
|
|
|
|
|
utils::serial* m_ar;
|
|
|
|
|
const usz m_ar_tar_start;
|
2017-02-16 03:15:00 +01:00
|
|
|
|
2025-04-05 21:50:45 +02:00
|
|
|
usz largest_offset = 0; // We store the largest offset so we can continue to scan from there.
|
2021-04-19 13:22:03 +02:00
|
|
|
std::map<std::string, std::pair<u64, TARHeader>> m_map{}; // Maps path to offset of file data and its header
|
2017-02-16 03:15:00 +01:00
|
|
|
|
2021-03-11 00:26:39 +01:00
|
|
|
TARHeader read_header(u64 offset) const;
|
2017-02-16 03:15:00 +01:00
|
|
|
|
|
|
|
|
public:
|
2021-03-11 00:26:39 +01:00
|
|
|
tar_object(const fs::file& file);
|
2023-11-15 20:07:42 +01:00
|
|
|
tar_object(utils::serial& ar);
|
2017-02-16 03:15:00 +01:00
|
|
|
|
|
|
|
|
std::vector<std::string> get_filenames();
|
|
|
|
|
|
2023-11-15 20:07:42 +01:00
|
|
|
std::unique_ptr<utils::serial> get_file(const std::string& path, std::string* new_file_path = nullptr);
|
2017-02-16 03:15:00 +01:00
|
|
|
|
2023-10-29 01:46:52 +02:00
|
|
|
using process_func = std::function<bool(const fs::file&, std::string&, utils::serial&)>;
|
2021-07-09 19:28:38 +02:00
|
|
|
|
2022-07-04 15:02:17 +02:00
|
|
|
// Extract all files in archive to destination (as VFS if is_vfs is true)
|
2021-03-05 17:07:36 +01:00
|
|
|
// Allow to optionally specify explicit mount point (which may be directory meant for extraction)
|
2024-11-05 22:34:38 +01:00
|
|
|
bool extract(const std::string& prefix_path = {}, bool is_vfs = false);
|
2021-07-09 19:28:38 +02:00
|
|
|
|
2023-11-15 20:07:42 +01:00
|
|
|
static void save_directory(const std::string& src_dir, utils::serial& ar, const process_func& func = {}, std::vector<fs::dir_entry>&& = std::vector<fs::dir_entry>{}, bool has_evaluated_results = false, usz src_dir_pos = umax);
|
2017-02-22 14:08:53 +01:00
|
|
|
};
|
2021-03-05 17:07:36 +01:00
|
|
|
|
2021-07-09 19:28:38 +02:00
|
|
|
bool extract_tar(const std::string& file_path, const std::string& dir_path, fs::file file = {});
|