From 422039f72783df75a1b12d35ce8da5d0efe987af Mon Sep 17 00:00:00 2001 From: yellows8 Date: Fri, 22 Oct 2021 13:15:41 -0400 Subject: [PATCH] Use physfs instead of minizip for asset loading, etc. --- Makefile.nx | 2 +- Makefile.pc | 2 +- common/assets.c | 115 +++++++++++++----------------------------------- common/assets.h | 2 +- common/theme.c | 4 +- 5 files changed, 36 insertions(+), 89 deletions(-) diff --git a/Makefile.nx b/Makefile.nx index 71b05ae..26618d9 100644 --- a/Makefile.nx +++ b/Makefile.nx @@ -63,7 +63,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions ASFLAGS := -g $(ARCH) LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) -LIBS := -ldeko3d -lminizip -lphysfs `freetype-config --libs` -lconfig -lturbojpeg -lpng +LIBS := -ldeko3d -lphysfs `freetype-config --libs` -lconfig -lturbojpeg -lpng #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing diff --git a/Makefile.pc b/Makefile.pc index a58074d..41d636c 100644 --- a/Makefile.pc +++ b/Makefile.pc @@ -14,7 +14,7 @@ test : pc_main/main.cpp pc_main/pc_launch.c pc_main/pc_power.c pc_main/pc_netsta common/menu-entry.c common/menu-list.c common/message-box.c common/text.c \ common/ui.c common/assets.c common/math.c common/theme.c \ common/netloader.c - gcc -Wall -O2 -g -DVERSION=\"v$(APP_VERSION)\" $(EXTRA_CFLAGS) `pkg-config freetype2 --cflags` $^ -lsfml-graphics -lsfml-window -lsfml-system -lstdc++ -lpthread `pkg-config freetype2 --libs` -lm -lminizip -lphysfs -lz -lconfig -lturbojpeg -lpng $(EXTRA_LDFLAGS) -I. -iquote $(DEVKITPRO)/libnx/include -Ibuild_pc -g -o $@ + gcc -Wall -O2 -g -DVERSION=\"v$(APP_VERSION)\" $(EXTRA_CFLAGS) `pkg-config freetype2 --cflags` $^ -lsfml-graphics -lsfml-window -lsfml-system -lstdc++ -lpthread `pkg-config freetype2 --libs` -lm -lphysfs -lz -lconfig -lturbojpeg -lpng $(EXTRA_LDFLAGS) -I. -iquote $(DEVKITPRO)/libnx/include -Ibuild_pc -g -o $@ clean: rm -rf build_pc/ test test.* diff --git a/common/assets.c b/common/assets.c index 941b099..b65b52b 100644 --- a/common/assets.c +++ b/common/assets.c @@ -1,6 +1,5 @@ #include "common.h" -#include #include #include @@ -47,59 +46,9 @@ static void assetsSetPixelSize(assetsDataEntry *entry) { } } -static int assetsLoadFile(unzFile zipf, assetsDataEntry *entry) { - int ret; - int filesize=0; - unz_file_info file_info; - u8* buffer = NULL; - - assetsSetPixelSize(entry); - - ret = unzLocateFile(zipf, entry->path, 0); - - if (ret==UNZ_OK) ret = unzOpenCurrentFile(zipf); - - if (ret==UNZ_OK) { - ret = unzGetCurrentFileInfo(zipf, &file_info, NULL, 0, NULL, 0, NULL, 0); - - filesize = file_info.uncompressed_size; - if (filesize != entry->imageSize[0] * entry->imageSize[1] * entry->pixSize) ret = -10; - - if (ret==UNZ_OK) { - buffer = (u8*)malloc(filesize); - if (buffer) { - memset(buffer, 0, filesize); - } else { - ret = -11; - } - } - - if (ret==UNZ_OK) { - ret = unzReadCurrentFile(zipf, buffer, filesize); - if(ret < filesize) { - ret = -12; - } else { - ret = UNZ_OK; - } - } - - if (ret!=UNZ_OK && buffer!=NULL) free(buffer); - - unzCloseCurrentFile(zipf); - } - - if (ret==UNZ_OK) { - entry->buffer = buffer; - entry->size = filesize; - } - - return ret; -} - Result assetsInit(void) { - int ret=0; + bool ret=false; int i, stopi; - unzFile zipf; assetsDataEntry *entry = NULL; char tmp_path[PATH_MAX]; @@ -118,40 +67,34 @@ Result assetsInit(void) { snprintf(tmp_path, sizeof(tmp_path)-1, "%s/romfs/assets.zip", menuGetRootBasePath()); #endif - zipf = unzOpen(tmp_path); - if(zipf==NULL) { - #ifdef __SWITCH__ - romfsExit(); - #endif - - return 0x80; - } - - for (i=0; ipath[0]) { - ret = assetsLoadFile(zipf, entry); - if (ret!=UNZ_OK) break; - entry->initialized = true; + if (PHYSFS_mount(tmp_path, "", 0)) { + ret=true; + for (i=0; ipath[0]) { + ret = assetsLoadData(i, NULL, NULL); + if (!ret) break; + } } - } - if (ret!=UNZ_OK) { - for (i=0; i= AssetId_Max) return false; - assetsDataEntry *entry = &g_assetsDataList[id][1]; + assetsDataEntry *entry = &g_assetsDataList[id][path ? 1 : 0]; if (entry->initialized) return false; - memset(entry, 0, sizeof(*entry)); + if (path) memset(entry, 0, sizeof(*entry)); - entry->imageSize[0] = imageSize[0]; - entry->imageSize[1] = imageSize[1]; + if (imageSize) { + entry->imageSize[0] = imageSize[0]; + entry->imageSize[1] = imageSize[1]; + } - entry->imageMode = g_assetsDataList[id][0].imageMode; + if (path) entry->imageMode = g_assetsDataList[id][0].imageMode; assetsSetPixelSize(entry); entry->size = entry->imageSize[0] * entry->imageSize[1] * entry->pixSize; - strncpy(entry->path, path, sizeof(entry->path)-1); + if (path) strncpy(entry->path, path, sizeof(entry->path)-1); const char* ext = getExtension(entry->path); bool ret=true; diff --git a/common/assets.h b/common/assets.h index fdf4b9c..88fce6e 100644 --- a/common/assets.h +++ b/common/assets.h @@ -36,7 +36,7 @@ Result assetsInit(void); void assetsExit(void); void assetsClearTheme(void); bool assetsPhysfsReadFile(const char *path, u8 **data_buf, size_t *filesize, bool nul_term); -bool assetsLoadFromTheme(AssetId id, const char *path, int *imageSize); +bool assetsLoadData(AssetId id, const char *path, int *imageSize); void assetsGetData(AssetId id, assetsDataEntry **out); u8 *assetsGetDataBuffer(AssetId id); diff --git a/common/theme.c b/common/theme.c index a86a1c7..acda944 100644 --- a/common/theme.c +++ b/common/theme.c @@ -85,7 +85,7 @@ bool assetObjectFromSetting(config_setting_t *asset_setting, AssetId id, ThemeLa memset(tmp_path, 0, sizeof(tmp_path)); snprintf(tmp_path, sizeof(tmp_path)-1, "theme/%s", path); - return assetsLoadFromTheme(id, tmp_path, imageSize); + return assetsLoadData(id, tmp_path, imageSize); } void themeStartup(ThemePreset preset) { @@ -420,7 +420,9 @@ void themeStartup(ThemePreset preset) { const char *AText, *BText, *XText, *YText, *PText, *MText, *starOnText, *starOffText; bool logoColor_set = false; bool good_cfg = false; + #ifdef __SWITCH__ bool is_romfs = false; + #endif bool is_archive = false; const char* theme_archive_path = NULL;