mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-04 14:05:32 +02:00
Bind checking case insensitive filenames from Ruby
This commit is contained in:
parent
19389a580f
commit
89da4f3b8c
3 changed files with 25 additions and 2 deletions
|
@ -250,6 +250,17 @@ RB_METHOD(_marshalLoad) {
|
|||
}
|
||||
#endif
|
||||
|
||||
RB_METHOD(fileIntDesensitize) {
|
||||
RB_UNUSED_PARAM;
|
||||
|
||||
VALUE filename;
|
||||
rb_scan_args(argc, argv, "1", &filename);
|
||||
SafeStringValue(filename);
|
||||
|
||||
return rb_str_new_cstr(
|
||||
shState->fileSystem().desensitize(RSTRING_PTR(filename)));
|
||||
}
|
||||
|
||||
void fileIntBindingInit() {
|
||||
VALUE klass = rb_define_class("FileInt", rb_cIO);
|
||||
#if RAPI_FULL > 187
|
||||
|
@ -269,6 +280,7 @@ void fileIntBindingInit() {
|
|||
#endif
|
||||
_rb_define_method(klass, "binmode", fileIntBinmode);
|
||||
_rb_define_method(klass, "close", fileIntClose);
|
||||
rb_define_singleton_method(klass, "desensitize", RUBY_METHOD_FUNC(fileIntDesensitize), -1);
|
||||
|
||||
_rb_define_module_function(rb_mKernel, "load_data", kernelLoadData);
|
||||
_rb_define_module_function(rb_mKernel, "save_data", kernelSaveData);
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#define FILESYSTEM_H
|
||||
|
||||
#include <SDL_rwops.h>
|
||||
#include <string>
|
||||
|
||||
struct FileSystemPrivate;
|
||||
class SharedFontState;
|
||||
|
@ -69,6 +70,8 @@ public:
|
|||
/* Does not perform extension supplementing */
|
||||
bool exists(const char *filename);
|
||||
|
||||
const char *desensitize(const char *filename);
|
||||
|
||||
private:
|
||||
FileSystemPrivate *p;
|
||||
};
|
||||
|
|
|
@ -622,10 +622,11 @@ void FileSystem::openRead(OpenHandler &handler, const char *filename) {
|
|||
throw Exception(Exception::NoFileError, "%s", filename);
|
||||
}
|
||||
|
||||
// FIXME: This is (a) slower than RGSS and (b) case-sensitive
|
||||
// FIXME: This is slower than RGSS
|
||||
void FileSystem::openReadRaw(SDL_RWops &ops, const char *filename,
|
||||
bool freeOnClose) {
|
||||
PHYSFS_File *handle = PHYSFS_openRead(filename);
|
||||
|
||||
PHYSFS_File *handle = PHYSFS_openRead(desensitize(filename));
|
||||
|
||||
// assert(handle);
|
||||
if (!handle)
|
||||
|
@ -669,3 +670,10 @@ char *FileSystem::normalize(const char *pathname, bool preferred,
|
|||
bool FileSystem::exists(const char *filename) {
|
||||
return PHYSFS_exists(filename);
|
||||
}
|
||||
|
||||
const char *FileSystem::desensitize(const char *filename) {
|
||||
OFString *fn_lower = @(filename).lowercaseString;
|
||||
if (p->havePathCache && p->pathCache.contains(fn_lower.UTF8String))
|
||||
return p->pathCache[fn_lower.UTF8String].c_str();
|
||||
return filename;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue