Working on switching to std::string.
This commit is contained in:
@@ -15,6 +15,4 @@ using namespace xe::kernel::fs;
|
||||
|
||||
Device::Device(const std::string& path) : path_(path) {}
|
||||
|
||||
Device::~Device() {}
|
||||
|
||||
const char* Device::path() const { return path_.c_str(); }
|
||||
Device::~Device() = default;
|
||||
|
||||
@@ -26,7 +26,7 @@ class Device {
|
||||
Device(const std::string& path);
|
||||
virtual ~Device();
|
||||
|
||||
const char* path() const;
|
||||
const std::string& path() const { return path_; }
|
||||
|
||||
virtual Entry* ResolvePath(const char* path) = 0;
|
||||
|
||||
|
||||
@@ -29,15 +29,15 @@ DiscImageFile::DiscImageFile(
|
||||
DiscImageFile::~DiscImageFile() {
|
||||
}
|
||||
|
||||
const char* DiscImageFile::path(void) const {
|
||||
const std::string& DiscImageFile::path() const {
|
||||
return entry_->path();
|
||||
}
|
||||
|
||||
const char* DiscImageFile::absolute_path(void) const {
|
||||
const std::string& DiscImageFile::absolute_path() const {
|
||||
return entry_->absolute_path();
|
||||
}
|
||||
|
||||
const char* DiscImageFile::name(void) const {
|
||||
const std::string& DiscImageFile::name() const {
|
||||
return entry_->name();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,43 +15,39 @@
|
||||
|
||||
#include <xenia/kernel/objects/xfile.h>
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace kernel {
|
||||
namespace fs {
|
||||
|
||||
class DiscImageEntry;
|
||||
|
||||
|
||||
class DiscImageFile : public XFile {
|
||||
public:
|
||||
public:
|
||||
DiscImageFile(KernelState* kernel_state, uint32_t desired_access,
|
||||
DiscImageEntry* entry);
|
||||
virtual ~DiscImageFile();
|
||||
~DiscImageFile() override;
|
||||
|
||||
virtual const char* path(void) const;
|
||||
virtual const char* absolute_path(void) const;
|
||||
virtual const char* name(void) const;
|
||||
const std::string& path() const override;
|
||||
const std::string& absolute_path() const override;
|
||||
const std::string& name() const override;
|
||||
|
||||
virtual X_STATUS QueryInfo(XFileInfo* out_info);
|
||||
virtual X_STATUS QueryDirectory(XDirectoryInfo* out_info,
|
||||
size_t length, const char* file_name, bool restart);
|
||||
virtual X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length);
|
||||
virtual X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info, size_t length);
|
||||
X_STATUS QueryInfo(XFileInfo* out_info) override;
|
||||
X_STATUS QueryDirectory(XDirectoryInfo* out_info, size_t length,
|
||||
const char* file_name, bool restart) override;
|
||||
X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) override;
|
||||
X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info,
|
||||
size_t length) override;
|
||||
|
||||
protected:
|
||||
virtual X_STATUS ReadSync(
|
||||
void* buffer, size_t buffer_length, size_t byte_offset,
|
||||
size_t* out_bytes_read);
|
||||
protected:
|
||||
X_STATUS ReadSync(void* buffer, size_t buffer_length, size_t byte_offset,
|
||||
size_t* out_bytes_read) override;
|
||||
|
||||
private:
|
||||
private:
|
||||
DiscImageEntry* entry_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace fs
|
||||
} // namespace kernel
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_KERNEL_FS_DEVICES_DISC_IMAGE_FILE_H_
|
||||
|
||||
@@ -29,15 +29,15 @@ HostPathFile::~HostPathFile() {
|
||||
CloseHandle(file_handle_);
|
||||
}
|
||||
|
||||
const char* HostPathFile::path(void) const {
|
||||
const std::string& HostPathFile::path() const {
|
||||
return entry_->path();
|
||||
}
|
||||
|
||||
const char* HostPathFile::absolute_path(void) const {
|
||||
const std::string& HostPathFile::absolute_path() const {
|
||||
return entry_->absolute_path();
|
||||
}
|
||||
|
||||
const char* HostPathFile::name(void) const {
|
||||
const std::string& HostPathFile::name() const {
|
||||
return entry_->name();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,49 +10,47 @@
|
||||
#ifndef XENIA_KERNEL_FS_DEVICES_HOST_PATH_FILE_H_
|
||||
#define XENIA_KERNEL_FS_DEVICES_HOST_PATH_FILE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <xenia/common.h>
|
||||
#include <xenia/core.h>
|
||||
|
||||
#include <xenia/kernel/objects/xfile.h>
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace kernel {
|
||||
namespace fs {
|
||||
|
||||
class HostPathEntry;
|
||||
|
||||
|
||||
class HostPathFile : public XFile {
|
||||
public:
|
||||
public:
|
||||
HostPathFile(KernelState* kernel_state, uint32_t desired_access,
|
||||
HostPathEntry* entry, HANDLE file_handle);
|
||||
virtual ~HostPathFile();
|
||||
~HostPathFile() override;
|
||||
|
||||
virtual const char* path(void) const;
|
||||
virtual const char* absolute_path(void) const;
|
||||
virtual const char* name(void) const;
|
||||
const std::string& path() const override;
|
||||
const std::string& absolute_path() const override;
|
||||
const std::string& name() const override;
|
||||
|
||||
virtual X_STATUS QueryInfo(XFileInfo* out_info);
|
||||
virtual X_STATUS QueryDirectory(XDirectoryInfo* out_info,
|
||||
size_t length, const char* file_name, bool restart);
|
||||
virtual X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length);
|
||||
virtual X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info, size_t length);
|
||||
X_STATUS QueryInfo(XFileInfo* out_info) override;
|
||||
X_STATUS QueryDirectory(XDirectoryInfo* out_info, size_t length,
|
||||
const char* file_name, bool restart) override;
|
||||
X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) override;
|
||||
X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info,
|
||||
size_t length) override;
|
||||
|
||||
protected:
|
||||
virtual X_STATUS ReadSync(
|
||||
void* buffer, size_t buffer_length, size_t byte_offset,
|
||||
size_t* out_bytes_read);
|
||||
protected:
|
||||
X_STATUS ReadSync(void* buffer, size_t buffer_length, size_t byte_offset,
|
||||
size_t* out_bytes_read) override;
|
||||
|
||||
private:
|
||||
private:
|
||||
HostPathEntry* entry_;
|
||||
HANDLE file_handle_;
|
||||
HANDLE file_handle_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace fs
|
||||
} // namespace kernel
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_KERNEL_FS_DEVICES_HOST_PATH_FILE_H_
|
||||
|
||||
@@ -29,15 +29,15 @@ STFSContainerFile::STFSContainerFile(
|
||||
STFSContainerFile::~STFSContainerFile() {
|
||||
}
|
||||
|
||||
const char* STFSContainerFile::path(void) const {
|
||||
const std::string& STFSContainerFile::path() const {
|
||||
return entry_->path();
|
||||
}
|
||||
|
||||
const char* STFSContainerFile::absolute_path(void) const {
|
||||
const std::string& STFSContainerFile::absolute_path() const {
|
||||
return entry_->absolute_path();
|
||||
}
|
||||
|
||||
const char* STFSContainerFile::name(void) const {
|
||||
const std::string& STFSContainerFile::name() const {
|
||||
return entry_->name();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,43 +15,39 @@
|
||||
|
||||
#include <xenia/kernel/objects/xfile.h>
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace kernel {
|
||||
namespace fs {
|
||||
|
||||
class STFSContainerEntry;
|
||||
|
||||
|
||||
class STFSContainerFile : public XFile {
|
||||
public:
|
||||
public:
|
||||
STFSContainerFile(KernelState* kernel_state, uint32_t desired_access,
|
||||
STFSContainerEntry* entry);
|
||||
virtual ~STFSContainerFile();
|
||||
~STFSContainerFile() override;
|
||||
|
||||
virtual const char* path(void) const;
|
||||
virtual const char* absolute_path(void) const;
|
||||
virtual const char* name(void) const;
|
||||
const std::string& path() const override;
|
||||
const std::string& absolute_path() const override;
|
||||
const std::string& name() const override;
|
||||
|
||||
virtual X_STATUS QueryInfo(XFileInfo* out_info);
|
||||
virtual X_STATUS QueryDirectory(XDirectoryInfo* out_info,
|
||||
size_t length, const char* file_name, bool restart);
|
||||
virtual X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length);
|
||||
virtual X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info, size_t length);
|
||||
X_STATUS QueryInfo(XFileInfo* out_info) override;
|
||||
X_STATUS QueryDirectory(XDirectoryInfo* out_info, size_t length,
|
||||
const char* file_name, bool restart) override;
|
||||
X_STATUS QueryVolume(XVolumeInfo* out_info, size_t length) override;
|
||||
X_STATUS QueryFileSystemAttributes(XFileSystemAttributeInfo* out_info,
|
||||
size_t length) override;
|
||||
|
||||
protected:
|
||||
virtual X_STATUS ReadSync(
|
||||
void* buffer, size_t buffer_length, size_t byte_offset,
|
||||
size_t* out_bytes_read);
|
||||
protected:
|
||||
X_STATUS ReadSync(void* buffer, size_t buffer_length, size_t byte_offset,
|
||||
size_t* out_bytes_read) override;
|
||||
|
||||
private:
|
||||
private:
|
||||
STFSContainerEntry* entry_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace fs
|
||||
} // namespace kernel
|
||||
} // namespace xe
|
||||
|
||||
|
||||
#endif // XENIA_KERNEL_FS_DEVICES_STFS_CONTAINER_FILE_H_
|
||||
|
||||
@@ -14,28 +14,17 @@ using namespace xe;
|
||||
using namespace xe::kernel;
|
||||
using namespace xe::kernel::fs;
|
||||
|
||||
MemoryMapping::MemoryMapping(uint8_t* address, size_t length)
|
||||
: address_(address), length_(length) {}
|
||||
|
||||
MemoryMapping::MemoryMapping(uint8_t* address, size_t length) :
|
||||
address_(address), length_(length) {
|
||||
}
|
||||
MemoryMapping::~MemoryMapping() {}
|
||||
|
||||
MemoryMapping::~MemoryMapping() {
|
||||
}
|
||||
|
||||
|
||||
Entry::Entry(Type type, Device* device, const char* path) :
|
||||
type_(type),
|
||||
device_(device) {
|
||||
Entry::Entry(Type type, Device* device, const std::string& path)
|
||||
: type_(type), device_(device), path_(path) {
|
||||
assert_not_null(device);
|
||||
path_ = xestrdupa(path);
|
||||
// TODO(benvanik): *shudder*
|
||||
absolute_path_ = xestrdupa((std::string(device->path()) + std::string(path)).c_str());
|
||||
absolute_path_ = device->path() + path;
|
||||
// TODO(benvanik): last index of \, unless \ at end, then before that
|
||||
name_ = NULL;
|
||||
name_ = "";
|
||||
}
|
||||
|
||||
Entry::~Entry() {
|
||||
xe_free(name_);
|
||||
xe_free(path_);
|
||||
xe_free(absolute_path_);
|
||||
}
|
||||
Entry::~Entry() = default;
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#ifndef XENIA_KERNEL_FS_ENTRY_H_
|
||||
#define XENIA_KERNEL_FS_ENTRY_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <xenia/common.h>
|
||||
#include <xenia/core.h>
|
||||
|
||||
@@ -52,14 +54,14 @@ public:
|
||||
kTypeDirectory,
|
||||
};
|
||||
|
||||
Entry(Type type, Device* device, const char* path);
|
||||
Entry(Type type, Device* device, const std::string& path);
|
||||
virtual ~Entry();
|
||||
|
||||
Type type() const { return type_; }
|
||||
Device* device() const { return device_; }
|
||||
const char* path() const { return path_; }
|
||||
const char* absolute_path() const { return absolute_path_; }
|
||||
const char* name() const { return name_; }
|
||||
const std::string& path() const { return path_; }
|
||||
const std::string& absolute_path() const { return absolute_path_; }
|
||||
const std::string& name() const { return name_; }
|
||||
|
||||
virtual X_STATUS QueryInfo(XFileInfo* out_info) = 0;
|
||||
virtual X_STATUS QueryDirectory(XDirectoryInfo* out_info,
|
||||
@@ -79,9 +81,9 @@ public:
|
||||
private:
|
||||
Type type_;
|
||||
Device* device_;
|
||||
char* path_;
|
||||
char* absolute_path_;
|
||||
char* name_;
|
||||
std::string path_;
|
||||
std::string absolute_path_;
|
||||
std::string name_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <xenia/kernel/fs/filesystem.h>
|
||||
|
||||
#include <poly/string.h>
|
||||
#include <xenia/kernel/fs/devices/disc_image_device.h>
|
||||
#include <xenia/kernel/fs/devices/host_path_device.h>
|
||||
#include <xenia/kernel/fs/devices/stfs_container_device.h>
|
||||
@@ -129,24 +130,22 @@ int FileSystem::RegisterSTFSContainerDevice(
|
||||
return RegisterDevice(path, device);
|
||||
}
|
||||
|
||||
int FileSystem::CreateSymbolicLink(const char* path, const char* target) {
|
||||
symlinks_.insert(std::pair<const char*, const char*>(
|
||||
xestrdupa(path),
|
||||
xestrdupa(target)));
|
||||
int FileSystem::CreateSymbolicLink(const std::string& path,
|
||||
const std::string& target) {
|
||||
symlinks_.insert({path, target});
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FileSystem::DeleteSymbolicLink(const char* path) {
|
||||
std::unordered_map<std::string, std::string>::iterator it =
|
||||
symlinks_.find(std::string(path));
|
||||
if (it != symlinks_.end()) {
|
||||
symlinks_.erase(it);
|
||||
return 0;
|
||||
int FileSystem::DeleteSymbolicLink(const std::string& path) {
|
||||
auto& it = symlinks_.find(path);
|
||||
if (it == symlinks_.end()) {
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
symlinks_.erase(it);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Entry* FileSystem::ResolvePath(const char* path) {
|
||||
Entry* FileSystem::ResolvePath(const std::string& path) {
|
||||
// Strip off prefix and pass to device.
|
||||
// e.g., d:\some\PATH.foo -> some\PATH.foo
|
||||
// Support both symlinks and device specifiers, like:
|
||||
@@ -158,33 +157,24 @@ Entry* FileSystem::ResolvePath(const char* path) {
|
||||
// Resolve symlinks.
|
||||
// TODO(benvanik): more robust symlink handling - right now we assume simple
|
||||
// drive path -> device mappings with nothing nested.
|
||||
char full_path[poly::max_path];
|
||||
XEIGNORE(xestrcpya(full_path, XECOUNT(full_path), path));
|
||||
for (std::unordered_map<std::string, std::string>::iterator it =
|
||||
symlinks_.begin(); it != symlinks_.end(); ++it) {
|
||||
if (xestrcasestra(path, it->first.c_str()) == path) {
|
||||
// Found symlink, fixup.
|
||||
const char* after_path = path + it->first.size();
|
||||
XEIGNORE(xesnprintfa(full_path, XECOUNT(full_path), "%s%s",
|
||||
it->second.c_str(), after_path));
|
||||
std::string full_path = path;
|
||||
for (const auto& it : symlinks_) {
|
||||
if (poly::find_first_of_case(path, it.first) == 0) {
|
||||
// Found symlink, fixup by replacing the prefix.
|
||||
full_path = it.second + full_path.substr(it.first.size());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Scan all devices.
|
||||
for (std::vector<Device*>::iterator it = devices_.begin();
|
||||
it != devices_.end(); ++it) {
|
||||
Device* device = *it;
|
||||
if (xestrcasestra(full_path, device->path()) == full_path) {
|
||||
// Found!
|
||||
// Trim the device prefix off and pass down.
|
||||
char device_path[poly::max_path];
|
||||
XEIGNORE(xestrcpya(device_path, XECOUNT(device_path),
|
||||
full_path + xestrlena(device->path())));
|
||||
return device->ResolvePath(device_path);
|
||||
for (auto& device : devices_) {
|
||||
if (poly::find_first_of_case(full_path, device->path()) == 0) {
|
||||
// Found! Trim the device prefix off and pass down.
|
||||
auto device_path = full_path.substr(device->path().size());
|
||||
return device->ResolvePath(device_path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
XELOGE("ResolvePath(%s) failed - no root found", path);
|
||||
XELOGE("ResolvePath(%s) failed - no root found", path.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -47,10 +47,10 @@ class FileSystem {
|
||||
int RegisterSTFSContainerDevice(const std::string& path,
|
||||
const std::wstring& local_path);
|
||||
|
||||
int CreateSymbolicLink(const char* path, const char* target);
|
||||
int DeleteSymbolicLink(const char* path);
|
||||
int CreateSymbolicLink(const std::string& path, const std::string& target);
|
||||
int DeleteSymbolicLink(const std::string& path);
|
||||
|
||||
Entry* ResolvePath(const char* path);
|
||||
Entry* ResolvePath(const std::string& path);
|
||||
|
||||
private:
|
||||
std::vector<Device*> devices_;
|
||||
|
||||
@@ -40,7 +40,7 @@ GDFXEntry* GDFXEntry::GetChild(const char* name) {
|
||||
for (std::vector<GDFXEntry*>::iterator it = children.begin();
|
||||
it != children.end(); ++it) {
|
||||
GDFXEntry* entry = *it;
|
||||
if (xestrcasecmpa(entry->name.c_str(), name) == 0) {
|
||||
if (strcasecmp(entry->name.c_str(), name) == 0) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ STFSEntry* STFSEntry::GetChild(const char* name) {
|
||||
// TODO(benvanik): a faster search
|
||||
for (auto it = children.begin(); it != children.end(); ++it) {
|
||||
STFSEntry* entry = *it;
|
||||
if (xestrcasecmpa(entry->name.c_str(), name) == 0) {
|
||||
if (strcasecmp(entry->name.c_str(), name) == 0) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user