[Emulator] Updated "Install Content" function to match PR status
This commit is contained in:
parent
f19cb704aa
commit
469d062a50
|
@ -368,90 +368,19 @@ X_STATUS Emulator::InstallContentPackage(const std::filesystem::path& path) {
|
||||||
|
|
||||||
std::filesystem::path installation_path =
|
std::filesystem::path installation_path =
|
||||||
content_root() / fmt::format("{:08X}", device->title_id()) /
|
content_root() / fmt::format("{:08X}", device->title_id()) /
|
||||||
fmt::format("{:08X}", device->content_type());
|
fmt::format("{:08X}", device->content_type()) / path.filename();
|
||||||
|
|
||||||
if (std::filesystem::exists(installation_path / path.filename())) {
|
if (std::filesystem::exists(installation_path)) {
|
||||||
// TODO: Popup
|
// TODO(Gliniak): Popup
|
||||||
// Do you want to overwrite already existing data?
|
// Do you want to overwrite already existing data?
|
||||||
} else {
|
} else {
|
||||||
std::error_code error_code;
|
std::error_code error_code;
|
||||||
std::filesystem::create_directories(installation_path / path.filename(),
|
std::filesystem::create_directories(installation_path, error_code);
|
||||||
error_code);
|
|
||||||
if (error_code) {
|
if (error_code) {
|
||||||
return error_code.value();
|
return error_code.value();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return vfs::VirtualFileSystem::ExtractFiles(device.get(), installation_path);
|
||||||
// Run through all the files, breadth-first style.
|
|
||||||
std::queue<vfs::Entry*> queue;
|
|
||||||
auto root = device->ResolvePath("/");
|
|
||||||
queue.push(root);
|
|
||||||
|
|
||||||
// Allocate a buffer when needed.
|
|
||||||
size_t buffer_size = 0;
|
|
||||||
uint8_t* buffer = nullptr;
|
|
||||||
|
|
||||||
while (!queue.empty()) {
|
|
||||||
auto entry = queue.front();
|
|
||||||
queue.pop();
|
|
||||||
for (auto& entry : entry->children()) {
|
|
||||||
queue.push(entry.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
auto dest_name =
|
|
||||||
installation_path / path.filename() / xe::to_path(entry->path());
|
|
||||||
if (entry->attributes() & vfs::kFileAttributeDirectory) {
|
|
||||||
std::error_code error_code;
|
|
||||||
std::filesystem::create_directories(dest_name, error_code);
|
|
||||||
if (error_code) {
|
|
||||||
return error_code.value();
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
vfs::File* in_file = nullptr;
|
|
||||||
if (entry->Open(vfs::FileAccess::kFileReadData, &in_file) !=
|
|
||||||
X_STATUS_SUCCESS) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto file = xe::filesystem::OpenFile(dest_name, "wb");
|
|
||||||
if (!file) {
|
|
||||||
in_file->Destroy();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entry->can_map()) {
|
|
||||||
auto map = entry->OpenMapped(xe::MappedMemory::Mode::kRead);
|
|
||||||
fwrite(map->data(), map->size(), 1, file);
|
|
||||||
map->Close();
|
|
||||||
} else {
|
|
||||||
// Can't map the file into memory. Read it into a temporary buffer.
|
|
||||||
if (!buffer || entry->size() > buffer_size) {
|
|
||||||
// Resize the buffer.
|
|
||||||
if (buffer) {
|
|
||||||
delete[] buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a buffer rounded up to the nearest 512MB.
|
|
||||||
buffer_size = xe::round_up(entry->size(), 512_MiB);
|
|
||||||
buffer = new uint8_t[buffer_size];
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t bytes_read = 0;
|
|
||||||
in_file->ReadSync(buffer, entry->size(), 0, &bytes_read);
|
|
||||||
fwrite(buffer, bytes_read, 1, file);
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
in_file->Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffer) {
|
|
||||||
delete[] buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
return X_STATUS_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Emulator::Pause() {
|
void Emulator::Pause() {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* Xenia : Xbox 360 Emulator Research Project *
|
* Xenia : Xbox 360 Emulator Research Project *
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* Copyright 2021 Ben Vanik. All rights reserved. *
|
* Copyright 2022 Ben Vanik. All rights reserved. *
|
||||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
@ -19,12 +19,11 @@
|
||||||
|
|
||||||
#include "xenia/vfs/devices/stfs_container_device.h"
|
#include "xenia/vfs/devices/stfs_container_device.h"
|
||||||
#include "xenia/vfs/file.h"
|
#include "xenia/vfs/file.h"
|
||||||
|
#include "xenia/vfs/virtual_file_system.h"
|
||||||
|
|
||||||
namespace xe {
|
namespace xe {
|
||||||
namespace vfs {
|
namespace vfs {
|
||||||
|
|
||||||
using namespace xe::literals;
|
|
||||||
|
|
||||||
DEFINE_transient_path(source, "", "Specifies the file to dump from.",
|
DEFINE_transient_path(source, "", "Specifies the file to dump from.",
|
||||||
"General");
|
"General");
|
||||||
|
|
||||||
|
@ -46,72 +45,7 @@ int vfs_dump_main(const std::vector<std::string>& args) {
|
||||||
XELOGE("Failed to initialize device");
|
XELOGE("Failed to initialize device");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
return VirtualFileSystem::ExtractFiles(device.get(), base_path);
|
||||||
// Run through all the files, breadth-first style.
|
|
||||||
std::queue<vfs::Entry*> queue;
|
|
||||||
auto root = device->ResolvePath("/");
|
|
||||||
queue.push(root);
|
|
||||||
|
|
||||||
// Allocate a buffer when needed.
|
|
||||||
size_t buffer_size = 0;
|
|
||||||
uint8_t* buffer = nullptr;
|
|
||||||
|
|
||||||
while (!queue.empty()) {
|
|
||||||
auto entry = queue.front();
|
|
||||||
queue.pop();
|
|
||||||
for (auto& entry : entry->children()) {
|
|
||||||
queue.push(entry.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
XELOGI("{}", entry->path());
|
|
||||||
auto dest_name = base_path / xe::to_path(entry->path());
|
|
||||||
if (entry->attributes() & kFileAttributeDirectory) {
|
|
||||||
std::filesystem::create_directories(dest_name);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
vfs::File* in_file = nullptr;
|
|
||||||
if (entry->Open(FileAccess::kFileReadData, &in_file) != X_STATUS_SUCCESS) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto file = xe::filesystem::OpenFile(dest_name, "wb");
|
|
||||||
if (!file) {
|
|
||||||
in_file->Destroy();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entry->can_map()) {
|
|
||||||
auto map = entry->OpenMapped(xe::MappedMemory::Mode::kRead);
|
|
||||||
fwrite(map->data(), map->size(), 1, file);
|
|
||||||
map->Close();
|
|
||||||
} else {
|
|
||||||
// Can't map the file into memory. Read it into a temporary buffer.
|
|
||||||
if (!buffer || entry->size() > buffer_size) {
|
|
||||||
// Resize the buffer.
|
|
||||||
if (buffer) {
|
|
||||||
delete[] buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate a buffer rounded up to the nearest 512MB.
|
|
||||||
buffer_size = xe::round_up(entry->size(), 512_MiB);
|
|
||||||
buffer = new uint8_t[buffer_size];
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t bytes_read = 0;
|
|
||||||
in_file->ReadSync(buffer, entry->size(), 0, &bytes_read);
|
|
||||||
fwrite(buffer, bytes_read, 1, file);
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(file);
|
|
||||||
in_file->Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffer) {
|
|
||||||
delete[] buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace vfs
|
} // namespace vfs
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include "xenia/vfs/virtual_file_system.h"
|
#include "xenia/vfs/virtual_file_system.h"
|
||||||
|
|
||||||
|
#include "xenia/base/literals.h"
|
||||||
#include "xenia/base/logging.h"
|
#include "xenia/base/logging.h"
|
||||||
#include "xenia/base/string.h"
|
#include "xenia/base/string.h"
|
||||||
#include "xenia/kernel/xfile.h"
|
#include "xenia/kernel/xfile.h"
|
||||||
|
@ -16,6 +17,8 @@
|
||||||
namespace xe {
|
namespace xe {
|
||||||
namespace vfs {
|
namespace vfs {
|
||||||
|
|
||||||
|
using namespace xe::literals;
|
||||||
|
|
||||||
VirtualFileSystem::VirtualFileSystem() {}
|
VirtualFileSystem::VirtualFileSystem() {}
|
||||||
|
|
||||||
VirtualFileSystem::~VirtualFileSystem() {
|
VirtualFileSystem::~VirtualFileSystem() {
|
||||||
|
@ -307,5 +310,77 @@ X_STATUS VirtualFileSystem::OpenFile(Entry* root_entry,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
X_STATUS VirtualFileSystem::ExtractFiles(Device* device,
|
||||||
|
std::filesystem::path base_path) {
|
||||||
|
// Run through all the files, breadth-first style.
|
||||||
|
std::queue<vfs::Entry*> queue;
|
||||||
|
auto root = device->ResolvePath("/");
|
||||||
|
queue.push(root);
|
||||||
|
|
||||||
|
// Allocate a buffer when needed.
|
||||||
|
size_t buffer_size = 0;
|
||||||
|
uint8_t* buffer = nullptr;
|
||||||
|
|
||||||
|
while (!queue.empty()) {
|
||||||
|
auto entry = queue.front();
|
||||||
|
queue.pop();
|
||||||
|
for (auto& entry : entry->children()) {
|
||||||
|
queue.push(entry.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
XELOGI("Extracting file: {}", entry->path());
|
||||||
|
auto dest_name = base_path / xe::to_path(entry->path());
|
||||||
|
if (entry->attributes() & kFileAttributeDirectory) {
|
||||||
|
std::error_code error_code;
|
||||||
|
std::filesystem::create_directories(dest_name, error_code);
|
||||||
|
if (error_code) {
|
||||||
|
return error_code.value();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
vfs::File* in_file = nullptr;
|
||||||
|
if (entry->Open(FileAccess::kFileReadData, &in_file) != X_STATUS_SUCCESS) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto file = xe::filesystem::OpenFile(dest_name, "wb");
|
||||||
|
if (!file) {
|
||||||
|
in_file->Destroy();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entry->can_map()) {
|
||||||
|
auto map = entry->OpenMapped(xe::MappedMemory::Mode::kRead);
|
||||||
|
fwrite(map->data(), map->size(), 1, file);
|
||||||
|
map->Close();
|
||||||
|
} else {
|
||||||
|
// Can't map the file into memory. Read it into a temporary buffer.
|
||||||
|
if (!buffer || entry->size() > buffer_size) {
|
||||||
|
// Resize the buffer.
|
||||||
|
if (buffer) {
|
||||||
|
delete[] buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate a buffer rounded up to the nearest 512MB.
|
||||||
|
buffer_size = xe::round_up(entry->size(), 512_MiB);
|
||||||
|
buffer = new uint8_t[buffer_size];
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t bytes_read = 0;
|
||||||
|
in_file->ReadSync(buffer, entry->size(), 0, &bytes_read);
|
||||||
|
fwrite(buffer, bytes_read, 1, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
in_file->Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer) {
|
||||||
|
delete[] buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
return X_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
} // namespace vfs
|
} // namespace vfs
|
||||||
} // namespace xe
|
} // namespace xe
|
||||||
|
|
|
@ -47,6 +47,7 @@ class VirtualFileSystem {
|
||||||
bool is_non_directory, File** out_file,
|
bool is_non_directory, File** out_file,
|
||||||
FileAction* out_action);
|
FileAction* out_action);
|
||||||
|
|
||||||
|
static X_STATUS ExtractFiles(Device* device, std::filesystem::path base_path);
|
||||||
private:
|
private:
|
||||||
xe::global_critical_region global_critical_region_;
|
xe::global_critical_region global_critical_region_;
|
||||||
std::vector<std::unique_ptr<Device>> devices_;
|
std::vector<std::unique_ptr<Device>> devices_;
|
||||||
|
|
Loading…
Reference in New Issue