[VFS] More cleanup in Zarchive loader
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2020 Ben Vanik. All rights reserved. *
|
||||
* Copyright 2023 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -19,49 +19,31 @@
|
||||
namespace xe {
|
||||
namespace vfs {
|
||||
|
||||
using namespace xe::literals;
|
||||
|
||||
const size_t kXESectorSize = 2_KiB;
|
||||
|
||||
DiscZarchiveDevice::DiscZarchiveDevice(const std::string_view mount_path,
|
||||
const std::filesystem::path& host_path)
|
||||
: Device(mount_path),
|
||||
name_("GDFX"),
|
||||
host_path_(host_path),
|
||||
opaque_(nullptr) {}
|
||||
: Device(mount_path), name_("GDFX"), host_path_(host_path), reader_() {}
|
||||
|
||||
DiscZarchiveDevice::~DiscZarchiveDevice() {
|
||||
ZArchiveReader* reader = static_cast<ZArchiveReader*>(opaque_);
|
||||
if (reader != nullptr) {
|
||||
delete reader;
|
||||
}
|
||||
};
|
||||
DiscZarchiveDevice::~DiscZarchiveDevice(){};
|
||||
|
||||
bool DiscZarchiveDevice::Initialize() {
|
||||
ZArchiveReader* reader = ZArchiveReader::OpenFromFile(host_path_);
|
||||
reader_ =
|
||||
std::unique_ptr<ZArchiveReader>(ZArchiveReader::OpenFromFile(host_path_));
|
||||
|
||||
if (!reader) {
|
||||
if (!reader_) {
|
||||
XELOGE("Disc ZArchive could not be opened");
|
||||
return false;
|
||||
}
|
||||
|
||||
opaque_ = static_cast<void*>(reader);
|
||||
bool result = reader->IsFile(reader->LookUp("default.xex", true, false));
|
||||
if (!result) {
|
||||
XELOGE("Failed to verify disc ZArchive (no default.xex)");
|
||||
}
|
||||
|
||||
const std::string root_path = std::string("/");
|
||||
ZArchiveNodeHandle handle = reader->LookUp(root_path);
|
||||
auto root_entry = new DiscZarchiveEntry(this, nullptr, root_path, reader);
|
||||
const ZArchiveNodeHandle handle = reader_->LookUp(root_path);
|
||||
auto root_entry = new DiscZarchiveEntry(this, nullptr, root_path);
|
||||
root_entry->attributes_ = kFileAttributeDirectory;
|
||||
root_entry->handle_ = static_cast<uint32_t>(handle);
|
||||
root_entry->name_ = root_path;
|
||||
root_entry->absolute_path_ = root_path;
|
||||
root_entry_ = std::unique_ptr<Entry>(root_entry);
|
||||
result = ReadAllEntries(reader, "", root_entry, nullptr);
|
||||
|
||||
return result;
|
||||
return ReadAllEntries("", root_entry, nullptr);
|
||||
}
|
||||
|
||||
void DiscZarchiveDevice::Dump(StringBuffer* string_buffer) {
|
||||
@@ -75,12 +57,11 @@ Entry* DiscZarchiveDevice::ResolvePath(const std::string_view path) {
|
||||
// some\PATH.foo
|
||||
XELOGFS("DiscZarchiveDevice::ResolvePath({})", path);
|
||||
|
||||
ZArchiveReader* reader = static_cast<ZArchiveReader*>(opaque_);
|
||||
if (!reader) {
|
||||
if (!reader_) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ZArchiveNodeHandle handle = reader->LookUp(path);
|
||||
const ZArchiveNodeHandle handle = reader_->LookUp(path);
|
||||
if (handle == ZARCHIVE_INVALID_NODE) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -88,18 +69,17 @@ Entry* DiscZarchiveDevice::ResolvePath(const std::string_view path) {
|
||||
return root_entry_->ResolvePath(path);
|
||||
}
|
||||
|
||||
bool DiscZarchiveDevice::ReadAllEntries(void* opaque, const std::string& path,
|
||||
bool DiscZarchiveDevice::ReadAllEntries(const std::string& path,
|
||||
DiscZarchiveEntry* node,
|
||||
DiscZarchiveEntry* parent) {
|
||||
ZArchiveReader* reader = static_cast<ZArchiveReader*>(opaque);
|
||||
ZArchiveNodeHandle handle = node->handle_;
|
||||
const ZArchiveNodeHandle handle = node->handle_;
|
||||
|
||||
if (handle == ZARCHIVE_INVALID_NODE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (reader->IsFile(handle)) {
|
||||
auto entry = new DiscZarchiveEntry(this, parent, path, opaque);
|
||||
if (reader_->IsFile(handle)) {
|
||||
auto entry = new DiscZarchiveEntry(this, parent, path);
|
||||
entry->attributes_ = kFileAttributeReadOnly;
|
||||
entry->handle_ = static_cast<uint32_t>(handle);
|
||||
entry->parent_ = parent;
|
||||
@@ -107,23 +87,23 @@ bool DiscZarchiveDevice::ReadAllEntries(void* opaque, const std::string& path,
|
||||
return true;
|
||||
}
|
||||
|
||||
if (reader->IsDirectory(handle)) {
|
||||
const uint32_t count = reader->GetDirEntryCount(handle);
|
||||
if (reader_->IsDirectory(handle)) {
|
||||
const uint32_t count = reader_->GetDirEntryCount(handle);
|
||||
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
ZArchiveReader::DirEntry dirEntry;
|
||||
if (!reader->GetDirEntry(handle, i, dirEntry)) {
|
||||
if (!reader_->GetDirEntry(handle, i, dirEntry)) {
|
||||
XELOGE("Invalid ZArchive directory! Skipping loading");
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string full_path = path + std::string(dirEntry.name);
|
||||
ZArchiveNodeHandle fileHandle = reader->LookUp(full_path);
|
||||
if (handle == ZARCHIVE_INVALID_NODE) {
|
||||
const ZArchiveNodeHandle fileHandle = reader_->LookUp(full_path);
|
||||
if (fileHandle == ZARCHIVE_INVALID_NODE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto entry = new DiscZarchiveEntry(this, parent, full_path, opaque);
|
||||
auto entry = new DiscZarchiveEntry(this, parent, full_path);
|
||||
entry->handle_ = static_cast<uint32_t>(fileHandle);
|
||||
entry->data_offset_ = 0;
|
||||
|
||||
@@ -133,17 +113,16 @@ bool DiscZarchiveDevice::ReadAllEntries(void* opaque, const std::string& path,
|
||||
entry->write_timestamp_ = 10000 * 11644473600000LL;
|
||||
entry->parent_ = node;
|
||||
|
||||
|
||||
if (dirEntry.isDirectory) {
|
||||
entry->data_size_ = 0;
|
||||
entry->size_ = dirEntry.size;
|
||||
entry->attributes_ = kFileAttributeDirectory | kFileAttributeReadOnly;
|
||||
node->children_.push_back(std::unique_ptr<Entry>(entry));
|
||||
if (!ReadAllEntries(reader, full_path + "\\", entry, node)) {
|
||||
if (!ReadAllEntries(full_path + "\\", entry, node)) {
|
||||
return false;
|
||||
}
|
||||
} else if (dirEntry.isFile) {
|
||||
entry->data_size_ = entry->size_ = reader->GetFileSize(fileHandle);
|
||||
entry->data_size_ = entry->size_ = reader_->GetFileSize(fileHandle);
|
||||
entry->attributes_ = kFileAttributeReadOnly;
|
||||
entry->allocation_size_ =
|
||||
xe::round_up(entry->size_, bytes_per_sector());
|
||||
|
||||
Reference in New Issue
Block a user