diff options
Diffstat (limited to 'src/common/fs/file.cpp')
| -rw-r--r-- | src/common/fs/file.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/common/fs/file.cpp b/src/common/fs/file.cpp index 656b03cc5..b0b25eb43 100644 --- a/src/common/fs/file.cpp +++ b/src/common/fs/file.cpp | |||
| @@ -5,6 +5,9 @@ | |||
| 5 | 5 | ||
| 6 | #include "common/fs/file.h" | 6 | #include "common/fs/file.h" |
| 7 | #include "common/fs/fs.h" | 7 | #include "common/fs/fs.h" |
| 8 | #ifdef ANDROID | ||
| 9 | #include "common/fs/fs_android.h" | ||
| 10 | #endif | ||
| 8 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 9 | 12 | ||
| 10 | #ifdef _WIN32 | 13 | #ifdef _WIN32 |
| @@ -252,6 +255,23 @@ void IOFile::Open(const fs::path& path, FileAccessMode mode, FileType type, File | |||
| 252 | } else { | 255 | } else { |
| 253 | _wfopen_s(&file, path.c_str(), AccessModeToWStr(mode, type)); | 256 | _wfopen_s(&file, path.c_str(), AccessModeToWStr(mode, type)); |
| 254 | } | 257 | } |
| 258 | #elif ANDROID | ||
| 259 | if (Android::IsContentUri(path)) { | ||
| 260 | ASSERT_MSG(mode == FileAccessMode::Read, "Content URI file access is for read-only!"); | ||
| 261 | const auto fd = Android::OpenContentUri(path, Android::OpenMode::Read); | ||
| 262 | if (fd != -1) { | ||
| 263 | file = fdopen(fd, "r"); | ||
| 264 | const auto error_num = errno; | ||
| 265 | if (error_num != 0 && file == nullptr) { | ||
| 266 | LOG_ERROR(Common_Filesystem, "Error opening file: {}, error: {}", path.c_str(), | ||
| 267 | strerror(error_num)); | ||
| 268 | } | ||
| 269 | } else { | ||
| 270 | LOG_ERROR(Common_Filesystem, "Error opening file: {}", path.c_str()); | ||
| 271 | } | ||
| 272 | } else { | ||
| 273 | file = std::fopen(path.c_str(), AccessModeToStr(mode, type)); | ||
| 274 | } | ||
| 255 | #else | 275 | #else |
| 256 | file = std::fopen(path.c_str(), AccessModeToStr(mode, type)); | 276 | file = std::fopen(path.c_str(), AccessModeToStr(mode, type)); |
| 257 | #endif | 277 | #endif |
| @@ -372,6 +392,23 @@ u64 IOFile::GetSize() const { | |||
| 372 | // Flush any unwritten buffered data into the file prior to retrieving the file size. | 392 | // Flush any unwritten buffered data into the file prior to retrieving the file size. |
| 373 | std::fflush(file); | 393 | std::fflush(file); |
| 374 | 394 | ||
| 395 | #if ANDROID | ||
| 396 | u64 file_size = 0; | ||
| 397 | if (Android::IsContentUri(file_path)) { | ||
| 398 | file_size = Android::GetSize(file_path); | ||
| 399 | } else { | ||
| 400 | std::error_code ec; | ||
| 401 | |||
| 402 | file_size = fs::file_size(file_path, ec); | ||
| 403 | |||
| 404 | if (ec) { | ||
| 405 | LOG_ERROR(Common_Filesystem, | ||
| 406 | "Failed to retrieve the file size of path={}, ec_message={}", | ||
| 407 | PathToUTF8String(file_path), ec.message()); | ||
| 408 | return 0; | ||
| 409 | } | ||
| 410 | } | ||
| 411 | #else | ||
| 375 | std::error_code ec; | 412 | std::error_code ec; |
| 376 | 413 | ||
| 377 | const auto file_size = fs::file_size(file_path, ec); | 414 | const auto file_size = fs::file_size(file_path, ec); |
| @@ -381,6 +418,7 @@ u64 IOFile::GetSize() const { | |||
| 381 | PathToUTF8String(file_path), ec.message()); | 418 | PathToUTF8String(file_path), ec.message()); |
| 382 | return 0; | 419 | return 0; |
| 383 | } | 420 | } |
| 421 | #endif | ||
| 384 | 422 | ||
| 385 | return file_size; | 423 | return file_size; |
| 386 | } | 424 | } |