From 8dd5fcfc8f297a9ce136036ddba944b3e7397ea4 Mon Sep 17 00:00:00 2001 From: obligaron Date: Sat, 9 Oct 2021 20:49:39 +0200 Subject: [PATCH] Search app assets folder in SFileOpenFile --- Source/init.cpp | 2 ++ Source/storm/storm.cpp | 14 ++++++++++++++ Source/storm/storm.h | 1 + 3 files changed, 17 insertions(+) diff --git a/Source/init.cpp b/Source/init.cpp index 03310355b..e7a81a74f 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -217,6 +217,8 @@ void init_archives() UiErrorOkDialog(_("Some Hellfire MPQs are missing"), _("Not all Hellfire MPQs were found.\nPlease copy all the hf*.mpq files.")); app_fatal(nullptr); } + + SFileSetAssetsPath(paths::AppPath() + "assets/"); } void init_create_window() diff --git a/Source/storm/storm.cpp b/Source/storm/storm.cpp index 5914e8b35..1d9590dbe 100644 --- a/Source/storm/storm.cpp +++ b/Source/storm/storm.cpp @@ -32,6 +32,7 @@ namespace { bool directFileAccess = false; std::optional SBasePath; +std::optional AssetsPath; SdlMutex Mutex; @@ -128,6 +129,14 @@ bool SFileOpenFile(const char *filename, HANDLE *phFile) result = SFileOpenFileEx((HANDLE)diabdat_mpq, filename, SFILE_OPEN_FROM_MPQ, phFile); } + // As last fallback always search app content folder + if (!result && AssetsPath) { + std::string path = *AssetsPath + filename; + for (std::size_t i = SBasePath->size(); i < path.size(); ++i) + path[i] = AsciiToLowerTable_Path[static_cast(path[i])]; + result = SFileOpenFileEx((HANDLE) nullptr, path.c_str(), SFILE_OPEN_LOCAL_FILE, phFile); + } + if (!result || (*phFile == nullptr)) { const auto error = SErrGetLastError(); if (error == STORM_ERROR_FILE_NOT_FOUND) { @@ -154,6 +163,11 @@ void SFileSetBasePath(string_view path) SBasePath.emplace(path); } +void SFileSetAssetsPath(string_view path) +{ + AssetsPath.emplace(path); +} + bool SFileEnableDirectAccess(bool enable) { directFileAccess = enable; diff --git a/Source/storm/storm.h b/Source/storm/storm.h index ed907f4ad..acb60d32f 100644 --- a/Source/storm/storm.h +++ b/Source/storm/storm.h @@ -247,6 +247,7 @@ void SErrSetLastError(uint32_t dwErrCode); void SStrCopy(char *dest, const char *src, int max_length); void SFileSetBasePath(string_view path); +void SFileSetAssetsPath(string_view path); bool SNetGetOwnerTurnsWaiting(uint32_t *); bool SNetUnregisterEventHandler(event_type); bool SNetRegisterEventHandler(event_type, SEVTHANDLER);