summaryrefslogtreecommitdiff
path: root/Source/Core/Common/File.cpp
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2020-09-23 12:27:43 -0400
committerGitHub <noreply@github.com>2020-09-23 12:27:43 -0400
commit54e570a95f2cb54fdc7be29d04870746c69a8b9e (patch)
tree1db68bbdaa591d6cd8025493478fa5d0dadf7980 /Source/Core/Common/File.cpp
parentf33767f19cca6ee95af9727f0050f27e2571f770 (diff)
parent5ba083215852a7f1afa2ac73316c2c0c500a6e7d (diff)
Merge pull request #8902 from JosJuice/android-convert
Android: Add disc image conversion
Diffstat (limited to 'Source/Core/Common/File.cpp')
-rw-r--r--Source/Core/Common/File.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/Source/Core/Common/File.cpp b/Source/Core/Common/File.cpp
index 9dfcdbd7d8..a724cbb723 100644
--- a/Source/Core/Common/File.cpp
+++ b/Source/Core/Common/File.cpp
@@ -15,6 +15,13 @@
#include <unistd.h>
#endif
+#ifdef ANDROID
+#include <algorithm>
+
+#include "Common/StringUtil.h"
+#include "jni/AndroidCommon/AndroidCommon.h"
+#endif
+
#include "Common/CommonTypes.h"
#include "Common/File.h"
#include "Common/FileUtil.h"
@@ -62,7 +69,21 @@ bool IOFile::Open(const std::string& filename, const char openmode[])
#ifdef _WIN32
m_good = _tfopen_s(&m_file, UTF8ToTStr(filename).c_str(), UTF8ToTStr(openmode).c_str()) == 0;
#else
- m_file = std::fopen(filename.c_str(), openmode);
+#ifdef ANDROID
+ if (StringBeginsWith(filename, "content://"))
+ {
+ // The Java method which OpenAndroidContent passes the mode to does not support the b specifier.
+ // Since we're on POSIX, it's fine to just remove the b.
+ std::string mode_without_b(openmode);
+ mode_without_b.erase(std::remove(mode_without_b.begin(), mode_without_b.end(), 'b'),
+ mode_without_b.end());
+ m_file = fdopen(OpenAndroidContent(filename, mode_without_b), mode_without_b.c_str());
+ }
+ else
+#endif
+ {
+ m_file = std::fopen(filename.c_str(), openmode);
+ }
m_good = m_file != nullptr;
#endif