Created
July 22, 2018 03:58
-
-
Save Subv/1ec3b21a2abe41eb6466aa3628a4545a to your computer and use it in GitHub Desktop.
This file contains hidden or 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/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp | |
index 22c858e0..99deb579 100644 | |
--- a/src/core/file_sys/vfs_real.cpp | |
+++ b/src/core/file_sys/vfs_real.cpp | |
@@ -1,7 +1,7 @@ | |
// Copyright 2018 yuzu emulator team | |
// Licensed under GPLv2 or any later version | |
// Refer to the license.txt file included. | |
- | |
+#pragma optimize("", off) | |
#include "common/common_paths.h" | |
#include "common/logging/log.h" | |
#include "core/file_sys/vfs_real.h" | |
@@ -9,7 +9,7 @@ | |
namespace FileSys { | |
static std::string PermissionsToCharArray(Mode perms) { | |
- std::string out; | |
+ /*std::string out; | |
switch (perms) { | |
case Mode::Read: | |
out += "r"; | |
@@ -21,7 +21,29 @@ static std::string PermissionsToCharArray(Mode perms) { | |
out += "a"; | |
break; | |
} | |
- return out + "b"; | |
+ return out + "b";*/ | |
+ 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"; | |
+ } | |
+ | |
+ mode_str += "b"; | |
+ | |
+ return mode_str; | |
} | |
RealVfsFile::RealVfsFile(const std::string& path_, Mode perms_) | |
@@ -48,11 +70,12 @@ std::shared_ptr<VfsDirectory> RealVfsFile::GetContainingDirectory() const { | |
} | |
bool RealVfsFile::IsWritable() const { | |
- return perms == Mode::Append || perms == Mode::Write; | |
+ return static_cast<u32>(perms) & | |
+ (static_cast<u32>(Mode::Append) | static_cast<u32>(Mode::Write)); | |
} | |
bool RealVfsFile::IsReadable() const { | |
- return perms == Mode::Read || perms == Mode::Write; | |
+ return static_cast<u32>(perms) & (static_cast<u32>(Mode::Read) | static_cast<u32>(Mode::Write)); | |
} | |
size_t RealVfsFile::Read(u8* data, size_t length, size_t offset) const { | |
@@ -85,11 +108,16 @@ 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) & (static_cast<u32>(Mode::Write) | | |
+ static_cast<u32>(Mode::Append)))) { | |
FileUtil::CreateDir(path); | |
+ } | |
+ | |
unsigned size; | |
- if (perms == Mode::Append) | |
+ | |
+ if (static_cast<u32>(perms) & static_cast<u32>(Mode::Append)) { | |
return; | |
+ } | |
FileUtil::ForeachDirectoryEntry( | |
&size, path, | |
@@ -112,11 +140,12 @@ std::vector<std::shared_ptr<VfsDirectory>> RealVfsDirectory::GetSubdirectories() | |
} | |
bool RealVfsDirectory::IsWritable() const { | |
- return perms == Mode::Write || perms == Mode::Append; | |
+ return static_cast<u32>(perms) & | |
+ (static_cast<u32>(Mode::Append) | static_cast<u32>(Mode::Write)); | |
} | |
bool RealVfsDirectory::IsReadable() const { | |
- return perms == Mode::Read || perms == Mode::Write; | |
+ return static_cast<u32>(perms) & (static_cast<u32>(Mode::Read) | static_cast<u32>(Mode::Write)); | |
} | |
std::string RealVfsDirectory::GetName() const { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment