From d75127e9c24bd8b3c5e586afb4f79db9cd0452a9 Mon Sep 17 00:00:00 2001 From: tunip3 <26260613+tunip3@users.noreply.github.com> Date: Tue, 26 Oct 2021 00:43:44 +0100 Subject: [PATCH] Fix issue where files over 2.5gb approx would fail to load on uwp/xbox (#13150) * fix issue where files over 2.5 gb would fail to read * fix issue where trying to get the file size on excessively large files would fail --- .../vfs/vfs_implementation_uwp.cpp | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/libretro-common/vfs/vfs_implementation_uwp.cpp b/libretro-common/vfs/vfs_implementation_uwp.cpp index 50fb1cbb92..3f844c842f 100644 --- a/libretro-common/vfs/vfs_implementation_uwp.cpp +++ b/libretro-common/vfs/vfs_implementation_uwp.cpp @@ -158,9 +158,16 @@ int64_t retro_vfs_file_truncate_impl(libretro_vfs_implementation_file* stream, i int64_t retro_vfs_file_tell_impl(libretro_vfs_implementation_file* stream) { - if (!stream) + if (!stream || (!stream->fp && stream->fh == INVALID_HANDLE_VALUE)) return -1; + if (stream->fh != INVALID_HANDLE_VALUE) + { + LARGE_INTEGER sz; + if (GetFileSizeEx(stream->fh, &sz)) + return sz.QuadPart; + return 0; + } if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0) { return ftell(stream->fp); @@ -213,8 +220,15 @@ int64_t retro_vfs_file_seek_impl(libretro_vfs_implementation_file* stream, int64_t retro_vfs_file_read_impl(libretro_vfs_implementation_file* stream, void* s, uint64_t len) { - if (!stream || !s) - return -1; + if (!stream || (!stream->fp && stream->fh == INVALID_HANDLE_VALUE) || !s) + return -1; + + if (stream->fh != INVALID_HANDLE_VALUE) + { + DWORD _bytes_read; + ReadFile(stream->fh, (char*)s, len, &_bytes_read, NULL); + return (int64_t)_bytes_read; + } if ((stream->hints & RFILE_HINT_UNBUFFERED) == 0) {