[VFS] Zarchive cleanup & style changes
This commit is contained in:
parent
18daf4a686
commit
9496c04ac5
|
@ -32,12 +32,13 @@ DiscZarchiveDevice::DiscZarchiveDevice(const std::string_view mount_path,
|
|||
|
||||
DiscZarchiveDevice::~DiscZarchiveDevice() {
|
||||
ZArchiveReader* reader = static_cast<ZArchiveReader*>(opaque_);
|
||||
if (reader != nullptr) delete reader;
|
||||
if (reader != nullptr) {
|
||||
delete reader;
|
||||
}
|
||||
};
|
||||
|
||||
bool DiscZarchiveDevice::Initialize() {
|
||||
ZArchiveReader* reader = nullptr;
|
||||
reader = ZArchiveReader::OpenFromFile(host_path_);
|
||||
ZArchiveReader* reader = ZArchiveReader::OpenFromFile(host_path_);
|
||||
|
||||
if (!reader) {
|
||||
XELOGE("Disc ZArchive could not be opened");
|
||||
|
@ -45,10 +46,10 @@ bool DiscZarchiveDevice::Initialize() {
|
|||
}
|
||||
|
||||
opaque_ = static_cast<void*>(reader);
|
||||
bool result = false;
|
||||
|
||||
result = reader->IsFile(reader->LookUp("default.xex", true, false));
|
||||
if (!result) XELOGE("Failed to verify disc ZArchive (no default.xex)");
|
||||
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);
|
||||
|
@ -75,12 +76,14 @@ Entry* DiscZarchiveDevice::ResolvePath(const std::string_view path) {
|
|||
XELOGFS("DiscZarchiveDevice::ResolvePath({})", path);
|
||||
|
||||
ZArchiveReader* reader = static_cast<ZArchiveReader*>(opaque_);
|
||||
if (!reader) return nullptr;
|
||||
if (!reader) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ZArchiveNodeHandle handle = reader->LookUp(path);
|
||||
bool result = (handle != ZARCHIVE_INVALID_NODE);
|
||||
|
||||
if (!result) return nullptr;
|
||||
if (handle == ZARCHIVE_INVALID_NODE) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return root_entry_->ResolvePath(path);
|
||||
}
|
||||
|
@ -90,30 +93,55 @@ bool DiscZarchiveDevice::ReadAllEntries(void* opaque, const std::string& path,
|
|||
DiscZarchiveEntry* parent) {
|
||||
ZArchiveReader* reader = static_cast<ZArchiveReader*>(opaque);
|
||||
ZArchiveNodeHandle handle = node->handle_;
|
||||
if (handle == ZARCHIVE_INVALID_NODE) return false;
|
||||
|
||||
if (handle == ZARCHIVE_INVALID_NODE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (reader->IsFile(handle)) {
|
||||
auto entry = new DiscZarchiveEntry(this, parent, path, opaque);
|
||||
entry->attributes_ = kFileAttributeReadOnly;
|
||||
entry->handle_ = static_cast<uint32_t>(handle);
|
||||
entry->parent_ = parent;
|
||||
entry->children_.push_back(std::unique_ptr<Entry>(entry));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (reader->IsDirectory(handle)) {
|
||||
uint32_t count = reader->GetDirEntryCount(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)) return false;
|
||||
std::string full_path = path + std::string(dirEntry.name);
|
||||
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) return false;
|
||||
if (handle == ZARCHIVE_INVALID_NODE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto entry = new DiscZarchiveEntry(this, parent, full_path, opaque);
|
||||
entry->handle_ = static_cast<uint32_t>(fileHandle);
|
||||
entry->data_offset_ = 0;
|
||||
|
||||
// Set to January 1, 1970 (UTC) in 100-nanosecond intervals
|
||||
entry->create_timestamp_ = 10000 * 11644473600000LL;
|
||||
entry->access_timestamp_ = 10000 * 11644473600000LL;
|
||||
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(reader, full_path + "\\", entry, node)) {
|
||||
return false;
|
||||
}
|
||||
} else if (dirEntry.isFile) {
|
||||
entry->data_size_ = entry->size_ = reader->GetFileSize(fileHandle);
|
||||
entry->attributes_ = kFileAttributeReadOnly;
|
||||
|
@ -123,13 +151,6 @@ bool DiscZarchiveDevice::ReadAllEntries(void* opaque, const std::string& path,
|
|||
}
|
||||
}
|
||||
return true;
|
||||
} else if (reader->IsFile(handle)) {
|
||||
auto entry = new DiscZarchiveEntry(this, parent, path, opaque);
|
||||
entry->attributes_ = kFileAttributeReadOnly;
|
||||
entry->handle_ = static_cast<uint32_t>(handle);
|
||||
entry->parent_ = parent;
|
||||
entry->children_.push_back(std::unique_ptr<Entry>(entry));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -33,10 +33,9 @@ X_STATUS DiscZarchiveFile::ReadSync(void* buffer, size_t buffer_length,
|
|||
return X_STATUS_END_OF_FILE;
|
||||
}
|
||||
ZArchiveReader* reader = static_cast<ZArchiveReader*>(entry_->opaque_);
|
||||
uint64_t bytes_read =
|
||||
const uint64_t bytes_read =
|
||||
reader->ReadFromFile(entry_->handle_, byte_offset, buffer_length, buffer);
|
||||
size_t real_offset = entry_->data_offset() + byte_offset;
|
||||
size_t real_length =
|
||||
const size_t real_length =
|
||||
std::min(buffer_length, entry_->data_size() - byte_offset);
|
||||
*out_bytes_read = real_length;
|
||||
return X_STATUS_SUCCESS;
|
||||
|
|
Loading…
Reference in New Issue