mirror of
https://github.com/kevinbentley/Descent3.git
synced 2025-01-22 11:28:56 +00:00
module: use cf_FindRealFileNameCaseInsensitive() instead duplicated
In mod_GetRealModuleName() there was error - arguments of mod_FindRealFileNameCaseInsensitive() is misplaced.
This commit is contained in:
parent
dc0cd880e4
commit
85cceef2af
@ -7,6 +7,7 @@ set(CPPS
|
|||||||
|
|
||||||
add_library(module STATIC ${HEADERS} ${CPPS})
|
add_library(module STATIC ${HEADERS} ${CPPS})
|
||||||
target_link_libraries(module PRIVATE
|
target_link_libraries(module PRIVATE
|
||||||
|
cfile
|
||||||
ddebug
|
ddebug
|
||||||
logger
|
logger
|
||||||
)
|
)
|
||||||
|
@ -101,55 +101,11 @@
|
|||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "cfile.h"
|
||||||
#include "crossplat.h"
|
#include "crossplat.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns fixed case file name to actual case on disk for case-sensitive filesystems (Linux).
|
|
||||||
* This is actually copy of cf_FindRealFileNameCaseInsensitive() from CFILE.
|
|
||||||
* @param fname the fixed case name to map to reality
|
|
||||||
* @param directory optional directory to search within (default - current path)
|
|
||||||
* @return filename with actual case name or empty path if there no mapping in filesystem
|
|
||||||
* @note This function returns only filename without directory part, i.e.
|
|
||||||
* mod_FindRealFileNameCaseInsensitive("test/test.txt") will return only "test.txt" on success.
|
|
||||||
*/
|
|
||||||
std::filesystem::path mod_FindRealFileNameCaseInsensitive(const std::filesystem::path &fname,
|
|
||||||
const std::filesystem::path &directory = ".") {
|
|
||||||
// Dumb check, maybe there already all ok?
|
|
||||||
if (std::filesystem::exists((directory / fname))) {
|
|
||||||
return fname.filename();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::filesystem::path result, search_path, search_file;
|
|
||||||
|
|
||||||
search_path = directory / fname.parent_path();
|
|
||||||
search_file = fname.filename();
|
|
||||||
|
|
||||||
// If directory does not exist, nothing to search.
|
|
||||||
if (!std::filesystem::is_directory(search_path) || search_file.empty()) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search component in search_path
|
|
||||||
auto const &it = std::filesystem::directory_iterator(search_path);
|
|
||||||
|
|
||||||
auto found = std::find_if(it, end(it), [&search_file, &search_path, &result](const auto &dir_entry) {
|
|
||||||
return stricmp(dir_entry.path().filename().u8string().c_str(), search_file.u8string().c_str()) == 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (found != end(it)) {
|
|
||||||
// Match, append to result
|
|
||||||
result = found->path();
|
|
||||||
search_path = result;
|
|
||||||
} else {
|
|
||||||
// Component not found, mission failed
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.filename();
|
|
||||||
}
|
|
||||||
|
|
||||||
int ModLastError = MODERR_NOERROR;
|
int ModLastError = MODERR_NOERROR;
|
||||||
|
|
||||||
std::filesystem::path mod_GetRealModuleName(const std::filesystem::path &mod_filename) {
|
std::filesystem::path mod_GetRealModuleName(const std::filesystem::path &mod_filename) {
|
||||||
@ -228,7 +184,7 @@ bool mod_LoadModule(module *handle, const std::filesystem::path &imodfilename, i
|
|||||||
if (!handle->handle) {
|
if (!handle->handle) {
|
||||||
// ok we couldn't find the given name...try other ways
|
// ok we couldn't find the given name...try other ways
|
||||||
std::filesystem::path parent_path = modfilename.parent_path();
|
std::filesystem::path parent_path = modfilename.parent_path();
|
||||||
std::filesystem::path new_filename = mod_FindRealFileNameCaseInsensitive(parent_path, modfilename.filename());
|
std::filesystem::path new_filename = cf_FindRealFileNameCaseInsensitive(modfilename.filename(), parent_path);
|
||||||
|
|
||||||
if (new_filename.empty()) {
|
if (new_filename.empty()) {
|
||||||
LOG_ERROR.printf("Module Load Err: %s", dlerror());
|
LOG_ERROR.printf("Module Load Err: %s", dlerror());
|
||||||
|
Loading…
Reference in New Issue
Block a user