Fix files in archives not loading for no good reason

This commit is contained in:
Inori 2019-08-05 16:24:16 -04:00
parent e2d9741b6f
commit 3ab0a2a430
2 changed files with 17 additions and 2 deletions

View file

@ -79,7 +79,7 @@ RB_METHOD(fileIntRead)
{ {
int length = -1; int length = -1;
rb_get_args(argc, argv, "i", &length RB_ARG_END); rb_get_args(argc, argv, "|i", &length RB_ARG_END);
SDL_RWops *ops = getPrivateData<SDL_RWops>(self); SDL_RWops *ops = getPrivateData<SDL_RWops>(self);
@ -87,6 +87,12 @@ RB_METHOD(fileIntRead)
{ {
Sint64 cur = SDL_RWtell(ops); Sint64 cur = SDL_RWtell(ops);
Sint64 end = SDL_RWseek(ops, 0, SEEK_END); Sint64 end = SDL_RWseek(ops, 0, SEEK_END);
// Sometimes SDL_RWseek will fail for no reason
// with encrypted archives, so let's just ask
// for the size up front
if (end < 0) end = ops->size(ops);
length = end - cur; length = end - cur;
SDL_RWseek(ops, cur, SEEK_SET); SDL_RWseek(ops, cur, SEEK_SET);
} }

View file

@ -689,7 +689,16 @@ void FileSystem::openReadRaw(SDL_RWops &ops,
bool freeOnClose) bool freeOnClose)
{ {
PHYSFS_File *handle = PHYSFS_openRead(filename); PHYSFS_File *handle = PHYSFS_openRead(filename);
// assert(handle); // Ruby exceptions are a little more helpful
// Not sure what to do with this assert, I feel like
// I should throw an exception for the binding but
// Essentials pings for files that don't exist
// I'll have to look at it later, but it works fine
// like this so I'll leave it commented out for now
// assert(handle);
initReadOps(handle, ops, freeOnClose); initReadOps(handle, ops, freeOnClose);
} }