mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-02-03 12:31:15 +00:00
Add support for .ini loading
This commit is contained in:
parent
41d9cca994
commit
e1173eb0d0
@ -8,10 +8,29 @@
|
|||||||
#include <SDL3/SDL_log.h>
|
#include <SDL3/SDL_log.h>
|
||||||
#include <emscripten/wasmfs.h>
|
#include <emscripten/wasmfs.h>
|
||||||
|
|
||||||
|
static backend_t opfs = nullptr;
|
||||||
|
static backend_t fetchfs = nullptr;
|
||||||
|
|
||||||
|
void Emscripten_SetupConfig(const char* p_iniConfig)
|
||||||
|
{
|
||||||
|
if (!p_iniConfig || !*p_iniConfig) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
opfs = wasmfs_create_opfs_backend();
|
||||||
|
MxString iniConfig = p_iniConfig;
|
||||||
|
|
||||||
|
char* parse = iniConfig.GetData();
|
||||||
|
while ((parse = SDL_strchr(++parse, '/'))) {
|
||||||
|
*parse = '\0';
|
||||||
|
wasmfs_create_directory(iniConfig.GetData(), 0644, opfs);
|
||||||
|
*parse = '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Emscripten_SetupFilesystem()
|
void Emscripten_SetupFilesystem()
|
||||||
{
|
{
|
||||||
auto fetchfs =
|
fetchfs = wasmfs_create_fetch_backend((MxString(Emscripten_streamHost) + MxString("/LEGO")).GetData(), 512 * 1024);
|
||||||
wasmfs_create_fetch_backend((MxString(Emscripten_streamHost) + MxString("/LEGO")).GetData(), 512 * 1024);
|
|
||||||
|
|
||||||
wasmfs_create_directory("/LEGO", 0644, fetchfs);
|
wasmfs_create_directory("/LEGO", 0644, fetchfs);
|
||||||
wasmfs_create_directory("/LEGO/Scripts", 0644, fetchfs);
|
wasmfs_create_directory("/LEGO/Scripts", 0644, fetchfs);
|
||||||
@ -26,7 +45,7 @@ void Emscripten_SetupFilesystem()
|
|||||||
wasmfs_create_directory("/LEGO/Scripts/Race", 0644, fetchfs);
|
wasmfs_create_directory("/LEGO/Scripts/Race", 0644, fetchfs);
|
||||||
wasmfs_create_directory("/LEGO/data", 0644, fetchfs);
|
wasmfs_create_directory("/LEGO/data", 0644, fetchfs);
|
||||||
|
|
||||||
const auto registerFile = [&fetchfs](const char* p_path) {
|
const auto registerFile = [](const char* p_path) {
|
||||||
MxString path = MxString(Emscripten_bundledPath) + MxString(p_path);
|
MxString path = MxString(Emscripten_bundledPath) + MxString(p_path);
|
||||||
path.MapPathToFilesystem();
|
path.MapPathToFilesystem();
|
||||||
|
|
||||||
@ -89,7 +108,9 @@ void Emscripten_SetupFilesystem()
|
|||||||
registerFile("/LEGO/data/testinf.dta");
|
registerFile("/LEGO/data/testinf.dta");
|
||||||
|
|
||||||
if (GameState()->GetSavePath() && *GameState()->GetSavePath()) {
|
if (GameState()->GetSavePath() && *GameState()->GetSavePath()) {
|
||||||
auto opfs = wasmfs_create_opfs_backend();
|
if (!opfs) {
|
||||||
|
opfs = wasmfs_create_opfs_backend();
|
||||||
|
}
|
||||||
|
|
||||||
MxString savePath = GameState()->GetSavePath();
|
MxString savePath = GameState()->GetSavePath();
|
||||||
if (savePath.GetData()[savePath.GetLength() - 1] != '/') {
|
if (savePath.GetData()[savePath.GetLength() - 1] != '/') {
|
||||||
|
|||||||
@ -10,6 +10,7 @@ inline static const char* Emscripten_savePath = "/save";
|
|||||||
inline static const char* Emscripten_streamPath = "/";
|
inline static const char* Emscripten_streamPath = "/";
|
||||||
inline static const char* Emscripten_streamHost = ISLE_EMSCRIPTEN_HOST;
|
inline static const char* Emscripten_streamHost = ISLE_EMSCRIPTEN_HOST;
|
||||||
|
|
||||||
|
void Emscripten_SetupConfig(const char* p_iniConfig);
|
||||||
void Emscripten_SetupFilesystem();
|
void Emscripten_SetupFilesystem();
|
||||||
|
|
||||||
#endif // EMSCRIPTEN_FILESYSTEM_H
|
#endif // EMSCRIPTEN_FILESYSTEM_H
|
||||||
|
|||||||
@ -721,6 +721,10 @@ bool IsleApp::LoadConfig()
|
|||||||
}
|
}
|
||||||
SDL_Log("Reading configuration from \"%s\"", iniConfig);
|
SDL_Log("Reading configuration from \"%s\"", iniConfig);
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
Emscripten_SetupConfig(iniConfig);
|
||||||
|
#endif
|
||||||
|
|
||||||
dictionary* dict = iniparser_load(iniConfig);
|
dictionary* dict = iniparser_load(iniConfig);
|
||||||
|
|
||||||
// [library:config]
|
// [library:config]
|
||||||
@ -996,5 +1000,6 @@ MxResult IsleApp::ParseArguments(int argc, char** argv)
|
|||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user