Removing utilities (that were just adding needless layers).
Progress on #294.
This commit is contained in:
@@ -12,9 +12,6 @@
|
||||
#include "xenia/base/filesystem.h"
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/string.h"
|
||||
#include "xenia/vfs/devices/disc_image_device.h"
|
||||
#include "xenia/vfs/devices/host_path_device.h"
|
||||
#include "xenia/vfs/devices/stfs_container_device.h"
|
||||
|
||||
namespace xe {
|
||||
namespace vfs {
|
||||
@@ -24,128 +21,28 @@ VirtualFileSystem::VirtualFileSystem() {}
|
||||
VirtualFileSystem::~VirtualFileSystem() {
|
||||
// Delete all devices.
|
||||
// This will explode if anyone is still using data from them.
|
||||
for (std::vector<Device*>::iterator it = devices_.begin();
|
||||
it != devices_.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
devices_.clear();
|
||||
symlinks_.clear();
|
||||
}
|
||||
|
||||
FileSystemType VirtualFileSystem::InferType(const std::wstring& local_path) {
|
||||
auto last_slash = local_path.find_last_of(xe::path_separator);
|
||||
auto last_dot = local_path.find_last_of('.');
|
||||
if (last_dot < last_slash) {
|
||||
last_dot = std::wstring::npos;
|
||||
}
|
||||
if (last_dot == std::wstring::npos) {
|
||||
// Likely an STFS container.
|
||||
return FileSystemType::STFS_TITLE;
|
||||
} else if (local_path.substr(last_dot) == L".xex") {
|
||||
// Treat as a naked xex file.
|
||||
return FileSystemType::XEX_FILE;
|
||||
} else {
|
||||
// Assume a disc image.
|
||||
return FileSystemType::DISC_IMAGE;
|
||||
}
|
||||
bool VirtualFileSystem::RegisterDevice(std::unique_ptr<Device> device) {
|
||||
devices_.emplace_back(std::move(device));
|
||||
return true;
|
||||
}
|
||||
|
||||
int VirtualFileSystem::InitializeFromPath(FileSystemType type,
|
||||
const std::wstring& local_path) {
|
||||
switch (type) {
|
||||
case FileSystemType::STFS_TITLE: {
|
||||
// Register the container in the virtual filesystem.
|
||||
int result_code =
|
||||
RegisterSTFSContainerDevice("\\Device\\Cdrom0", local_path);
|
||||
if (result_code) {
|
||||
XELOGE("Unable to mount STFS container");
|
||||
return result_code;
|
||||
}
|
||||
|
||||
// TODO(benvanik): figure out paths.
|
||||
// Create symlinks to the device.
|
||||
CreateSymbolicLink("game:", "\\Device\\Cdrom0");
|
||||
CreateSymbolicLink("d:", "\\Device\\Cdrom0");
|
||||
break;
|
||||
}
|
||||
case FileSystemType::XEX_FILE: {
|
||||
// Get the parent path of the file.
|
||||
auto last_slash = local_path.find_last_of(xe::path_separator);
|
||||
std::wstring parent_path = local_path.substr(0, last_slash);
|
||||
|
||||
// Register the local directory in the virtual filesystem.
|
||||
int result_code = RegisterHostPathDevice(
|
||||
"\\Device\\Harddisk0\\Partition0", parent_path, true);
|
||||
if (result_code) {
|
||||
XELOGE("Unable to mount local directory");
|
||||
return result_code;
|
||||
}
|
||||
|
||||
// Create symlinks to the device.
|
||||
CreateSymbolicLink("game:", "\\Device\\Harddisk0\\Partition0");
|
||||
CreateSymbolicLink("d:", "\\Device\\Harddisk0\\Partition0");
|
||||
break;
|
||||
}
|
||||
case FileSystemType::DISC_IMAGE: {
|
||||
// Register the disc image in the virtual filesystem.
|
||||
int result_code = RegisterDiscImageDevice("\\Device\\Cdrom0", local_path);
|
||||
if (result_code) {
|
||||
XELOGE("Unable to mount disc image");
|
||||
return result_code;
|
||||
}
|
||||
|
||||
// Create symlinks to the device.
|
||||
CreateSymbolicLink("game:", "\\Device\\Cdrom0");
|
||||
CreateSymbolicLink("d:", "\\Device\\Cdrom0");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VirtualFileSystem::RegisterDevice(const std::string& path, Device* device) {
|
||||
devices_.push_back(device);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VirtualFileSystem::RegisterHostPathDevice(const std::string& path,
|
||||
const std::wstring& local_path,
|
||||
bool read_only) {
|
||||
Device* device = new HostPathDevice(path, local_path, read_only);
|
||||
return RegisterDevice(path, device);
|
||||
}
|
||||
|
||||
int VirtualFileSystem::RegisterDiscImageDevice(const std::string& path,
|
||||
const std::wstring& local_path) {
|
||||
DiscImageDevice* device = new DiscImageDevice(path, local_path);
|
||||
if (device->Init()) {
|
||||
return 1;
|
||||
}
|
||||
return RegisterDevice(path, device);
|
||||
}
|
||||
|
||||
int VirtualFileSystem::RegisterSTFSContainerDevice(
|
||||
const std::string& path, const std::wstring& local_path) {
|
||||
STFSContainerDevice* device = new STFSContainerDevice(path, local_path);
|
||||
if (device->Init()) {
|
||||
return 1;
|
||||
}
|
||||
return RegisterDevice(path, device);
|
||||
}
|
||||
|
||||
int VirtualFileSystem::CreateSymbolicLink(const std::string& path,
|
||||
const std::string& target) {
|
||||
bool VirtualFileSystem::RegisterSymbolicLink(std::string path,
|
||||
std::string target) {
|
||||
symlinks_.insert({path, target});
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
int VirtualFileSystem::DeleteSymbolicLink(const std::string& path) {
|
||||
bool VirtualFileSystem::UnregisterSymbolicLink(std::string path) {
|
||||
auto& it = symlinks_.find(path);
|
||||
if (it == symlinks_.end()) {
|
||||
return 1;
|
||||
return false;
|
||||
}
|
||||
symlinks_.erase(it);
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<Entry> VirtualFileSystem::ResolvePath(const std::string& path) {
|
||||
@@ -167,8 +64,8 @@ std::unique_ptr<Entry> VirtualFileSystem::ResolvePath(const std::string& path) {
|
||||
// Not to fret, check to see if the path is fully qualified.
|
||||
if (device_path.empty()) {
|
||||
for (auto& device : devices_) {
|
||||
if (xe::find_first_of_case(normalized_path, device->path()) == 0) {
|
||||
device_path = device->path();
|
||||
if (xe::find_first_of_case(normalized_path, device->mount_path()) == 0) {
|
||||
device_path = device->mount_path();
|
||||
relative_path = normalized_path.substr(device_path.size());
|
||||
}
|
||||
}
|
||||
@@ -181,7 +78,7 @@ std::unique_ptr<Entry> VirtualFileSystem::ResolvePath(const std::string& path) {
|
||||
|
||||
// Scan all devices.
|
||||
for (auto& device : devices_) {
|
||||
if (strcasecmp(device_path.c_str(), device->path().c_str()) == 0) {
|
||||
if (strcasecmp(device_path.c_str(), device->mount_path().c_str()) == 0) {
|
||||
return device->ResolvePath(relative_path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user