mirror of
https://github.com/libretro/RetroArch
synced 2025-04-10 15:45:19 +00:00
(RARCH_CONSOLE) Split up rzlib helper functions into separate file
This commit is contained in:
parent
a6c2139a21
commit
86067e3aeb
@ -22,6 +22,11 @@
|
|||||||
CONSOLE EXTENSIONS
|
CONSOLE EXTENSIONS
|
||||||
============================================================ */
|
============================================================ */
|
||||||
#include "../retroarch_console.c"
|
#include "../retroarch_console.c"
|
||||||
|
|
||||||
|
#ifdef HAVE_ZLIB
|
||||||
|
#include "../retroarch_rzlib.c"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "../console_settings.c"
|
#include "../console_settings.c"
|
||||||
|
|
||||||
#ifdef HAVE_LIBRETRO_MANAGEMENT
|
#ifdef HAVE_LIBRETRO_MANAGEMENT
|
||||||
|
@ -32,11 +32,6 @@
|
|||||||
#include "../conf/config_file_macros.h"
|
#include "../conf/config_file_macros.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_ZLIB
|
|
||||||
#include "rzlib/zlib.h"
|
|
||||||
#define WRITEBUFFERSIZE (1024 * 512)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "../compat/posix_string.h"
|
#include "../compat/posix_string.h"
|
||||||
#endif
|
#endif
|
||||||
@ -105,132 +100,6 @@ void rarch_console_name_from_id(char *name, size_t size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_ZLIB
|
|
||||||
static int rarch_extract_currentfile_in_zip(unzFile uf)
|
|
||||||
{
|
|
||||||
char filename_inzip[PATH_MAX];
|
|
||||||
FILE *fout = NULL;
|
|
||||||
|
|
||||||
unz_file_info file_info;
|
|
||||||
int err = unzGetCurrentFileInfo(uf,
|
|
||||||
&file_info, filename_inzip, sizeof(filename_inzip),
|
|
||||||
NULL, 0, NULL, 0);
|
|
||||||
|
|
||||||
if (err != UNZ_OK)
|
|
||||||
{
|
|
||||||
RARCH_ERR("Error %d while trying to get ZIP file information.\n", err);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size_buf = WRITEBUFFERSIZE;
|
|
||||||
void *buf = malloc(size_buf);
|
|
||||||
if (!buf)
|
|
||||||
{
|
|
||||||
RARCH_ERR("Error allocating memory for ZIP extract operation.\n");
|
|
||||||
return UNZ_INTERNALERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
char write_filename[PATH_MAX];
|
|
||||||
|
|
||||||
#ifdef HAVE_HDD_CACHE_PARTITION
|
|
||||||
|
|
||||||
#if defined(__CELLOS_LV2__)
|
|
||||||
snprintf(write_filename, sizeof(write_filename), "/dev_hdd1/%s", filename_inzip);
|
|
||||||
#elif defined(_XBOX)
|
|
||||||
snprintf(write_filename, sizeof(write_filename), "cache:\\%s", filename_inzip);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
err = unzOpenCurrentFile(uf);
|
|
||||||
if (err != UNZ_OK)
|
|
||||||
RARCH_ERR("Error %d while trying to open ZIP file.\n", err);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* success */
|
|
||||||
fout = fopen(write_filename, "wb");
|
|
||||||
|
|
||||||
if (!fout)
|
|
||||||
RARCH_ERR("Error opening %s.\n", write_filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fout)
|
|
||||||
{
|
|
||||||
RARCH_LOG("Extracting: %s..\n", write_filename);
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
err = unzReadCurrentFile(uf, buf, size_buf);
|
|
||||||
if (err < 0)
|
|
||||||
{
|
|
||||||
RARCH_ERR("Error %d while reading from ZIP file.\n", err);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err > 0)
|
|
||||||
{
|
|
||||||
if (fwrite(buf, err, 1, fout) != 1)
|
|
||||||
{
|
|
||||||
RARCH_ERR("Error while extracting file(s) from ZIP.\n");
|
|
||||||
err = UNZ_ERRNO;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (err > 0);
|
|
||||||
|
|
||||||
if (fout)
|
|
||||||
fclose(fout);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err == UNZ_OK)
|
|
||||||
{
|
|
||||||
err = unzCloseCurrentFile (uf);
|
|
||||||
if (err != UNZ_OK)
|
|
||||||
RARCH_ERR("Error %d while trying to close ZIP file.\n", err);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
unzCloseCurrentFile(uf);
|
|
||||||
|
|
||||||
free(buf);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
int rarch_extract_zipfile(const char *zip_path)
|
|
||||||
{
|
|
||||||
unzFile uf = unzOpen(zip_path);
|
|
||||||
|
|
||||||
unz_global_info gi;
|
|
||||||
int err = unzGetGlobalInfo(uf, &gi);
|
|
||||||
if (err != UNZ_OK)
|
|
||||||
RARCH_ERR("Error %d while trying to get ZIP file global info.\n",err);
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < gi.number_entry; i++)
|
|
||||||
{
|
|
||||||
if (rarch_extract_currentfile_in_zip(uf) != UNZ_OK)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if ((i + 1) < gi.number_entry)
|
|
||||||
{
|
|
||||||
err = unzGoToNextFile(uf);
|
|
||||||
if (err != UNZ_OK)
|
|
||||||
{
|
|
||||||
RARCH_ERR("Error %d while trying to go to the next file in the ZIP archive.\n",err);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_HDD_CACHE_PARTITION
|
|
||||||
if(g_console.info_msg_enable)
|
|
||||||
rarch_settings_msg(S_MSG_EXTRACTED_ZIPFILE, S_DELAY_180);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*============================================================
|
/*============================================================
|
||||||
INPUT EXTENSIONS
|
INPUT EXTENSIONS
|
||||||
============================================================ */
|
============================================================ */
|
||||||
|
@ -170,10 +170,6 @@ const char *rarch_console_get_rom_ext(void);
|
|||||||
// Transforms a library id to a name suitable as a pathname.
|
// Transforms a library id to a name suitable as a pathname.
|
||||||
void rarch_console_name_from_id(char *name, size_t size);
|
void rarch_console_name_from_id(char *name, size_t size);
|
||||||
|
|
||||||
#ifdef HAVE_ZLIB
|
|
||||||
int rarch_extract_zipfile(const char *zip_path);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*============================================================
|
/*============================================================
|
||||||
INPUT EXTENSIONS
|
INPUT EXTENSIONS
|
||||||
============================================================ */
|
============================================================ */
|
||||||
|
145
console/retroarch_rzlib.c
Normal file
145
console/retroarch_rzlib.c
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
/* RetroArch - A frontend for libretro.
|
||||||
|
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
||||||
|
* Copyright (C) 2011-2012 - Daniel De Matteis
|
||||||
|
*
|
||||||
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||||
|
* of the GNU General Public License as published by the Free Software Found-
|
||||||
|
* ation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||||
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "../boolean.h"
|
||||||
|
|
||||||
|
#include "retroarch_rzlib.h"
|
||||||
|
|
||||||
|
static int rarch_extract_currentfile_in_zip(unzFile uf)
|
||||||
|
{
|
||||||
|
char filename_inzip[PATH_MAX];
|
||||||
|
FILE *file_out = NULL;
|
||||||
|
|
||||||
|
unz_file_info file_info;
|
||||||
|
int err = unzGetCurrentFileInfo(uf,
|
||||||
|
&file_info, filename_inzip, sizeof(filename_inzip),
|
||||||
|
NULL, 0, NULL, 0);
|
||||||
|
|
||||||
|
if (err != UNZ_OK)
|
||||||
|
{
|
||||||
|
RARCH_ERR("Error %d while trying to get ZIP file information.\n", err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size_buf = WRITEBUFFERSIZE;
|
||||||
|
void *buf = malloc(size_buf);
|
||||||
|
if (!buf)
|
||||||
|
{
|
||||||
|
RARCH_ERR("Error allocating memory for ZIP extract operation.\n");
|
||||||
|
return UNZ_INTERNALERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
char write_filename[PATH_MAX];
|
||||||
|
|
||||||
|
#ifdef HAVE_HDD_CACHE_PARTITION
|
||||||
|
|
||||||
|
#if defined(__CELLOS_LV2__)
|
||||||
|
snprintf(write_filename, sizeof(write_filename), "/dev_hdd1/%s", filename_inzip);
|
||||||
|
#elif defined(_XBOX)
|
||||||
|
snprintf(write_filename, sizeof(write_filename), "cache:\\%s", filename_inzip);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
err = unzOpenCurrentFile(uf);
|
||||||
|
if (err != UNZ_OK)
|
||||||
|
RARCH_ERR("Error %d while trying to open ZIP file.\n", err);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* success */
|
||||||
|
file_out = fopen(write_filename, "wb");
|
||||||
|
|
||||||
|
if (!file_out)
|
||||||
|
RARCH_ERR("Error opening %s.\n", write_filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_out)
|
||||||
|
{
|
||||||
|
RARCH_LOG("Extracting: %s..\n", write_filename);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
err = unzReadCurrentFile(uf, buf, size_buf);
|
||||||
|
if (err < 0)
|
||||||
|
{
|
||||||
|
RARCH_ERR("Error %d while reading from ZIP file.\n", err);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err > 0)
|
||||||
|
{
|
||||||
|
if (fwrite(buf, err, 1, file_out) != 1)
|
||||||
|
{
|
||||||
|
RARCH_ERR("Error while extracting file(s) from ZIP.\n");
|
||||||
|
err = UNZ_ERRNO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}while (err > 0);
|
||||||
|
|
||||||
|
if (file_out)
|
||||||
|
fclose(file_out);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err == UNZ_OK)
|
||||||
|
{
|
||||||
|
err = unzCloseCurrentFile (uf);
|
||||||
|
if (err != UNZ_OK)
|
||||||
|
RARCH_ERR("Error %d while trying to close ZIP file.\n", err);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
unzCloseCurrentFile(uf);
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rarch_extract_zipfile(const char *zip_path)
|
||||||
|
{
|
||||||
|
unzFile uf = unzOpen(zip_path);
|
||||||
|
|
||||||
|
unz_global_info gi;
|
||||||
|
int err = unzGetGlobalInfo(uf, &gi);
|
||||||
|
if (err != UNZ_OK)
|
||||||
|
RARCH_ERR("Error %d while trying to get ZIP file global info.\n",err);
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < gi.number_entry; i++)
|
||||||
|
{
|
||||||
|
if (rarch_extract_currentfile_in_zip(uf) != UNZ_OK)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if ((i + 1) < gi.number_entry)
|
||||||
|
{
|
||||||
|
err = unzGoToNextFile(uf);
|
||||||
|
if (err != UNZ_OK)
|
||||||
|
{
|
||||||
|
RARCH_ERR("Error %d while trying to go to the next file in the ZIP archive.\n",err);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_HDD_CACHE_PARTITION
|
||||||
|
if(g_console.info_msg_enable)
|
||||||
|
rarch_settings_msg(S_MSG_EXTRACTED_ZIPFILE, S_DELAY_180);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
26
console/retroarch_rzlib.h
Normal file
26
console/retroarch_rzlib.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/* RetroArch - A frontend for libretro.
|
||||||
|
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
||||||
|
* Copyright (C) 2011-2012 - Daniel De Matteis
|
||||||
|
*
|
||||||
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||||
|
* of the GNU General Public License as published by the Free Software Found-
|
||||||
|
* ation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||||
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _RARCH_CONSOLE_RZLIB_H
|
||||||
|
#define _RARCH_CONSOLE_RZLIB_H
|
||||||
|
|
||||||
|
#include "rzlib/zlib.h"
|
||||||
|
|
||||||
|
#define WRITEBUFFERSIZE (1024 * 512)
|
||||||
|
|
||||||
|
int rarch_extract_zipfile(const char *zip_path);
|
||||||
|
|
||||||
|
#endif
|
@ -28,6 +28,10 @@
|
|||||||
|
|
||||||
#include "../../console/retroarch_console.h"
|
#include "../../console/retroarch_console.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_ZLIB
|
||||||
|
#include "../../console/retroarch_rzlib.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "../../gfx/gl_common.h"
|
#include "../../gfx/gl_common.h"
|
||||||
#include "../../gfx/gl_font.h"
|
#include "../../gfx/gl_font.h"
|
||||||
#include "../../gfx/gfx_context.h"
|
#include "../../gfx/gfx_context.h"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user