Use physfs instead of minizip for asset loading, etc.
This commit is contained in:
parent
3f73855170
commit
422039f727
@ -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
|
||||
|
@ -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.*
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "common.h"
|
||||
|
||||
#include <minizip/unzip.h>
|
||||
#include <physfs.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) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (PHYSFS_mount(tmp_path, "", 0)) {
|
||||
ret=true;
|
||||
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;
|
||||
ret = assetsLoadData(i, NULL, NULL);
|
||||
if (!ret) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret!=UNZ_OK) {
|
||||
if (!ret) {
|
||||
for (i=0; i<stopi; i++) {
|
||||
assetsClearEntry(&g_assetsDataList[i][0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (ret==UNZ_OK) g_assetsInitialized = 1;
|
||||
if (ret) g_assetsInitialized = 1;
|
||||
|
||||
unzClose(zipf);
|
||||
PHYSFS_unmount(tmp_path);
|
||||
}
|
||||
|
||||
#ifdef __SWITCH__
|
||||
romfsExit();
|
||||
return ret ? 0 : MAKERESULT(Module_Libnx, LibnxError_IoError);
|
||||
#else
|
||||
return ret ? 0 : 1;
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void assetsExit(void) {
|
||||
@ -260,22 +203,24 @@ bool assetsPhysfsReadFile(const char *path, u8 **data_buf, size_t *filesize, boo
|
||||
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;
|
||||
|
||||
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));
|
||||
|
||||
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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user