Skip to content

Commit

Permalink
rg_storage: rg_storage_unzip_file is now present even if ZIP suppor…
Browse files Browse the repository at this point in the history
…t disabled

This reverts the previous commit. Applications don't have to care about the presence of zip support, just that unzipping failed for any reason.

If an application really needs to know if ZIP support is present, it can of course still `#if RG_ZIP_SUPPORT`.
  • Loading branch information
ducalex committed Jul 22, 2024
1 parent 003ade2 commit 763a5dc
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 31 deletions.
10 changes: 7 additions & 3 deletions components/retro-go/rg_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,14 @@ bool rg_storage_write_file(const char *path, const void *data_ptr, size_t data_l
return true;
}

#if RG_ZIP_SUPPORT
/**
* This is a minimal UNZIP implementation that utilizes only the miniz primitives found in ESP32's ROM.
* I think that we should use miniz' ZIP API instead and bundle miniz with retro-go. But first I need
* to do some testing to determine if the increased executable size is acceptable...
*/
#if RG_ZIP_SUPPORT
#include <rom/miniz.h>
#endif

#define ZIP_MAGIC 0x04034b50
typedef struct __attribute__((packed))
Expand All @@ -506,6 +507,7 @@ typedef struct __attribute__((packed))

bool rg_storage_unzip_file(const char *zip_path, const char *filter, void **data_out, size_t *data_len)
{
#if RG_ZIP_SUPPORT
RG_ASSERT(data_out && data_len, "Bad param");
CHECK_PATH(zip_path);

Expand Down Expand Up @@ -587,6 +589,8 @@ bool rg_storage_unzip_file(const char *zip_path, const char *filter, void **data
free(decomp);
fclose(fp);
return false;
}

#else
RG_LOGE("ZIP support hasn't been enabled!");
return false;
#endif
}
4 changes: 0 additions & 4 deletions gwenesis/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,8 @@ void app_main(void)

if (rg_extension_match(app->romPath, "zip"))
{
#if RG_ZIP_SUPPORT
if (!rg_storage_unzip_file(app->romPath, NULL, &rom_data, &rom_size))
RG_PANIC("ROM file unzipping failed!");
#else
RG_PANIC("ZIP files aren't supported!");
#endif
}
else if (!rg_storage_read_file(app->romPath, &rom_data, &rom_size))
{
Expand Down
4 changes: 0 additions & 4 deletions retro-core/main/main_gbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,12 @@ void gbc_main(void)
// Load ROM
if (rg_extension_match(app->romPath, "zip"))
{
#if RG_ZIP_SUPPORT
void *data;
size_t size;
if (!rg_storage_unzip_file(app->romPath, NULL, &data, &size))
RG_PANIC("ROM file unzipping failed!");
if (gnuboy_load_rom(data, size) < 0)
RG_PANIC("ROM Loading failed!");
#else
RG_PANIC("ZIP files aren't supported!");
#endif
}
else if (gnuboy_load_rom_file(app->romPath) < 0)
{
Expand Down
4 changes: 0 additions & 4 deletions retro-core/main/main_lynx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,13 @@ static CSystem *new_lynx(void)
{
if (rg_extension_match(app->romPath, "zip"))
{
#if RG_ZIP_SUPPORT
void *data;
size_t size;
if (!rg_storage_unzip_file(app->romPath, NULL, &data, &size))
RG_PANIC("ROM file unzipping failed!");
CSystem *lynx = new CSystem((UBYTE*)data, size, MIKIE_PIXEL_FORMAT_16BPP_565_BE, app->sampleRate);
free(data);
return lynx;
#else
RG_PANIC("ZIP files aren't supported!");
#endif
}
return new CSystem(app->romPath, MIKIE_PIXEL_FORMAT_16BPP_565_BE, app->sampleRate);
}
Expand Down
4 changes: 0 additions & 4 deletions retro-core/main/main_nes.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,11 @@ void nes_main(void)

if (rg_extension_match(app->romPath, "zip"))
{
#if RG_ZIP_SUPPORT
void *data;
size_t size;
if (!rg_storage_unzip_file(app->romPath, NULL, &data, &size))
RG_PANIC("ROM file unzipping failed!");
ret = nes_insertcart(rom_loadmem(data, size));
#else
RG_PANIC("ZIP files aren't supported!");
#endif
}
else
{
Expand Down
4 changes: 0 additions & 4 deletions retro-core/main/main_pce.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,12 @@ void pce_main(void)

if (rg_extension_match(app->romPath, "zip"))
{
#if RG_ZIP_SUPPORT
void *data;
size_t size;
if (!rg_storage_unzip_file(app->romPath, NULL, &data, &size))
RG_PANIC("ROM file unzipping failed!");
if (LoadCard(data, size) != 0)
RG_PANIC("ROM loading failed");
#else
RG_PANIC("ZIP files aren't supported!");
#endif
}
else if (LoadFile(app->romPath) != 0)
{
Expand Down
4 changes: 0 additions & 4 deletions retro-core/main/main_sms.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,12 @@ void sms_main(void)

if (rg_extension_match(app->romPath, "zip"))
{
#if RG_ZIP_SUPPORT
void *data;
size_t size;
if (!rg_storage_unzip_file(app->romPath, NULL, &data, &size))
RG_PANIC("ROM file unzipping failed!");
if (!load_rom(data, RG_MAX(0x4000, size), size))
RG_PANIC("ROM file loading failed!");
#else
RG_PANIC("ZIP files aren't supported!");
#endif
}
else if (!load_rom_file(app->romPath))
{
Expand Down
4 changes: 0 additions & 4 deletions retro-core/main/main_snes.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,10 @@ void snes_main(void)

if (rg_extension_match(filename, "zip"))
{
#if RG_ZIP_SUPPORT
free(Memory.ROM); // Would be nice to reuse it directly...
if (!rg_storage_unzip_file(filename, NULL, (void **)&Memory.ROM, &Memory.ROM_Size))
RG_PANIC("ROM file unzipping failed!");
filename = NULL;
#else
RG_PANIC("ZIP files aren't supported!");
#endif
}

if (!LoadROM(filename))
Expand Down

0 comments on commit 763a5dc

Please sign in to comment.