aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorGravatar bunnei <bunneidev@gmail.com>2014-11-17 22:26:54 -0500
committerGravatar bunnei <bunneidev@gmail.com>2014-11-17 22:26:54 -0500
commitb66859714bda5968e36fed47a2ff8516bcfd2248 (patch)
treef1a933079afdfea73e76a187441733642489e2b0 /src/core/file_sys
parent4ac4c3caf1ddcb645ef1ee877163eaf93cd5f1c5 (diff)
parent11641b5e7913a90d2428d7a3ad04b9963e9fa278 (diff)
Merge pull request #192 from bunnei/fs-fix-paths
FileSys: Updates backend code to use FileSys::Path and fixes binary path types.
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/archive.h35
-rw-r--r--src/core/file_sys/archive_romfs.cpp6
-rw-r--r--src/core/file_sys/archive_romfs.h6
-rw-r--r--src/core/file_sys/archive_sdmc.cpp12
-rw-r--r--src/core/file_sys/archive_sdmc.h6
-rw-r--r--src/core/file_sys/directory_sdmc.cpp4
-rw-r--r--src/core/file_sys/directory_sdmc.h2
-rw-r--r--src/core/file_sys/file_sdmc.cpp4
-rw-r--r--src/core/file_sys/file_sdmc.h2
9 files changed, 53 insertions, 24 deletions
diff --git a/src/core/file_sys/archive.h b/src/core/file_sys/archive.h
index 38145eed..dc2d2ced 100644
--- a/src/core/file_sys/archive.h
+++ b/src/core/file_sys/archive.h
@@ -74,6 +74,35 @@ public:
return type;
}
+ /**
+ * Gets the string representation of the path for debugging
+ * @return String representation of the path for debugging
+ */
+ const std::string DebugStr() const {
+ switch (GetType()) {
+ case Invalid:
+ return "[Invalid]";
+ case Empty:
+ return "[Empty]";
+ case Binary:
+ {
+ std::stringstream res;
+ res << "[Binary: ";
+ for (unsigned byte : binary)
+ res << std::hex << std::setw(2) << std::setfill('0') << byte;
+ res << ']';
+ return res.str();
+ }
+ case Char:
+ return "[Char: " + AsString() + ']';
+ case Wchar:
+ return "[Wchar: " + AsString() + ']';
+ default:
+ ERROR_LOG(KERNEL, "LowPathType cannot be converted to string!");
+ return {};
+ }
+ }
+
const std::string AsString() const {
switch (GetType()) {
case Char:
@@ -153,21 +182,21 @@ public:
* @param mode Mode to open the file with
* @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
* @param path Path relative to the archive
* @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
* @param path Path relative to the archive
* @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
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index cc759faa..3ea60134 100644
--- a/src/core/file_sys/archive_romfs.cpp
+++ b/src/core/file_sys/archive_romfs.cpp
@@ -29,7 +29,7 @@ Archive_RomFS::~Archive_RomFS() {
* @param mode Mode to open the file with
* @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);
}
@@ -38,7 +38,7 @@ std::unique_ptr<File> Archive_RomFS::OpenFile(const std::string& path, const Mod
* @param path Path relative to the archive
* @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.");
return false;
};
@@ -48,7 +48,7 @@ bool Archive_RomFS::CreateDirectory(const std::string& path) const {
* @param path Path relative to the archive
* @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);
}
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h
index ae2344e8..8d571573 100644
--- a/src/core/file_sys/archive_romfs.h
+++ b/src/core/file_sys/archive_romfs.h
@@ -34,21 +34,21 @@ public:
* @param mode Mode to open the file with
* @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
* @param path Path relative to the archive
* @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
* @param path Path relative to the archive
* @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
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp
index 66931e93..ecdb7f21 100644
--- a/src/core/file_sys/archive_sdmc.cpp
+++ b/src/core/file_sys/archive_sdmc.cpp
@@ -49,8 +49,8 @@ bool Archive_SDMC::Initialize() {
* @param mode Mode to open the file with
* @return Opened file, or nullptr
*/
-std::unique_ptr<File> Archive_SDMC::OpenFile(const std::string& path, const Mode mode) const {
- DEBUG_LOG(FILESYS, "called path=%s mode=%d", path.c_str(), mode);
+std::unique_ptr<File> Archive_SDMC::OpenFile(const Path& path, const Mode mode) const {
+ DEBUG_LOG(FILESYS, "called path=%s mode=%d", path.DebugStr().c_str(), mode);
File_SDMC* file = new File_SDMC(this, path, mode);
if (!file->Open())
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
* @return Whether the directory could be created
*/
-bool Archive_SDMC::CreateDirectory(const std::string& path) const {
- return FileUtil::CreateDir(GetMountPoint() + path);
+bool Archive_SDMC::CreateDirectory(const Path& path) const {
+ 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
* @return Opened directory, or nullptr
*/
-std::unique_ptr<Directory> Archive_SDMC::OpenDirectory(const std::string& path) const {
- DEBUG_LOG(FILESYS, "called path=%s", path.c_str());
+std::unique_ptr<Directory> Archive_SDMC::OpenDirectory(const Path& path) const {
+ DEBUG_LOG(FILESYS, "called path=%s", path.DebugStr().c_str());
Directory_SDMC* directory = new Directory_SDMC(this, path);
return std::unique_ptr<Directory>(directory);
}
diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h
index 0e059b63..1f621b3f 100644
--- a/src/core/file_sys/archive_sdmc.h
+++ b/src/core/file_sys/archive_sdmc.h
@@ -38,21 +38,21 @@ public:
* @param mode Mode to open the file with
* @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
* @param path Path relative to the archive
* @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
* @param path Path relative to the archive
* @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
diff --git a/src/core/file_sys/directory_sdmc.cpp b/src/core/file_sys/directory_sdmc.cpp
index fd558def..923ca686 100644
--- a/src/core/file_sys/directory_sdmc.cpp
+++ b/src/core/file_sys/directory_sdmc.cpp
@@ -15,11 +15,11 @@
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
// the root directory we set while opening the archive.
// 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);
children_iterator = directory.children.begin();
}
diff --git a/src/core/file_sys/directory_sdmc.h b/src/core/file_sys/directory_sdmc.h
index cb8d32fd..4520d040 100644
--- a/src/core/file_sys/directory_sdmc.h
+++ b/src/core/file_sys/directory_sdmc.h
@@ -19,7 +19,7 @@ namespace FileSys {
class Directory_SDMC final : public Directory {
public:
Directory_SDMC();
- Directory_SDMC(const Archive_SDMC* archive, const std::string& path);
+ Directory_SDMC(const Archive_SDMC* archive, const Path& path);
~Directory_SDMC() override;
/**
diff --git a/src/core/file_sys/file_sdmc.cpp b/src/core/file_sys/file_sdmc.cpp
index 26204392..a4b90670 100644
--- a/src/core/file_sys/file_sdmc.cpp
+++ b/src/core/file_sys/file_sdmc.cpp
@@ -15,11 +15,11 @@
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
// the root directory we set while opening the archive.
// 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;
}
diff --git a/src/core/file_sys/file_sdmc.h b/src/core/file_sys/file_sdmc.h
index df032f7c..80b44596 100644
--- a/src/core/file_sys/file_sdmc.h
+++ b/src/core/file_sys/file_sdmc.h
@@ -19,7 +19,7 @@ namespace FileSys {
class File_SDMC final : public File {
public:
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;
/**