mirror of
https://github.com/Lime3DS/Lime3DS
synced 2024-11-01 04:37:52 +00:00
FileSys: Updated backend code to use FileSys::Path instead of string for paths.
This commit is contained in:
parent
c04a04189a
commit
a3107a6b57
12 changed files with 38 additions and 38 deletions
|
@ -182,21 +182,21 @@ public:
|
||||||
* @param mode Mode to open the file with
|
* @param mode Mode to open the file with
|
||||||
* @return Opened file, or nullptr
|
* @return Opened file, or nullptr
|
||||||
*/
|
*/
|
||||||
virtual std::unique_ptr<File> OpenFile(const std::string& path, const Mode mode) const = 0;
|
virtual std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a directory specified by its path
|
* Create a directory specified by its path
|
||||||
* @param path Path relative to the archive
|
* @param path Path relative to the archive
|
||||||
* @return Whether the directory could be created
|
* @return Whether the directory could be created
|
||||||
*/
|
*/
|
||||||
virtual bool CreateDirectory(const std::string& path) const = 0;
|
virtual bool CreateDirectory(const Path& path) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a directory specified by its path
|
* Open a directory specified by its path
|
||||||
* @param path Path relative to the archive
|
* @param path Path relative to the archive
|
||||||
* @return Opened directory, or nullptr
|
* @return Opened directory, or nullptr
|
||||||
*/
|
*/
|
||||||
virtual std::unique_ptr<Directory> OpenDirectory(const std::string& path) const = 0;
|
virtual std::unique_ptr<Directory> OpenDirectory(const Path& path) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read data from the archive
|
* Read data from the archive
|
||||||
|
|
|
@ -29,7 +29,7 @@ Archive_RomFS::~Archive_RomFS() {
|
||||||
* @param mode Mode to open the file with
|
* @param mode Mode to open the file with
|
||||||
* @return Opened file, or nullptr
|
* @return Opened file, or nullptr
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<File> Archive_RomFS::OpenFile(const std::string& path, const Mode mode) const {
|
std::unique_ptr<File> Archive_RomFS::OpenFile(const Path& path, const Mode mode) const {
|
||||||
return std::unique_ptr<File>(new File_RomFS);
|
return std::unique_ptr<File>(new File_RomFS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ std::unique_ptr<File> Archive_RomFS::OpenFile(const std::string& path, const Mod
|
||||||
* @param path Path relative to the archive
|
* @param path Path relative to the archive
|
||||||
* @return Whether the directory could be created
|
* @return Whether the directory could be created
|
||||||
*/
|
*/
|
||||||
bool Archive_RomFS::CreateDirectory(const std::string& path) const {
|
bool Archive_RomFS::CreateDirectory(const Path& path) const {
|
||||||
ERROR_LOG(FILESYS, "Attempted to create a directory in ROMFS.");
|
ERROR_LOG(FILESYS, "Attempted to create a directory in ROMFS.");
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
@ -48,7 +48,7 @@ bool Archive_RomFS::CreateDirectory(const std::string& path) const {
|
||||||
* @param path Path relative to the archive
|
* @param path Path relative to the archive
|
||||||
* @return Opened directory, or nullptr
|
* @return Opened directory, or nullptr
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<Directory> Archive_RomFS::OpenDirectory(const std::string& path) const {
|
std::unique_ptr<Directory> Archive_RomFS::OpenDirectory(const Path& path) const {
|
||||||
return std::unique_ptr<Directory>(new Directory_RomFS);
|
return std::unique_ptr<Directory>(new Directory_RomFS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,21 +34,21 @@ public:
|
||||||
* @param mode Mode to open the file with
|
* @param mode Mode to open the file with
|
||||||
* @return Opened file, or nullptr
|
* @return Opened file, or nullptr
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<File> OpenFile(const std::string& path, const Mode mode) const override;
|
std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a directory specified by its path
|
* Create a directory specified by its path
|
||||||
* @param path Path relative to the archive
|
* @param path Path relative to the archive
|
||||||
* @return Whether the directory could be created
|
* @return Whether the directory could be created
|
||||||
*/
|
*/
|
||||||
bool CreateDirectory(const std::string& path) const override;
|
bool CreateDirectory(const Path& path) const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a directory specified by its path
|
* Open a directory specified by its path
|
||||||
* @param path Path relative to the archive
|
* @param path Path relative to the archive
|
||||||
* @return Opened directory, or nullptr
|
* @return Opened directory, or nullptr
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<Directory> OpenDirectory(const std::string& path) const override;
|
std::unique_ptr<Directory> OpenDirectory(const Path& path) const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read data from the archive
|
* Read data from the archive
|
||||||
|
|
|
@ -49,8 +49,8 @@ bool Archive_SDMC::Initialize() {
|
||||||
* @param mode Mode to open the file with
|
* @param mode Mode to open the file with
|
||||||
* @return Opened file, or nullptr
|
* @return Opened file, or nullptr
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<File> Archive_SDMC::OpenFile(const std::string& path, const Mode mode) const {
|
std::unique_ptr<File> Archive_SDMC::OpenFile(const Path& path, const Mode mode) const {
|
||||||
DEBUG_LOG(FILESYS, "called path=%s mode=%d", path.c_str(), mode);
|
DEBUG_LOG(FILESYS, "called path=%s mode=%d", path.DebugStr().c_str(), mode);
|
||||||
File_SDMC* file = new File_SDMC(this, path, mode);
|
File_SDMC* file = new File_SDMC(this, path, mode);
|
||||||
if (!file->Open())
|
if (!file->Open())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -62,8 +62,8 @@ std::unique_ptr<File> Archive_SDMC::OpenFile(const std::string& path, const Mode
|
||||||
* @param path Path relative to the archive
|
* @param path Path relative to the archive
|
||||||
* @return Whether the directory could be created
|
* @return Whether the directory could be created
|
||||||
*/
|
*/
|
||||||
bool Archive_SDMC::CreateDirectory(const std::string& path) const {
|
bool Archive_SDMC::CreateDirectory(const Path& path) const {
|
||||||
return FileUtil::CreateDir(GetMountPoint() + path);
|
return FileUtil::CreateDir(GetMountPoint() + path.AsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,8 +71,8 @@ bool Archive_SDMC::CreateDirectory(const std::string& path) const {
|
||||||
* @param path Path relative to the archive
|
* @param path Path relative to the archive
|
||||||
* @return Opened directory, or nullptr
|
* @return Opened directory, or nullptr
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<Directory> Archive_SDMC::OpenDirectory(const std::string& path) const {
|
std::unique_ptr<Directory> Archive_SDMC::OpenDirectory(const Path& path) const {
|
||||||
DEBUG_LOG(FILESYS, "called path=%s", path.c_str());
|
DEBUG_LOG(FILESYS, "called path=%s", path.DebugStr().c_str());
|
||||||
Directory_SDMC* directory = new Directory_SDMC(this, path);
|
Directory_SDMC* directory = new Directory_SDMC(this, path);
|
||||||
return std::unique_ptr<Directory>(directory);
|
return std::unique_ptr<Directory>(directory);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,21 +38,21 @@ public:
|
||||||
* @param mode Mode to open the file with
|
* @param mode Mode to open the file with
|
||||||
* @return Opened file, or nullptr
|
* @return Opened file, or nullptr
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<File> OpenFile(const std::string& path, const Mode mode) const override;
|
std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a directory specified by its path
|
* Create a directory specified by its path
|
||||||
* @param path Path relative to the archive
|
* @param path Path relative to the archive
|
||||||
* @return Whether the directory could be created
|
* @return Whether the directory could be created
|
||||||
*/
|
*/
|
||||||
bool CreateDirectory(const std::string& path) const override;
|
bool CreateDirectory(const Path& path) const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a directory specified by its path
|
* Open a directory specified by its path
|
||||||
* @param path Path relative to the archive
|
* @param path Path relative to the archive
|
||||||
* @return Opened directory, or nullptr
|
* @return Opened directory, or nullptr
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<Directory> OpenDirectory(const std::string& path) const override;
|
std::unique_ptr<Directory> OpenDirectory(const Path& path) const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read data from the archive
|
* Read data from the archive
|
||||||
|
|
|
@ -15,11 +15,11 @@
|
||||||
|
|
||||||
namespace FileSys {
|
namespace FileSys {
|
||||||
|
|
||||||
Directory_SDMC::Directory_SDMC(const Archive_SDMC* archive, const std::string& path) {
|
Directory_SDMC::Directory_SDMC(const Archive_SDMC* archive, const Path& path) {
|
||||||
// TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
|
// TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
|
||||||
// the root directory we set while opening the archive.
|
// the root directory we set while opening the archive.
|
||||||
// For example, opening /../../usr/bin can give the emulated program your installed programs.
|
// For example, opening /../../usr/bin can give the emulated program your installed programs.
|
||||||
std::string absolute_path = archive->GetMountPoint() + path;
|
std::string absolute_path = archive->GetMountPoint() + path.AsString();
|
||||||
FileUtil::ScanDirectoryTree(absolute_path, directory);
|
FileUtil::ScanDirectoryTree(absolute_path, directory);
|
||||||
children_iterator = directory.children.begin();
|
children_iterator = directory.children.begin();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace FileSys {
|
||||||
class Directory_SDMC final : public Directory {
|
class Directory_SDMC final : public Directory {
|
||||||
public:
|
public:
|
||||||
Directory_SDMC();
|
Directory_SDMC();
|
||||||
Directory_SDMC(const Archive_SDMC* archive, const std::string& path);
|
Directory_SDMC(const Archive_SDMC* archive, const Path& path);
|
||||||
~Directory_SDMC() override;
|
~Directory_SDMC() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,11 +15,11 @@
|
||||||
|
|
||||||
namespace FileSys {
|
namespace FileSys {
|
||||||
|
|
||||||
File_SDMC::File_SDMC(const Archive_SDMC* archive, const std::string& path, const Mode mode) {
|
File_SDMC::File_SDMC(const Archive_SDMC* archive, const Path& path, const Mode mode) {
|
||||||
// TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
|
// TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
|
||||||
// the root directory we set while opening the archive.
|
// the root directory we set while opening the archive.
|
||||||
// For example, opening /../../etc/passwd can give the emulated program your users list.
|
// For example, opening /../../etc/passwd can give the emulated program your users list.
|
||||||
this->path = archive->GetMountPoint() + path;
|
this->path = archive->GetMountPoint() + path.AsString();
|
||||||
this->mode.hex = mode.hex;
|
this->mode.hex = mode.hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace FileSys {
|
||||||
class File_SDMC final : public File {
|
class File_SDMC final : public File {
|
||||||
public:
|
public:
|
||||||
File_SDMC();
|
File_SDMC();
|
||||||
File_SDMC(const Archive_SDMC* archive, const std::string& path, const Mode mode);
|
File_SDMC(const Archive_SDMC* archive, const Path& path, const Mode mode);
|
||||||
~File_SDMC() override;
|
~File_SDMC() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -129,12 +129,12 @@ public:
|
||||||
class File : public Object {
|
class File : public Object {
|
||||||
public:
|
public:
|
||||||
std::string GetTypeName() const override { return "File"; }
|
std::string GetTypeName() const override { return "File"; }
|
||||||
std::string GetName() const override { return path; }
|
std::string GetName() const override { return path.DebugStr(); }
|
||||||
|
|
||||||
static Kernel::HandleType GetStaticHandleType() { return HandleType::File; }
|
static Kernel::HandleType GetStaticHandleType() { return HandleType::File; }
|
||||||
Kernel::HandleType GetHandleType() const override { return HandleType::File; }
|
Kernel::HandleType GetHandleType() const override { return HandleType::File; }
|
||||||
|
|
||||||
std::string path; ///< Path of the file
|
FileSys::Path path; ///< Path of the file
|
||||||
std::unique_ptr<FileSys::File> backend; ///< File backend interface
|
std::unique_ptr<FileSys::File> backend; ///< File backend interface
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -221,12 +221,12 @@ public:
|
||||||
class Directory : public Object {
|
class Directory : public Object {
|
||||||
public:
|
public:
|
||||||
std::string GetTypeName() const override { return "Directory"; }
|
std::string GetTypeName() const override { return "Directory"; }
|
||||||
std::string GetName() const override { return path; }
|
std::string GetName() const override { return path.DebugStr(); }
|
||||||
|
|
||||||
static Kernel::HandleType GetStaticHandleType() { return HandleType::Directory; }
|
static Kernel::HandleType GetStaticHandleType() { return HandleType::Directory; }
|
||||||
Kernel::HandleType GetHandleType() const override { return HandleType::Directory; }
|
Kernel::HandleType GetHandleType() const override { return HandleType::Directory; }
|
||||||
|
|
||||||
std::string path; ///< Path of the directory
|
FileSys::Path path; ///< Path of the directory
|
||||||
std::unique_ptr<FileSys::Directory> backend; ///< File backend interface
|
std::unique_ptr<FileSys::Directory> backend; ///< File backend interface
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -366,7 +366,7 @@ Handle CreateArchive(FileSys::Archive* backend, const std::string& name) {
|
||||||
* @param mode Mode under which to open the File
|
* @param mode Mode under which to open the File
|
||||||
* @return Opened File object
|
* @return Opened File object
|
||||||
*/
|
*/
|
||||||
Handle OpenFileFromArchive(Handle archive_handle, const std::string& path, const FileSys::Mode mode) {
|
Handle OpenFileFromArchive(Handle archive_handle, const FileSys::Path& path, const FileSys::Mode mode) {
|
||||||
File* file = new File;
|
File* file = new File;
|
||||||
Handle handle = Kernel::g_object_pool.Create(file);
|
Handle handle = Kernel::g_object_pool.Create(file);
|
||||||
|
|
||||||
|
@ -386,7 +386,7 @@ Handle OpenFileFromArchive(Handle archive_handle, const std::string& path, const
|
||||||
* @param path Path to the Directory inside of the Archive
|
* @param path Path to the Directory inside of the Archive
|
||||||
* @return Opened Directory object
|
* @return Opened Directory object
|
||||||
*/
|
*/
|
||||||
Result CreateDirectoryFromArchive(Handle archive_handle, const std::string& path) {
|
Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) {
|
||||||
Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
|
Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
|
||||||
if (archive == nullptr)
|
if (archive == nullptr)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -401,7 +401,7 @@ Result CreateDirectoryFromArchive(Handle archive_handle, const std::string& path
|
||||||
* @param path Path to the Directory inside of the Archive
|
* @param path Path to the Directory inside of the Archive
|
||||||
* @return Opened Directory object
|
* @return Opened Directory object
|
||||||
*/
|
*/
|
||||||
Handle OpenDirectoryFromArchive(Handle archive_handle, const std::string& path) {
|
Handle OpenDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) {
|
||||||
Directory* directory = new Directory;
|
Directory* directory = new Directory;
|
||||||
Handle handle = Kernel::g_object_pool.Create(directory);
|
Handle handle = Kernel::g_object_pool.Create(directory);
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ Handle CreateArchive(FileSys::Archive* backend, const std::string& name);
|
||||||
* @param mode Mode under which to open the File
|
* @param mode Mode under which to open the File
|
||||||
* @return Opened File object
|
* @return Opened File object
|
||||||
*/
|
*/
|
||||||
Handle OpenFileFromArchive(Handle archive_handle, const std::string& name, const FileSys::Mode mode);
|
Handle OpenFileFromArchive(Handle archive_handle, const FileSys::Path& path, const FileSys::Mode mode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a Directory from an Archive
|
* Create a Directory from an Archive
|
||||||
|
@ -51,7 +51,7 @@ Handle OpenFileFromArchive(Handle archive_handle, const std::string& name, const
|
||||||
* @param path Path to the Directory inside of the Archive
|
* @param path Path to the Directory inside of the Archive
|
||||||
* @return Whether creation of directory succeeded
|
* @return Whether creation of directory succeeded
|
||||||
*/
|
*/
|
||||||
Result CreateDirectoryFromArchive(Handle archive_handle, const std::string& name);
|
Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a Directory from an Archive
|
* Open a Directory from an Archive
|
||||||
|
@ -59,7 +59,7 @@ Result CreateDirectoryFromArchive(Handle archive_handle, const std::string& name
|
||||||
* @param path Path to the Directory inside of the Archive
|
* @param path Path to the Directory inside of the Archive
|
||||||
* @return Opened Directory object
|
* @return Opened Directory object
|
||||||
*/
|
*/
|
||||||
Handle OpenDirectoryFromArchive(Handle archive_handle, const std::string& name);
|
Handle OpenDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path);
|
||||||
|
|
||||||
/// Initialize archives
|
/// Initialize archives
|
||||||
void ArchiveInit();
|
void ArchiveInit();
|
||||||
|
|
|
@ -55,7 +55,7 @@ void OpenFile(Service::Interface* self) {
|
||||||
DEBUG_LOG(KERNEL, "type=%d size=%d mode=%d attrs=%d data=%s",
|
DEBUG_LOG(KERNEL, "type=%d size=%d mode=%d attrs=%d data=%s",
|
||||||
filename_type, filename_size, mode, attributes, file_string.c_str());
|
filename_type, filename_size, mode, attributes, file_string.c_str());
|
||||||
|
|
||||||
Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_string, mode);
|
Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_path, mode);
|
||||||
if (handle) {
|
if (handle) {
|
||||||
cmd_buff[1] = 0;
|
cmd_buff[1] = 0;
|
||||||
cmd_buff[3] = handle;
|
cmd_buff[3] = handle;
|
||||||
|
@ -115,7 +115,7 @@ void OpenFileDirectly(Service::Interface* self) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_string, mode);
|
Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_path, mode);
|
||||||
if (handle) {
|
if (handle) {
|
||||||
cmd_buff[1] = 0;
|
cmd_buff[1] = 0;
|
||||||
cmd_buff[3] = handle;
|
cmd_buff[3] = handle;
|
||||||
|
@ -163,7 +163,7 @@ void CreateDirectory(Service::Interface* self) {
|
||||||
|
|
||||||
DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str());
|
DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str());
|
||||||
|
|
||||||
cmd_buff[1] = Kernel::CreateDirectoryFromArchive(archive_handle, dir_string);
|
cmd_buff[1] = Kernel::CreateDirectoryFromArchive(archive_handle, dir_path);
|
||||||
|
|
||||||
DEBUG_LOG(KERNEL, "called");
|
DEBUG_LOG(KERNEL, "called");
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ void OpenDirectory(Service::Interface* self) {
|
||||||
|
|
||||||
DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str());
|
DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str());
|
||||||
|
|
||||||
Handle handle = Kernel::OpenDirectoryFromArchive(archive_handle, dir_string);
|
Handle handle = Kernel::OpenDirectoryFromArchive(archive_handle, dir_path);
|
||||||
if (handle) {
|
if (handle) {
|
||||||
cmd_buff[1] = 0;
|
cmd_buff[1] = 0;
|
||||||
cmd_buff[3] = handle;
|
cmd_buff[3] = handle;
|
||||||
|
|
Loading…
Reference in a new issue