@@ -11,6 +11,7 @@
|
||||
|
||||
#include "xenia/base/filesystem.h"
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/math.h"
|
||||
#include "xenia/vfs/devices/host_path_entry.h"
|
||||
#include "xenia/kernel/objects/xfile.h"
|
||||
|
||||
@@ -21,30 +22,50 @@ HostPathDevice::HostPathDevice(const std::string& mount_path,
|
||||
const std::wstring& local_path, bool read_only)
|
||||
: Device(mount_path), local_path_(local_path), read_only_(read_only) {}
|
||||
|
||||
HostPathDevice::~HostPathDevice() {}
|
||||
HostPathDevice::~HostPathDevice() = default;
|
||||
|
||||
std::unique_ptr<Entry> HostPathDevice::ResolvePath(const char* path) {
|
||||
// The filesystem will have stripped our prefix off already, so the path will
|
||||
// be in the form:
|
||||
// some\PATH.foo
|
||||
|
||||
XELOGFS("HostPathDevice::ResolvePath(%s)", path);
|
||||
|
||||
auto rel_path = xe::to_wstring(path);
|
||||
auto full_path = xe::join_paths(local_path_, rel_path);
|
||||
full_path = xe::fix_path_separators(full_path);
|
||||
|
||||
// Only check the file exists when the device is read-only
|
||||
if (read_only_) {
|
||||
if (!xe::filesystem::PathExists(full_path)) {
|
||||
return nullptr;
|
||||
}
|
||||
bool HostPathDevice::Initialize() {
|
||||
if (!filesystem::PathExists(local_path_)) {
|
||||
XELOGE("Host path does not exist");
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO(benvanik): get file info
|
||||
// TODO(benvanik): switch based on type
|
||||
auto root_entry = new HostPathEntry(this, "", local_path_);
|
||||
root_entry->attributes_ = kFileAttributeDirectory;
|
||||
root_entry_ = std::unique_ptr<Entry>(root_entry);
|
||||
PopulateEntry(root_entry);
|
||||
|
||||
return std::make_unique<HostPathEntry>(this, path, full_path);
|
||||
return true;
|
||||
}
|
||||
|
||||
void HostPathDevice::PopulateEntry(HostPathEntry* entry) {
|
||||
auto child_infos = filesystem::ListFiles(entry->local_path());
|
||||
for (auto& child_info : child_infos) {
|
||||
auto child =
|
||||
new HostPathEntry(this, xe::to_string(child_info.name),
|
||||
xe::join_paths(entry->local_path(), child_info.name));
|
||||
child->create_timestamp_ = child_info.create_timestamp;
|
||||
child->access_timestamp_ = child_info.access_timestamp;
|
||||
child->write_timestamp_ = child_info.write_timestamp;
|
||||
|
||||
if (child_info.type == filesystem::FileInfo::Type::kDirectory) {
|
||||
child->attributes_ = kFileAttributeDirectory;
|
||||
} else {
|
||||
child->attributes_ = kFileAttributeNormal;
|
||||
if (read_only_) {
|
||||
child->attributes_ |= kFileAttributeReadOnly;
|
||||
}
|
||||
child->size_ = child_info.total_size;
|
||||
child->allocation_size_ =
|
||||
xe::round_up(child_info.total_size, bytes_per_sector());
|
||||
}
|
||||
|
||||
entry->children_.push_back(std::unique_ptr<Entry>(child));
|
||||
|
||||
if (child_info.type == filesystem::FileInfo::Type::kDirectory) {
|
||||
PopulateEntry(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace vfs
|
||||
|
||||
Reference in New Issue
Block a user