summaryrefslogtreecommitdiff
path: root/jni
diff options
context:
space:
mode:
Diffstat (limited to 'jni')
-rw-r--r--jni/physfs-serve-sdl-wrap.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/jni/physfs-serve-sdl-wrap.c b/jni/physfs-serve-sdl-wrap.c
index c0de9df..92b2290 100644
--- a/jni/physfs-serve-sdl-wrap.c
+++ b/jni/physfs-serve-sdl-wrap.c
@@ -4,6 +4,7 @@
#include <unistd.h>
#include <string.h>
#include <stdio.h>
+#include <assert.h>
static void ignore_ret(bool b, ...) {};
#define ignore_ret(x) ignore_ret(true, x);
@@ -117,28 +118,27 @@ content_type(struct physfs_serve *serve, const char *path) {
}
static bool
+replace_ext(char buf[], const size_t bufsz, const char *old, const char *new) {
+ if (!physfs_ends_with(buf, old)) return false;
+ size_t len = strlen(buf);
+ assert(len >= strlen(old));
+ len -= strlen(old);
+ assert(bufsz >= len);
+ snprintf(buf + len, bufsz - len, "%s", new);
+ return true;
+}
+
+static bool
path_rewrite(struct physfs_serve *serve, char buf[], const size_t bufsz, struct PHYSFS_Stat *st) {
if (physfs_default_path_rewrite(serve, buf, bufsz, st)) return true;
- if (physfs_ends_with(buf, ".rpgmvm")) {
- buf[strlen(buf) - 1] = 'o';
- if (st->filetype == -1 && PHYSFS_stat(buf, st)) return false;
- } else if (physfs_ends_with(buf, ".rpgmvo")) {
- buf[strlen(buf) - 1] = 'm';
- if (st->filetype == -1 && PHYSFS_stat(buf, st)) return false;
- } else if (physfs_ends_with(buf, ".webm")) {
- buf[strlen(buf) - 1] = 0;
- buf[strlen(buf) - 2] = '4';
- buf[strlen(buf) - 3] = 'p';
- buf[strlen(buf) - 4] = 'm';
- if (st->filetype == -1 && PHYSFS_stat(buf, st)) return false;
- } else if (physfs_ends_with(buf, ".mp4")) {
- buf[strlen(buf) + 2] = 0;
- buf[strlen(buf) + 1] = 'm';
- buf[strlen(buf)] = 'b';
- buf[strlen(buf) - 1] = 'e';
- buf[strlen(buf) - 2] = 'w';
- if (st->filetype == -1 && PHYSFS_stat(buf, st)) return false;
- }
+ if (st->filetype != -1) return false;
+ if (replace_ext(buf, bufsz, ".rpgmvm", ".rpgmvo")) return PHYSFS_stat(buf, st);
+ else if (replace_ext(buf, bufsz, ".rpgmvo", ".rpgmvm")) return PHYSFS_stat(buf, st);
+ else if (replace_ext(buf, bufsz, ".webm", ".mp4")) return PHYSFS_stat(buf, st);
+ else if (replace_ext(buf, bufsz, ".mp4", ".webm")) return PHYSFS_stat(buf, st);
+ else if (replace_ext(buf, bufsz, ".png", ".rpgmvp")) return PHYSFS_stat(buf, st);
+ else if (replace_ext(buf, bufsz, ".ogg", ".rpgmvo")) return PHYSFS_stat(buf, st);
+ else if (replace_ext(buf, bufsz, ".mp4", ".rpgmvm")) return PHYSFS_stat(buf, st);
return false;
}