Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
games
doomretro
fix-iwad-search-path.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File fix-iwad-search-path.patch of Package doomretro
From 6266cb45c4749bb9352ff57664b6becfeb3d12ce Mon Sep 17 00:00:00 2001 From: bubbleguuum <bubbleguuum@free.fr> Date: Mon, 12 Aug 2024 16:47:01 +0200 Subject: [PATCH] fix IWAD search path issues on platforms other that Windows and macOS --- src/d_iwad.c | 7 +++-- src/m_misc.c | 87 +++++++++++++++++++++++++++++----------------------- 2 files changed, 54 insertions(+), 40 deletions(-) diff --git a/src/d_iwad.c b/src/d_iwad.c index 24132cf1a..766e6c8b5 100644 --- a/src/d_iwad.c +++ b/src/d_iwad.c @@ -499,11 +499,14 @@ static const iwads_t iwads[] = }; #if !defined(_WIN32) && !defined(__APPLE__) -// Returns true if the specified path is a path to a file +// Returns true if the specified path is a path to a WAD file // of the specified name. static bool DirIsFile(char *path, char *filename) { - return (strchr(path, DIR_SEPARATOR) && !strcasecmp(leafname(path), filename)); + char *filenamewithext = M_StringJoin(filename, ".wad", NULL); + bool ret = (strchr(path, DIR_SEPARATOR) && !strcasecmp(leafname(path), filenamewithext)); + free(filenamewithext); + return ret; } // Check if the specified directory contains the specified IWAD diff --git a/src/m_misc.c b/src/m_misc.c index a6afe4db2..d93394f13 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -123,61 +123,72 @@ bool M_FileExists(const char *filename) } #if !defined(_WIN32) && !defined(__APPLE__) + +bool file_exists_get_path(const char *basedir, const char *filename, char **retpath) { + *retpath = M_StringJoin(basedir, DIR_SEPARATOR_S, filename, NULL); + + if (M_FileExists(*retpath)) + return true; + + free(*retpath); + *retpath = NULL; + return false; +} + // Check if a file exists by probing for common case variation of its filename. // Returns a newly allocated string that the caller is responsible for freeing. char *M_FileCaseExists(const char *path) { - char *path_dup = M_StringDuplicate(path); - char *filename; - char *ufilename; - char *ext; + char *basedir; + char *filename; + char *retpath; + char *tmpfilename = NULL; + char *pos; // actual path - if (M_FileExists(path_dup)) - return path_dup; - - if ((filename = strrchr(path_dup, DIR_SEPARATOR))) - filename++; - else - filename = path_dup; + if (M_FileExists(path)) + return M_StringDuplicate(path); + + pos = strrchr(path, DIR_SEPARATOR); + if(pos) { + basedir = M_SubString(path, 0, pos-path); + filename = M_StringDuplicate(pos+1); + } else { + basedir = "."; + filename = M_StringDuplicate(path); + } // lowercase filename, e.g. doom2.wad - lowercase(filename); - - if (M_FileExists(path_dup)) - return path_dup; + if(file_exists_get_path(basedir, lowercase(filename), &retpath)) + goto cleanup; // uppercase filename, e.g. DOOM2.WAD - ufilename = uppercase(filename); + tmpfilename = uppercase(filename); + if(file_exists_get_path(basedir, tmpfilename, &retpath)) + goto cleanup; // uppercase basename with lowercase extension, e.g. DOOM2.wad - if ((ext = strrchr(path_dup, '.')) && ext > ufilename) - { - lowercase(ext + 1); - - if (M_FileExists(path_dup)) - { - free(ufilename); - return path_dup; - } + if ((pos = strrchr(tmpfilename, '.')) && tmpfilename[strlen(tmpfilename)-1] != '.') { + lowercase(pos + 1); + if(file_exists_get_path(basedir, tmpfilename, &retpath)) + goto cleanup; } // lowercase filename with uppercase first letter, e.g. Doom2.wad - if (strlen(ufilename) > 1) - { - lowercase(ufilename + 1); - - if (M_FileExists(path_dup)) - { - free(ufilename); - return path_dup; - } + if (strlen(tmpfilename) > 1) { + lowercase(tmpfilename + 1); + if(file_exists_get_path(basedir, tmpfilename, &retpath)) + goto cleanup; } - // no luck - free(ufilename); - free(path_dup); - return NULL; + cleanup: + free(filename); + if(tmpfilename) + free(tmpfilename); + if(strcmp(basedir, ".")) + free(basedir); + + return retpath; } #endif
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor