Skip to content

Commit

Permalink
Add handling for Android content URIs to VFSReadFile, fixing savestat…
Browse files Browse the repository at this point in the history
…e thumbnails.
  • Loading branch information
hrydgard committed Jul 19, 2021
1 parent b0558b2 commit e1b4a91
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Common/Data/Format/JSONReader.cpp
@@ -1,4 +1,5 @@
#include "Common/File/VFS/VFS.h"
#include "Common/File/Path.h"
#include "Common/File/FileUtil.h"
#include "Common/Data/Format/JSONReader.h"

Expand All @@ -11,7 +12,7 @@ JsonReader::JsonReader(const std::string &filename) {
parse();
} else {
// Okay, try to read on the local file system
buffer_ = (char *)File::ReadLocalFile(filename.c_str(), &buf_size);
buffer_ = (char *)File::ReadLocalFile(Path(filename), &buf_size);
if (buffer_) {
parse();
} else {
Expand Down
6 changes: 2 additions & 4 deletions Common/File/FileUtil.cpp
Expand Up @@ -987,10 +987,8 @@ bool ReadFileToString(bool text_file, const Path &filename, std::string &str) {
return success;
}

// This is an odd one, mainly used for asset reading, so doesn't really
// need to support Path.
uint8_t *ReadLocalFile(const char *filename, size_t * size) {
FILE *file = File::OpenCFile(Path(filename), "rb");
uint8_t *ReadLocalFile(const Path &filename, size_t *size) {
FILE *file = File::OpenCFile(filename, "rb");
if (!file) {
*size = 0;
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion Common/File/FileUtil.h
Expand Up @@ -201,6 +201,6 @@ bool WriteDataToFile(bool text_file, const void* data, const unsigned int size,

bool ReadFileToString(bool text_file, const Path &filename, std::string &str);
// Return value must be delete[]-d.
uint8_t *ReadLocalFile(const char *filename, size_t *size);
uint8_t *ReadLocalFile(const Path &filename, size_t *size);

} // namespace
2 changes: 1 addition & 1 deletion Common/File/VFS/AssetReader.cpp
Expand Up @@ -172,7 +172,7 @@ DirectoryAssetReader::DirectoryAssetReader(const Path &path) {

uint8_t *DirectoryAssetReader::ReadAsset(const char *path, size_t *size) {
Path new_path = Path(path).StartsWith(path_) ? Path(path) : path_ / path;
return File::ReadLocalFile(new_path.c_str(), size);
return File::ReadLocalFile(new_path, size);
}

bool DirectoryAssetReader::GetFileListing(const char *path, std::vector<File::FileInfo> *listing, const char *filter = nullptr) {
Expand Down
6 changes: 4 additions & 2 deletions Common/File/VFS/VFS.cpp
@@ -1,6 +1,7 @@
#include "Common/Log.h"
#include "Common/File/VFS/VFS.h"
#include "Common/File/VFS/AssetReader.h"
#include "Common/File/AndroidStorage.h"

struct VFSEntry {
const char *prefix;
Expand Down Expand Up @@ -32,15 +33,16 @@ static bool IsLocalAbsolutePath(const char *path) {
#else
bool isWindowsLocal = false;
#endif
return isUnixLocal || isWindowsLocal;
bool isContentURI = Android_IsContentUri(path);
return isUnixLocal || isWindowsLocal || isContentURI;
}

// The returned data should be free'd with delete[].
uint8_t *VFSReadFile(const char *filename, size_t *size) {
if (IsLocalAbsolutePath(filename)) {
// Local path, not VFS.
// INFO_LOG(IO, "Not a VFS path: %s . Reading local file.", filename);
return File::ReadLocalFile(filename, size);
return File::ReadLocalFile(Path(filename), size);
}

int fn_len = (int)strlen(filename);
Expand Down
4 changes: 2 additions & 2 deletions Common/GPU/OpenGL/GLSLProgram.cpp
Expand Up @@ -104,7 +104,7 @@ bool glsl_recompile(GLSLProgram *program, std::string *error_message) {
program->vshader_mtime = vs.st_mtime;
if (!program->vshader_source) {
size_t sz;
vsh_src.reset((char *)File::ReadLocalFile(program->vshader_filename, &sz));
vsh_src.reset((char *)File::ReadLocalFile(Path(program->vshader_filename), &sz));
}
} else {
program->vshader_mtime = 0;
Expand All @@ -114,7 +114,7 @@ bool glsl_recompile(GLSLProgram *program, std::string *error_message) {
program->fshader_mtime = fs.st_mtime;
if (!program->fshader_source) {
size_t sz;
fsh_src.reset((char *)File::ReadLocalFile(program->fshader_filename, &sz));
fsh_src.reset((char *)File::ReadLocalFile(Path(program->fshader_filename), &sz));
}
} else {
program->fshader_mtime = 0;
Expand Down

0 comments on commit e1b4a91

Please sign in to comment.