1#include "DvdArchive.hh"
3#include <abstract/File.hh>
5#include <egg/core/Decomp.hh>
10DvdArchive::DvdArchive()
11 : m_archive(nullptr), m_archiveStart(nullptr), m_archiveSize(0), m_fileStart(nullptr),
12 m_fileSize(0), m_state(State::Cleared) {}
15DvdArchive::~DvdArchive() {
20void DvdArchive::decompress() {
21 m_archiveSize = EGG::Decomp::GetExpandSize(
reinterpret_cast<u8 *
>(m_fileStart));
22 m_archiveStart =
new u8[m_archiveSize];
23 EGG::Decomp::DecodeSZS(
reinterpret_cast<u8 *
>(m_fileStart),
24 reinterpret_cast<u8 *
>(m_archiveStart));
25 m_state = State::Decompressed;
29void *DvdArchive::getFile(
const char *filename,
size_t *size)
const {
30 if (m_state != State::Mounted) {
35 if (filename[0] ==
'/') {
36 snprintf(buffer,
sizeof(buffer),
"%s", filename);
38 snprintf(buffer,
sizeof(buffer),
"/%s", filename);
40 buffer[
sizeof(buffer) - 1] =
'\0';
43 s32 entryId = m_archive->convertPathToEntryId(buffer);
48 void *file = m_archive->getFileFast(entryId, fileInfo);
50 *size = fileInfo.length;
57void DvdArchive::load(
const char *path,
bool decompress_) {
58 if (m_state == State::Cleared) {
62 if (m_state == State::Ripped) {
74void DvdArchive::load(
const DvdArchive *other) {
75 if (other->m_state == State::Ripped) {
76 m_fileStart = other->m_fileStart;
77 m_state = State::Ripped;
80 m_fileStart =
nullptr;
83 m_state = State::Cleared;
88void DvdArchive::load(
void *fileStart,
size_t fileSize,
bool decompress_) {
89 m_fileStart = fileStart;
90 m_fileSize = fileSize;
93 m_fileStart =
nullptr;
100void DvdArchive::mount() {
102 m_state = State::Mounted;
106void DvdArchive::move() {
107 m_archiveStart = m_fileStart;
108 m_archiveSize = m_fileSize;
109 m_fileStart =
nullptr;
111 m_state = State::Decompressed;
115void DvdArchive::rip(
const char *path) {
116 m_fileStart = Abstract::File::Load(path, m_fileSize);
117 if (m_fileSize != 0 && m_fileStart) {
118 m_state = State::Ripped;
123void DvdArchive::clear() {
129void DvdArchive::clearArchive() {
130 if (!m_archiveStart) {
134 delete[]
static_cast<u8 *
>(m_archiveStart);
135 m_archiveStart =
nullptr;
140void DvdArchive::clearFile() {
145 delete[]
static_cast<u8 *
>(m_fileStart);
146 m_fileStart =
nullptr;
151void DvdArchive::unmount() {
152 if (m_state == State::Mounted) {
153 m_archive->unmount();
156 m_state = State::Cleared;
static Archive * Mount(void *archiveStart)
Creates a new Archive object or increments the ref count for an already existing Archive.
High-level handling for generic system operations, such as input reading, race configuration,...