Created
July 20, 2018 21:07
-
-
Save zachhilman/fe79eb60190d59cf48dc2492f328d2bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/core/file_sys/mode.h b/src/core/file_sys/mode.h | |
index b436315..6d40ad5 100644 | |
--- a/src/core/file_sys/mode.h | |
+++ b/src/core/file_sys/mode.h | |
@@ -14,4 +14,6 @@ enum class Mode : u32 { | |
Append = 4, | |
}; | |
+constexpr Mode MODE_RW = static_cast<Mode>(3); | |
+ | |
} // namespace FileSys | |
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp | |
index 22c858e..cc392f2 100644 | |
--- a/src/core/file_sys/vfs_real.cpp | |
+++ b/src/core/file_sys/vfs_real.cpp | |
@@ -9,19 +9,28 @@ | |
namespace FileSys { | |
static std::string PermissionsToCharArray(Mode perms) { | |
- std::string out; | |
- switch (perms) { | |
- case Mode::Read: | |
- out += "r"; | |
- break; | |
- case Mode::Write: | |
- out += "r+"; | |
- break; | |
- case Mode::Append: | |
- out += "a"; | |
- break; | |
+ std::string mode_str; | |
+ u32 mode_flags = static_cast<u32>(perms); | |
+ | |
+ // Calculate the correct open mode for the file. | |
+ if ((mode_flags & static_cast<u32>(Mode::Read)) && | |
+ (mode_flags & static_cast<u32>(Mode::Write))) { | |
+ if (mode_flags & static_cast<u32>(Mode::Append)) | |
+ mode_str = "a+"; | |
+ else | |
+ mode_str = "r+"; | |
+ } else { | |
+ if (mode_flags & static_cast<u32>(Mode::Read)) | |
+ mode_str = "r"; | |
+ else if (mode_flags & static_cast<u32>(Mode::Append)) | |
+ mode_str = "a"; | |
+ else if (mode_flags & static_cast<u32>(Mode::Write)) | |
+ mode_str = "w"; | |
} | |
- return out + "b"; | |
+ | |
+ mode_str += "b"; | |
+ | |
+ return mode_str; | |
} | |
RealVfsFile::RealVfsFile(const std::string& path_, Mode perms_) | |
@@ -85,7 +94,7 @@ RealVfsDirectory::RealVfsDirectory(const std::string& path_, Mode perms_) | |
path_components(FileUtil::SplitPathComponents(path)), | |
parent_components(FileUtil::SliceVector(path_components, 0, path_components.size() - 1)), | |
perms(perms_) { | |
- if (!FileUtil::Exists(path) && (perms == Mode::Write || perms == Mode::Append)) | |
+ if (!FileUtil::Exists(path) && (static_cast<u32>(perms_) & 0x6)) | |
FileUtil::CreateDir(path); | |
unsigned size; | |
if (perms == Mode::Append) | |
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp | |
index dffcdfb..8485671 100644 | |
--- a/src/core/hle/service/filesystem/filesystem.cpp | |
+++ b/src/core/hle/service/filesystem/filesystem.cpp | |
@@ -272,9 +272,9 @@ void RegisterFileSystems() { | |
sdmc_factory = nullptr; | |
auto nand_directory = std::make_shared<FileSys::RealVfsDirectory>( | |
- FileUtil::GetUserPath(D_NAND_IDX), FileSys::Mode::Write); | |
+ FileUtil::GetUserPath(D_NAND_IDX), FileSys::MODE_RW); | |
auto sd_directory = std::make_shared<FileSys::RealVfsDirectory>( | |
- FileUtil::GetUserPath(D_SDMC_IDX), FileSys::Mode::Write); | |
+ FileUtil::GetUserPath(D_SDMC_IDX), FileSys::MODE_RW); | |
auto savedata = std::make_unique<FileSys::SaveDataFactory>(std::move(nand_directory)); | |
save_data_factory = std::move(savedata); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment