From 21abe6ff9a7e50df69946f89b2cfa3e2b36d991d Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Sun, 4 Aug 2024 22:25:17 -0700 Subject: [PATCH] movie: load case-insensitive filename --- include/xsystem4.h | 1 + src/movie_ffmpeg.c | 8 +++++++- src/movie_plmpeg.c | 7 ++++++- src/util.c | 12 ++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/xsystem4.h b/include/xsystem4.h index f23fc0a..b91536e 100644 --- a/include/xsystem4.h +++ b/include/xsystem4.h @@ -67,6 +67,7 @@ void log_message(const char *log, const char *fmt, ...); char *unix_path(const char *path); char *gamedir_path(const char *path); +char *gamedir_path_icase(const char *path); char *savedir_path(const char *path); void get_date(int *year, int *month, int *mday, int *wday); diff --git a/src/movie_ffmpeg.c b/src/movie_ffmpeg.c index 57198ba..1017512 100644 --- a/src/movie_ffmpeg.c +++ b/src/movie_ffmpeg.c @@ -168,6 +168,7 @@ static int audio_callback(sts_mixer_sample_t *sample, void *data) assert(sample == &mc->sts_stream.sample); if (!decode_frame(&mc->audio, mc)) { + NOTICE("???"); free(sample->data); sample->length = 0; sample->data = NULL; @@ -206,7 +207,12 @@ struct movie_context *movie_load(const char *filename) { struct movie_context *mc = xcalloc(1, sizeof(struct movie_context)); mc->voice = -1; - char *path = gamedir_path(filename); + char *path = gamedir_path_icase(filename); + if (!path) { + WARNING("%s: file does not exist", filename); + movie_free(mc); + return NULL; + } int ret; if ((ret = avformat_open_input(&mc->format_ctx, path, NULL, NULL)) != 0) { WARNING("%s: avformat_open_input failed: %d", path, ret); diff --git a/src/movie_plmpeg.c b/src/movie_plmpeg.c index 9840df5..4f0b02d 100644 --- a/src/movie_plmpeg.c +++ b/src/movie_plmpeg.c @@ -112,7 +112,12 @@ struct movie_context *movie_load(const char *filename) { struct movie_context *mc = xcalloc(1, sizeof(struct movie_context)); mc->voice = -1; - char *path = gamedir_path(filename); + char *path = gamedir_path_icase(filename); + if (!path) { + WARNING("%s: file does not exist", filename); + movie_free(mc); + return NULL; + } FILE *fp = file_open_utf8(path, "rb"); if (!fp) { WARNING("%s: %s", path, strerror(errno)); diff --git a/src/util.c b/src/util.c index 695be0e..573c303 100644 --- a/src/util.c +++ b/src/util.c @@ -23,6 +23,7 @@ #include #include "system4.h" +#include "system4/file.h" #include "system4/utfsjis.h" #include "xsystem4.h" @@ -146,6 +147,17 @@ char *gamedir_path(const char *path) return resolve_path(config.game_dir, path); } +char *gamedir_path_icase(const char *path) +{ + char *resolved = resolve_path(config.game_dir, path); + if (!file_exists(resolved)) { + char *tmp = path_get_icase(resolved); + free(resolved); + resolved = tmp; + } + return resolved; +} + char *savedir_path(const char *path) { return resolve_path(config.save_dir, path);