Webclient: Read default texture pack in less hacky way

This commit is contained in:
UnknownShadow200 2020-11-29 14:23:32 +11:00
parent dbbf0cbc66
commit bfd9c01e89
2 changed files with 10 additions and 22 deletions

View File

@ -1492,16 +1492,11 @@ void SaveLevelScreen_Show(void) {
*---------------------------------------------------TexturePackScreen-----------------------------------------------------*
*#########################################################################################################################*/
static void TexturePackScreen_EntryClick(void* screen, void* widget) {
cc_string path; char pathBuffer[FILENAME_SIZE];
struct ListScreen* s = (struct ListScreen*)screen;
cc_string relPath;
relPath = ListScreen_UNSAFE_GetCur(s, widget);
String_InitArray(path, pathBuffer);
String_Format1(&path, "texpacks/%s", &relPath);
if (!File_Exists(&path)) return;
TexturePack_SetDefault(&relPath);
cc_string file = ListScreen_UNSAFE_GetCur(s, widget);
if (String_CaselessEqualsConst(&file, LISTSCREEN_EMPTY)) return;
TexturePack_SetDefault(&file);
TexturePack_Url.length = 0;
TexturePack_ExtractCurrent(true);
}

View File

@ -337,17 +337,14 @@ static void ExtractFromFile(const cc_string* filename) {
struct Stream stream;
cc_result res;
/* TODO: This is an ugly hack to load textures from memory. */
/* We need to mount /classicube to IndexedDB, but texpacks folder */
/* should be read from memory. I don't know how to do that, */
/* since mounting /classicube/texpacks to memory doesn't work.. */
#ifdef CC_BUILD_WEB
extern int chdir(const char* path);
chdir("/");
#endif
String_InitArray(path, pathBuffer);
#ifdef CC_BUILD_WEB
/* texpacks/default.zip must be read from memory */
/* instead of the default filesystem */
String_Format1(&path, "/texpacks/%s", filename);
#else
String_Format1(&path, "texpacks/%s", filename);
#endif
res = Stream_OpenFile(&stream, &path);
if (res) { Logger_SysWarn2(res, "opening", &path); return; }
@ -355,10 +352,6 @@ static void ExtractFromFile(const cc_string* filename) {
res = stream.Close(&stream);
if (res) { Logger_SysWarn2(res, "closing", &path); }
#ifdef CC_BUILD_WEB
Platform_SetDefaultCurrentDirectory(0, NULL);
#endif
}
static void ExtractDefault(void) {