Browse Source

Search app assets folder in SFileOpenFile

pull/3080/head
obligaron 5 years ago committed by Anders Jenbo
parent
commit
8dd5fcfc8f
  1. 2
      Source/init.cpp
  2. 14
      Source/storm/storm.cpp
  3. 1
      Source/storm/storm.h

2
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()

14
Source/storm/storm.cpp

@ -32,6 +32,7 @@ namespace {
bool directFileAccess = false;
std::optional<std::string> SBasePath;
std::optional<std::string> 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<unsigned char>(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;

1
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);

Loading…
Cancel
Save