diff --git a/src/xenia/vfs/devices/disc_image_device.cc b/src/xenia/vfs/devices/disc_image_device.cc index 1f5663c58..2b5a49855 100644 --- a/src/xenia/vfs/devices/disc_image_device.cc +++ b/src/xenia/vfs/devices/disc_image_device.cc @@ -118,8 +118,8 @@ bool DiscImageDevice::ReadEntry(ParseState* state, const uint8_t* buffer, return false; } - auto entry = new DiscImageEntry(this, parent, std::string(name, name_length), - mmap_.get()); + auto entry = DiscImageEntry::Create( + this, parent, std::string(name, name_length), mmap_.get()); entry->attributes_ = attributes | kFileAttributeReadOnly; entry->size_ = length; entry->allocation_size_ = xe::round_up(length, bytes_per_sector()); @@ -127,9 +127,6 @@ bool DiscImageDevice::ReadEntry(ParseState* state, const uint8_t* buffer, entry->access_timestamp_ = 0; entry->write_timestamp_ = 0; - // Add to parent. - parent->children_.emplace_back(std::unique_ptr(entry)); - if (attributes & kFileAttributeDirectory) { // Folder. entry->data_offset_ = 0; @@ -143,7 +140,7 @@ bool DiscImageDevice::ReadEntry(ParseState* state, const uint8_t* buffer, // Read child list. uint8_t* folder_ptr = state->ptr + state->game_offset + (sector * kXESectorSize); - if (!ReadEntry(state, folder_ptr, 0, entry)) { + if (!ReadEntry(state, folder_ptr, 0, entry.get())) { return false; } } @@ -153,6 +150,9 @@ bool DiscImageDevice::ReadEntry(ParseState* state, const uint8_t* buffer, entry->data_size_ = length; } + // Add to parent. + parent->children_.emplace_back(std::move(entry)); + // Read next file in the list. if (node_r && !ReadEntry(state, buffer, node_r, parent)) { return false; diff --git a/src/xenia/vfs/devices/disc_image_entry.cc b/src/xenia/vfs/devices/disc_image_entry.cc index 552a34f7d..5997c0875 100644 --- a/src/xenia/vfs/devices/disc_image_entry.cc +++ b/src/xenia/vfs/devices/disc_image_entry.cc @@ -26,6 +26,16 @@ DiscImageEntry::DiscImageEntry(Device* device, Entry* parent, std::string path, DiscImageEntry::~DiscImageEntry() = default; +std::unique_ptr DiscImageEntry::Create(Device* device, + Entry* parent, + std::string name, + MappedMemory* mmap) { + auto path = xe::join_paths(parent->path(), name); + auto entry = std::make_unique(device, parent, path, mmap); + + return std::move(entry); +} + X_STATUS DiscImageEntry::Open(uint32_t desired_access, File** out_file) { *out_file = new DiscImageFile(desired_access, this); return X_STATUS_SUCCESS; diff --git a/src/xenia/vfs/devices/disc_image_entry.h b/src/xenia/vfs/devices/disc_image_entry.h index c2e83e43f..99de02706 100644 --- a/src/xenia/vfs/devices/disc_image_entry.h +++ b/src/xenia/vfs/devices/disc_image_entry.h @@ -28,6 +28,10 @@ class DiscImageEntry : public Entry { MappedMemory* mmap); ~DiscImageEntry() override; + static std::unique_ptr Create(Device* device, Entry* parent, + std::string name, + MappedMemory* mmap); + MappedMemory* mmap() const { return mmap_; } size_t data_offset() const { return data_offset_; } size_t data_size() const { return data_size_; } diff --git a/src/xenia/vfs/devices/host_path_entry.cc b/src/xenia/vfs/devices/host_path_entry.cc index d704a3be2..3d0ce2057 100644 --- a/src/xenia/vfs/devices/host_path_entry.cc +++ b/src/xenia/vfs/devices/host_path_entry.cc @@ -29,8 +29,9 @@ HostPathEntry::~HostPathEntry() = default; HostPathEntry* HostPathEntry::Create(Device* device, Entry* parent, const std::wstring& full_path, xe::filesystem::FileInfo file_info) { - auto entry = new HostPathEntry(device, parent, xe::to_string(file_info.name), - full_path); + auto path = xe::join_paths(parent->path(), xe::to_string(file_info.name)); + auto entry = new HostPathEntry(device, parent, path, full_path); + entry->create_timestamp_ = file_info.create_timestamp; entry->access_timestamp_ = file_info.access_timestamp; entry->write_timestamp_ = file_info.write_timestamp; diff --git a/src/xenia/vfs/devices/stfs_container_device.cc b/src/xenia/vfs/devices/stfs_container_device.cc index c0cf1943c..0e4c80682 100644 --- a/src/xenia/vfs/devices/stfs_container_device.cc +++ b/src/xenia/vfs/devices/stfs_container_device.cc @@ -168,7 +168,7 @@ StfsContainerDevice::Error StfsContainerDevice::ReadAllEntries( parent_entry = all_entries[path_indicator]; } - auto entry = new StfsContainerEntry( + auto entry = StfsContainerEntry::Create( this, parent_entry, std::string(reinterpret_cast(filename), filename_length_flags & 0x3F), @@ -187,7 +187,7 @@ StfsContainerDevice::Error StfsContainerDevice::ReadAllEntries( entry->create_timestamp_ = update_timestamp; entry->access_timestamp_ = access_timestamp; entry->write_timestamp_ = update_timestamp; - all_entries.push_back(entry); + all_entries.push_back(entry.get()); // Fill in all block records. // It's easier to do this now and just look them up later, at the cost @@ -212,7 +212,7 @@ StfsContainerDevice::Error StfsContainerDevice::ReadAllEntries( } } - parent_entry->children_.emplace_back(std::unique_ptr(entry)); + parent_entry->children_.emplace_back(std::move(entry)); } auto block_hash = GetBlockHash(map_ptr, table_block_index, 0); diff --git a/src/xenia/vfs/devices/stfs_container_entry.cc b/src/xenia/vfs/devices/stfs_container_entry.cc index 79b8756da..71c2440ba 100644 --- a/src/xenia/vfs/devices/stfs_container_entry.cc +++ b/src/xenia/vfs/devices/stfs_container_entry.cc @@ -24,6 +24,14 @@ StfsContainerEntry::StfsContainerEntry(Device* device, Entry* parent, StfsContainerEntry::~StfsContainerEntry() = default; +std::unique_ptr StfsContainerEntry::Create( + Device* device, Entry* parent, std::string name, MappedMemory* mmap) { + auto path = xe::join_paths(parent->path(), name); + auto entry = std::make_unique(device, parent, path, mmap); + + return std::move(entry); +} + X_STATUS StfsContainerEntry::Open(uint32_t desired_access, File** out_file) { *out_file = new StfsContainerFile(desired_access, this); return X_STATUS_SUCCESS; diff --git a/src/xenia/vfs/devices/stfs_container_entry.h b/src/xenia/vfs/devices/stfs_container_entry.h index 2ab2d9dae..279c83523 100644 --- a/src/xenia/vfs/devices/stfs_container_entry.h +++ b/src/xenia/vfs/devices/stfs_container_entry.h @@ -29,6 +29,11 @@ class StfsContainerEntry : public Entry { MappedMemory* mmap); ~StfsContainerEntry() override; + static std::unique_ptr Create(Device* device, + Entry* parent, + std::string name, + MappedMemory* mmap); + MappedMemory* mmap() const { return mmap_; } size_t data_offset() const { return data_offset_; } size_t data_size() const { return data_size_; }