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