summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Subv2018-03-19 22:57:34 -0500
committerGravatar Subv2018-03-19 22:57:34 -0500
commitfc44261dd1304c7dd1f38999a13ef9734c23b69a (patch)
tree91cbdaae10e1e5b909cab874f9afe8fbbb2d4ed7 /src/core
parentFS: Implement MountSdCard. (diff)
downloadyuzu-fc44261dd1304c7dd1f38999a13ef9734c23b69a.tar.gz
yuzu-fc44261dd1304c7dd1f38999a13ef9734c23b69a.tar.xz
yuzu-fc44261dd1304c7dd1f38999a13ef9734c23b69a.zip
FS: Support the file Append open mode.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/file_sys/disk_filesystem.cpp24
-rw-r--r--src/core/file_sys/filesystem.h1
2 files changed, 23 insertions, 2 deletions
diff --git a/src/core/file_sys/disk_filesystem.cpp b/src/core/file_sys/disk_filesystem.cpp
index 22b17ba04..9d456e0bf 100644
--- a/src/core/file_sys/disk_filesystem.cpp
+++ b/src/core/file_sys/disk_filesystem.cpp
@@ -17,10 +17,30 @@ std::string Disk_FileSystem::GetName() const {
17 17
18ResultVal<std::unique_ptr<StorageBackend>> Disk_FileSystem::OpenFile(const std::string& path, 18ResultVal<std::unique_ptr<StorageBackend>> Disk_FileSystem::OpenFile(const std::string& path,
19 Mode mode) const { 19 Mode mode) const {
20 ASSERT_MSG(mode == Mode::Read || mode == Mode::Write, "Other file modes are not supported"); 20
21 std::string mode_str = "";
22 u32 mode_flags = static_cast<u32>(mode);
23
24 // Calculate the correct open mode for the file.
25 if ((mode_flags & static_cast<u32>(Mode::Read)) &&
26 (mode_flags & static_cast<u32>(Mode::Write))) {
27 if (mode_flags & static_cast<u32>(Mode::Append))
28 mode_str = "a+";
29 else
30 mode_str = "r+";
31 } else {
32 if (mode_flags & static_cast<u32>(Mode::Read))
33 mode_str = "r";
34 else if (mode_flags & static_cast<u32>(Mode::Append))
35 mode_str = "a";
36 else if (mode_flags & static_cast<u32>(Mode::Write))
37 mode_str = "w";
38 }
39
40 mode_str += "b";
21 41
22 std::string full_path = base_directory + path; 42 std::string full_path = base_directory + path;
23 auto file = std::make_shared<FileUtil::IOFile>(full_path, mode == Mode::Read ? "rb" : "wb"); 43 auto file = std::make_shared<FileUtil::IOFile>(full_path, mode_str.c_str());
24 44
25 if (!file->IsOpen()) { 45 if (!file->IsOpen()) {
26 return ERROR_PATH_NOT_FOUND; 46 return ERROR_PATH_NOT_FOUND;
diff --git a/src/core/file_sys/filesystem.h b/src/core/file_sys/filesystem.h
index 94ad2abf2..4c9993efa 100644
--- a/src/core/file_sys/filesystem.h
+++ b/src/core/file_sys/filesystem.h
@@ -35,6 +35,7 @@ enum EntryType : u32 {
35enum class Mode : u32 { 35enum class Mode : u32 {
36 Read = 1, 36 Read = 1,
37 Write = 2, 37 Write = 2,
38 Append = 4,
38}; 39};
39 40
40class Path { 41class Path {