mirror of
https://github.com/libretro/RetroArch
synced 2025-04-24 06:02:36 +00:00
Simplify zip_support.c
This commit is contained in:
parent
9d74dbdef6
commit
bcc84fd66c
@ -62,8 +62,7 @@ int read_zip_file(const char * archive_path,
|
|||||||
RARCH_ERR("Could not get global ZIP file info of %s."
|
RARCH_ERR("Could not get global ZIP file info of %s."
|
||||||
"Could be only a GZIP file without the ZIP part.\n",
|
"Could be only a GZIP file without the ZIP part.\n",
|
||||||
archive_path);
|
archive_path);
|
||||||
unzClose(zipfile);
|
goto error;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( i = 0; i < global_info.number_entry; ++i )
|
for ( i = 0; i < global_info.number_entry; ++i )
|
||||||
@ -82,8 +81,7 @@ int read_zip_file(const char * archive_path,
|
|||||||
{
|
{
|
||||||
RARCH_ERR("Could not read file info in ZIP %s.\n",
|
RARCH_ERR("Could not read file info in ZIP %s.\n",
|
||||||
archive_path);
|
archive_path);
|
||||||
unzClose(zipfile);
|
goto error;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if this entry is a directory or file. */
|
/* Check if this entry is a directory or file. */
|
||||||
@ -94,27 +92,29 @@ int read_zip_file(const char * archive_path,
|
|||||||
}
|
}
|
||||||
else if (strcmp(filename,relative_path) == 0)
|
else if (strcmp(filename,relative_path) == 0)
|
||||||
{
|
{
|
||||||
/* We found the correct file in the zip, now extract it to *buf */
|
/* We found the correct file in the zip,
|
||||||
|
* now extract it to *buf. */
|
||||||
if (unzOpenCurrentFile(zipfile) != UNZ_OK )
|
if (unzOpenCurrentFile(zipfile) != UNZ_OK )
|
||||||
{
|
{
|
||||||
RARCH_ERR("The file %s in %s could not be read.\n",
|
RARCH_ERR("The file %s in %s could not be read.\n",
|
||||||
relative_path, archive_path);
|
relative_path, archive_path);
|
||||||
unzClose(zipfile);
|
goto error;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optional_outfile != 0)
|
if (optional_outfile != 0)
|
||||||
{
|
{
|
||||||
char read_buffer[RARCH_ZIP_SUPPORT_BUFFER_SIZE_MAX];
|
char read_buffer[RARCH_ZIP_SUPPORT_BUFFER_SIZE_MAX];
|
||||||
FILE* outsink = fopen(optional_outfile,"wb");
|
FILE* outsink = fopen(optional_outfile,"wb");
|
||||||
|
|
||||||
if (outsink == NULL)
|
if (outsink == NULL)
|
||||||
{
|
{
|
||||||
RARCH_ERR("Could not open outfilepath %s.\n", optional_outfile);
|
RARCH_ERR("Could not open outfilepath %s.\n", optional_outfile);
|
||||||
unzCloseCurrentFile(zipfile);
|
unzCloseCurrentFile(zipfile);
|
||||||
unzClose(zipfile);
|
goto error;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes_read = 0;
|
bytes_read = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
ssize_t fwrite_bytes;
|
ssize_t fwrite_bytes;
|
||||||
@ -130,8 +130,7 @@ int read_zip_file(const char * archive_path,
|
|||||||
RARCH_ERR("Error writing to %s.\n",optional_outfile);
|
RARCH_ERR("Error writing to %s.\n",optional_outfile);
|
||||||
fclose(outsink);
|
fclose(outsink);
|
||||||
unzCloseCurrentFile(zipfile);
|
unzCloseCurrentFile(zipfile);
|
||||||
unzClose(zipfile);
|
goto error;
|
||||||
return -1;
|
|
||||||
} while(bytes_read > 0);
|
} while(bytes_read > 0);
|
||||||
|
|
||||||
fclose(outsink);
|
fclose(outsink);
|
||||||
@ -151,9 +150,7 @@ int read_zip_file(const char * archive_path,
|
|||||||
relative_path, archive_path);
|
relative_path, archive_path);
|
||||||
free(*buf);
|
free(*buf);
|
||||||
unzCloseCurrentFile(zipfile);
|
unzCloseCurrentFile(zipfile);
|
||||||
unzClose(zipfile);
|
goto error;
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
((char*)(*buf))[file_info.uncompressed_size] = '\0';
|
((char*)(*buf))[file_info.uncompressed_size] = '\0';
|
||||||
}
|
}
|
||||||
@ -173,8 +170,7 @@ int read_zip_file(const char * archive_path,
|
|||||||
RARCH_ERR(
|
RARCH_ERR(
|
||||||
"Could not iterate to next file in %s. ZIP file might be corrupt.\n",
|
"Could not iterate to next file in %s. ZIP file might be corrupt.\n",
|
||||||
archive_path );
|
archive_path );
|
||||||
unzClose(zipfile);
|
goto error;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,11 +178,16 @@ int read_zip_file(const char * archive_path,
|
|||||||
|
|
||||||
if(!finished_reading)
|
if(!finished_reading)
|
||||||
{
|
{
|
||||||
RARCH_ERR("File %s not found in %s\n", relative_path, archive_path);
|
RARCH_ERR("File %s not found in %s\n",
|
||||||
|
relative_path, archive_path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bytes_read;
|
return bytes_read;
|
||||||
|
|
||||||
|
error:
|
||||||
|
unzClose(zipfile);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef RARCH_ZIP_SUPPORT_BUFFER_SIZE_MAX
|
#undef RARCH_ZIP_SUPPORT_BUFFER_SIZE_MAX
|
||||||
|
Loading…
x
Reference in New Issue
Block a user