Use physfs instead of minizip for asset loading, etc.

This commit is contained in:
yellows8 2021-10-22 13:15:41 -04:00
parent 3f73855170
commit 422039f727
No known key found for this signature in database
GPG Key ID: 0AF90DA3F1E60E43
5 changed files with 36 additions and 89 deletions

View File

@ -63,7 +63,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH) ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) 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 # list of directories containing libraries, this must be the top level containing

View File

@ -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/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/ui.c common/assets.c common/math.c common/theme.c \
common/netloader.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: clean:
rm -rf build_pc/ test test.* rm -rf build_pc/ test test.*

View File

@ -1,6 +1,5 @@
#include "common.h" #include "common.h"
#include <minizip/unzip.h>
#include <physfs.h> #include <physfs.h>
#include <png.h> #include <png.h>
@ -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) { Result assetsInit(void) {
int ret=0; bool ret=false;
int i, stopi; int i, stopi;
unzFile zipf;
assetsDataEntry *entry = NULL; assetsDataEntry *entry = NULL;
char tmp_path[PATH_MAX]; char tmp_path[PATH_MAX];
@ -118,40 +67,34 @@ Result assetsInit(void) {
snprintf(tmp_path, sizeof(tmp_path)-1, "%s/romfs/assets.zip", menuGetRootBasePath()); snprintf(tmp_path, sizeof(tmp_path)-1, "%s/romfs/assets.zip", menuGetRootBasePath());
#endif #endif
zipf = unzOpen(tmp_path); if (PHYSFS_mount(tmp_path, "", 0)) {
if(zipf==NULL) { ret=true;
#ifdef __SWITCH__ for (i=0; i<AssetId_Max; i++) {
romfsExit(); stopi = i;
#endif entry = &g_assetsDataList[i][0];
if (entry->path[0]) {
return 0x80; ret = assetsLoadData(i, NULL, NULL);
} if (!ret) break;
}
for (i=0; i<AssetId_Max; i++) {
stopi = i;
entry = &g_assetsDataList[i][0];
if (entry->path[0]) {
ret = assetsLoadFile(zipf, entry);
if (ret!=UNZ_OK) break;
entry->initialized = true;
} }
}
if (ret!=UNZ_OK) { if (!ret) {
for (i=0; i<stopi; i++) { for (i=0; i<stopi; i++) {
assetsClearEntry(&g_assetsDataList[i][0]); assetsClearEntry(&g_assetsDataList[i][0]);
}
} }
if (ret) g_assetsInitialized = 1;
PHYSFS_unmount(tmp_path);
} }
if (ret==UNZ_OK) g_assetsInitialized = 1;
unzClose(zipf);
#ifdef __SWITCH__ #ifdef __SWITCH__
romfsExit(); romfsExit();
return ret ? 0 : MAKERESULT(Module_Libnx, LibnxError_IoError);
#else
return ret ? 0 : 1;
#endif #endif
return ret;
} }
void assetsExit(void) { void assetsExit(void) {
@ -260,22 +203,24 @@ bool assetsPhysfsReadFile(const char *path, u8 **data_buf, size_t *filesize, boo
return ret; return ret;
} }
bool assetsLoadFromTheme(AssetId id, const char *path, int *imageSize) { bool assetsLoadData(AssetId id, const char *path, int *imageSize) {
if (id < 0 || id >= AssetId_Max) return false; if (id < 0 || id >= AssetId_Max) return false;
assetsDataEntry *entry = &g_assetsDataList[id][1]; assetsDataEntry *entry = &g_assetsDataList[id][path ? 1 : 0];
if (entry->initialized) return false; if (entry->initialized) return false;
memset(entry, 0, sizeof(*entry)); if (path) memset(entry, 0, sizeof(*entry));
entry->imageSize[0] = imageSize[0]; if (imageSize) {
entry->imageSize[1] = imageSize[1]; 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); assetsSetPixelSize(entry);
entry->size = entry->imageSize[0] * entry->imageSize[1] * entry->pixSize; 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); const char* ext = getExtension(entry->path);
bool ret=true; bool ret=true;

View File

@ -36,7 +36,7 @@ Result assetsInit(void);
void assetsExit(void); void assetsExit(void);
void assetsClearTheme(void); void assetsClearTheme(void);
bool assetsPhysfsReadFile(const char *path, u8 **data_buf, size_t *filesize, bool nul_term); 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); void assetsGetData(AssetId id, assetsDataEntry **out);
u8 *assetsGetDataBuffer(AssetId id); u8 *assetsGetDataBuffer(AssetId id);

View File

@ -85,7 +85,7 @@ bool assetObjectFromSetting(config_setting_t *asset_setting, AssetId id, ThemeLa
memset(tmp_path, 0, sizeof(tmp_path)); memset(tmp_path, 0, sizeof(tmp_path));
snprintf(tmp_path, sizeof(tmp_path)-1, "theme/%s", 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) { void themeStartup(ThemePreset preset) {
@ -420,7 +420,9 @@ void themeStartup(ThemePreset preset) {
const char *AText, *BText, *XText, *YText, *PText, *MText, *starOnText, *starOffText; const char *AText, *BText, *XText, *YText, *PText, *MText, *starOnText, *starOffText;
bool logoColor_set = false; bool logoColor_set = false;
bool good_cfg = false; bool good_cfg = false;
#ifdef __SWITCH__
bool is_romfs = false; bool is_romfs = false;
#endif
bool is_archive = false; bool is_archive = false;
const char* theme_archive_path = NULL; const char* theme_archive_path = NULL;