summaryrefslogtreecommitdiff
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorGravatar bunnei2014-11-17 22:26:54 -0500
committerGravatar bunnei2014-11-17 22:26:54 -0500
commitb66859714bda5968e36fed47a2ff8516bcfd2248 (patch)
treef1a933079afdfea73e76a187441733642489e2b0 /src/core/file_sys
parentMerge pull request #201 from archshift/boss (diff)
parentArchive: Fixed to not destroy archive handle on close. (diff)
downloadyuzu-b66859714bda5968e36fed47a2ff8516bcfd2248.tar.gz
yuzu-b66859714bda5968e36fed47a2ff8516bcfd2248.tar.xz
yuzu-b66859714bda5968e36fed47a2ff8516bcfd2248.zip
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 38145eed8..dc2d2ced9 100644
--- a/src/core/file_sys/archive.h
+++ b/src/core/file_sys/archive.h
@@ -74,6 +74,35 @@ public:
74 return type; 74 return type;
75 } 75 }
76 76
77 /**
78 * Gets the string representation of the path for debugging
79 * @return String representation of the path for debugging
80 */
81 const std::string DebugStr() const {
82 switch (GetType()) {
83 case Invalid:
84 return "[Invalid]";
85 case Empty:
86 return "[Empty]";
87 case Binary:
88 {
89 std::stringstream res;
90 res << "[Binary: ";
91 for (unsigned byte : binary)
92 res << std::hex << std::setw(2) << std::setfill('0') << byte;
93 res << ']';
94 return res.str();
95 }
96 case Char:
97 return "[Char: " + AsString() + ']';
98 case Wchar:
99 return "[Wchar: " + AsString() + ']';
100 default:
101 ERROR_LOG(KERNEL, "LowPathType cannot be converted to string!");
102 return {};
103 }
104 }
105
77 const std::string AsString() const { 106 const std::string AsString() const {
78 switch (GetType()) { 107 switch (GetType()) {
79 case Char: 108 case Char:
@@ -153,21 +182,21 @@ public:
153 * @param mode Mode to open the file with 182 * @param mode Mode to open the file with
154 * @return Opened file, or nullptr 183 * @return Opened file, or nullptr
155 */ 184 */
156 virtual std::unique_ptr<File> OpenFile(const std::string& path, const Mode mode) const = 0; 185 virtual std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const = 0;
157 186
158 /** 187 /**
159 * Create a directory specified by its path 188 * Create a directory specified by its path
160 * @param path Path relative to the archive 189 * @param path Path relative to the archive
161 * @return Whether the directory could be created 190 * @return Whether the directory could be created
162 */ 191 */
163 virtual bool CreateDirectory(const std::string& path) const = 0; 192 virtual bool CreateDirectory(const Path& path) const = 0;
164 193
165 /** 194 /**
166 * Open a directory specified by its path 195 * Open a directory specified by its path
167 * @param path Path relative to the archive 196 * @param path Path relative to the archive
168 * @return Opened directory, or nullptr 197 * @return Opened directory, or nullptr
169 */ 198 */
170 virtual std::unique_ptr<Directory> OpenDirectory(const std::string& path) const = 0; 199 virtual std::unique_ptr<Directory> OpenDirectory(const Path& path) const = 0;
171 200
172 /** 201 /**
173 * Read data from the archive 202 * Read data from the archive
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index cc759faa8..3ea60134f 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() {
29 * @param mode Mode to open the file with 29 * @param mode Mode to open the file with
30 * @return Opened file, or nullptr 30 * @return Opened file, or nullptr
31 */ 31 */
32std::unique_ptr<File> Archive_RomFS::OpenFile(const std::string& path, const Mode mode) const { 32std::unique_ptr<File> Archive_RomFS::OpenFile(const Path& path, const Mode mode) const {
33 return std::unique_ptr<File>(new File_RomFS); 33 return std::unique_ptr<File>(new File_RomFS);
34} 34}
35 35
@@ -38,7 +38,7 @@ std::unique_ptr<File> Archive_RomFS::OpenFile(const std::string& path, const Mod
38 * @param path Path relative to the archive 38 * @param path Path relative to the archive
39 * @return Whether the directory could be created 39 * @return Whether the directory could be created
40 */ 40 */
41bool Archive_RomFS::CreateDirectory(const std::string& path) const { 41bool Archive_RomFS::CreateDirectory(const Path& path) const {
42 ERROR_LOG(FILESYS, "Attempted to create a directory in ROMFS."); 42 ERROR_LOG(FILESYS, "Attempted to create a directory in ROMFS.");
43 return false; 43 return false;
44}; 44};
@@ -48,7 +48,7 @@ bool Archive_RomFS::CreateDirectory(const std::string& path) const {
48 * @param path Path relative to the archive 48 * @param path Path relative to the archive
49 * @return Opened directory, or nullptr 49 * @return Opened directory, or nullptr
50 */ 50 */
51std::unique_ptr<Directory> Archive_RomFS::OpenDirectory(const std::string& path) const { 51std::unique_ptr<Directory> Archive_RomFS::OpenDirectory(const Path& path) const {
52 return std::unique_ptr<Directory>(new Directory_RomFS); 52 return std::unique_ptr<Directory>(new Directory_RomFS);
53} 53}
54 54
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h
index ae2344e82..8d5715734 100644
--- a/src/core/file_sys/archive_romfs.h
+++ b/src/core/file_sys/archive_romfs.h
@@ -34,21 +34,21 @@ public:
34 * @param mode Mode to open the file with 34 * @param mode Mode to open the file with
35 * @return Opened file, or nullptr 35 * @return Opened file, or nullptr
36 */ 36 */
37 std::unique_ptr<File> OpenFile(const std::string& path, const Mode mode) const override; 37 std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const override;
38 38
39 /** 39 /**
40 * Create a directory specified by its path 40 * Create a directory specified by its path
41 * @param path Path relative to the archive 41 * @param path Path relative to the archive
42 * @return Whether the directory could be created 42 * @return Whether the directory could be created
43 */ 43 */
44 bool CreateDirectory(const std::string& path) const override; 44 bool CreateDirectory(const Path& path) const override;
45 45
46 /** 46 /**
47 * Open a directory specified by its path 47 * Open a directory specified by its path
48 * @param path Path relative to the archive 48 * @param path Path relative to the archive
49 * @return Opened directory, or nullptr 49 * @return Opened directory, or nullptr
50 */ 50 */
51 std::unique_ptr<Directory> OpenDirectory(const std::string& path) const override; 51 std::unique_ptr<Directory> OpenDirectory(const Path& path) const override;
52 52
53 /** 53 /**
54 * Read data from the archive 54 * Read data from the archive
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp
index 66931e93e..ecdb7f211 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() {
49 * @param mode Mode to open the file with 49 * @param mode Mode to open the file with
50 * @return Opened file, or nullptr 50 * @return Opened file, or nullptr
51 */ 51 */
52std::unique_ptr<File> Archive_SDMC::OpenFile(const std::string& path, const Mode mode) const { 52std::unique_ptr<File> Archive_SDMC::OpenFile(const Path& path, const Mode mode) const {
53 DEBUG_LOG(FILESYS, "called path=%s mode=%d", path.c_str(), mode); 53 DEBUG_LOG(FILESYS, "called path=%s mode=%d", path.DebugStr().c_str(), mode);
54 File_SDMC* file = new File_SDMC(this, path, mode); 54 File_SDMC* file = new File_SDMC(this, path, mode);
55 if (!file->Open()) 55 if (!file->Open())
56 return nullptr; 56 return nullptr;
@@ -62,8 +62,8 @@ std::unique_ptr<File> Archive_SDMC::OpenFile(const std::string& path, const Mode
62 * @param path Path relative to the archive 62 * @param path Path relative to the archive
63 * @return Whether the directory could be created 63 * @return Whether the directory could be created
64 */ 64 */
65bool Archive_SDMC::CreateDirectory(const std::string& path) const { 65bool Archive_SDMC::CreateDirectory(const Path& path) const {
66 return FileUtil::CreateDir(GetMountPoint() + path); 66 return FileUtil::CreateDir(GetMountPoint() + path.AsString());
67} 67}
68 68
69/** 69/**
@@ -71,8 +71,8 @@ bool Archive_SDMC::CreateDirectory(const std::string& path) const {
71 * @param path Path relative to the archive 71 * @param path Path relative to the archive
72 * @return Opened directory, or nullptr 72 * @return Opened directory, or nullptr
73 */ 73 */
74std::unique_ptr<Directory> Archive_SDMC::OpenDirectory(const std::string& path) const { 74std::unique_ptr<Directory> Archive_SDMC::OpenDirectory(const Path& path) const {
75 DEBUG_LOG(FILESYS, "called path=%s", path.c_str()); 75 DEBUG_LOG(FILESYS, "called path=%s", path.DebugStr().c_str());
76 Directory_SDMC* directory = new Directory_SDMC(this, path); 76 Directory_SDMC* directory = new Directory_SDMC(this, path);
77 return std::unique_ptr<Directory>(directory); 77 return std::unique_ptr<Directory>(directory);
78} 78}
diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h
index 0e059b635..1f621b3f7 100644
--- a/src/core/file_sys/archive_sdmc.h
+++ b/src/core/file_sys/archive_sdmc.h
@@ -38,21 +38,21 @@ public:
38 * @param mode Mode to open the file with 38 * @param mode Mode to open the file with
39 * @return Opened file, or nullptr 39 * @return Opened file, or nullptr
40 */ 40 */
41 std::unique_ptr<File> OpenFile(const std::string& path, const Mode mode) const override; 41 std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const override;
42 42
43 /** 43 /**
44 * Create a directory specified by its path 44 * Create a directory specified by its path
45 * @param path Path relative to the archive 45 * @param path Path relative to the archive
46 * @return Whether the directory could be created 46 * @return Whether the directory could be created
47 */ 47 */
48 bool CreateDirectory(const std::string& path) const override; 48 bool CreateDirectory(const Path& path) const override;
49 49
50 /** 50 /**
51 * Open a directory specified by its path 51 * Open a directory specified by its path
52 * @param path Path relative to the archive 52 * @param path Path relative to the archive
53 * @return Opened directory, or nullptr 53 * @return Opened directory, or nullptr
54 */ 54 */
55 std::unique_ptr<Directory> OpenDirectory(const std::string& path) const override; 55 std::unique_ptr<Directory> OpenDirectory(const Path& path) const override;
56 56
57 /** 57 /**
58 * Read data from the archive 58 * Read data from the archive
diff --git a/src/core/file_sys/directory_sdmc.cpp b/src/core/file_sys/directory_sdmc.cpp
index fd558def9..923ca6862 100644
--- a/src/core/file_sys/directory_sdmc.cpp
+++ b/src/core/file_sys/directory_sdmc.cpp
@@ -15,11 +15,11 @@
15 15
16namespace FileSys { 16namespace FileSys {
17 17
18Directory_SDMC::Directory_SDMC(const Archive_SDMC* archive, const std::string& path) { 18Directory_SDMC::Directory_SDMC(const Archive_SDMC* archive, const Path& path) {
19 // TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass 19 // TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
20 // the root directory we set while opening the archive. 20 // the root directory we set while opening the archive.
21 // For example, opening /../../usr/bin can give the emulated program your installed programs. 21 // For example, opening /../../usr/bin can give the emulated program your installed programs.
22 std::string absolute_path = archive->GetMountPoint() + path; 22 std::string absolute_path = archive->GetMountPoint() + path.AsString();
23 FileUtil::ScanDirectoryTree(absolute_path, directory); 23 FileUtil::ScanDirectoryTree(absolute_path, directory);
24 children_iterator = directory.children.begin(); 24 children_iterator = directory.children.begin();
25} 25}
diff --git a/src/core/file_sys/directory_sdmc.h b/src/core/file_sys/directory_sdmc.h
index cb8d32fda..4520d0401 100644
--- a/src/core/file_sys/directory_sdmc.h
+++ b/src/core/file_sys/directory_sdmc.h
@@ -19,7 +19,7 @@ namespace FileSys {
19class Directory_SDMC final : public Directory { 19class Directory_SDMC final : public Directory {
20public: 20public:
21 Directory_SDMC(); 21 Directory_SDMC();
22 Directory_SDMC(const Archive_SDMC* archive, const std::string& path); 22 Directory_SDMC(const Archive_SDMC* archive, const Path& path);
23 ~Directory_SDMC() override; 23 ~Directory_SDMC() override;
24 24
25 /** 25 /**
diff --git a/src/core/file_sys/file_sdmc.cpp b/src/core/file_sys/file_sdmc.cpp
index 26204392c..a4b90670a 100644
--- a/src/core/file_sys/file_sdmc.cpp
+++ b/src/core/file_sys/file_sdmc.cpp
@@ -15,11 +15,11 @@
15 15
16namespace FileSys { 16namespace FileSys {
17 17
18File_SDMC::File_SDMC(const Archive_SDMC* archive, const std::string& path, const Mode mode) { 18File_SDMC::File_SDMC(const Archive_SDMC* archive, const Path& path, const Mode mode) {
19 // TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass 19 // TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
20 // the root directory we set while opening the archive. 20 // the root directory we set while opening the archive.
21 // For example, opening /../../etc/passwd can give the emulated program your users list. 21 // For example, opening /../../etc/passwd can give the emulated program your users list.
22 this->path = archive->GetMountPoint() + path; 22 this->path = archive->GetMountPoint() + path.AsString();
23 this->mode.hex = mode.hex; 23 this->mode.hex = mode.hex;
24} 24}
25 25
diff --git a/src/core/file_sys/file_sdmc.h b/src/core/file_sys/file_sdmc.h
index df032f7c0..80b445968 100644
--- a/src/core/file_sys/file_sdmc.h
+++ b/src/core/file_sys/file_sdmc.h
@@ -19,7 +19,7 @@ namespace FileSys {
19class File_SDMC final : public File { 19class File_SDMC final : public File {
20public: 20public:
21 File_SDMC(); 21 File_SDMC();
22 File_SDMC(const Archive_SDMC* archive, const std::string& path, const Mode mode); 22 File_SDMC(const Archive_SDMC* archive, const Path& path, const Mode mode);
23 ~File_SDMC() override; 23 ~File_SDMC() override;
24 24
25 /** 25 /**