Merge pull request #7458 from gblues/master

Capture CRC content for deferred-loading cores
This commit is contained in:
Twinaphex 2018-10-20 22:13:54 +02:00 committed by GitHub
commit 0abb93228e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 4 deletions

View File

@ -23,6 +23,8 @@
#include <stdint.h>
#include <stddef.h>
#include <encodings/crc32.h>
#include <streams/file_stream.h>
#include <stdlib.h>
static const uint32_t crc32_table[256] = {
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
@ -88,3 +90,50 @@ uint32_t encoding_crc32(uint32_t crc, const uint8_t *buf, size_t len)
return crc ^ 0xffffffff;
}
#define CRC32_BUFFER_SIZE 1048576
#define CRC32_MAX_MB 64
/**
* Calculate a CRC32 from the first part of the given file.
* "first part" being the first (CRC32_BUFFER_SIZE * CRC32_MAX_MB)
* bytes.
*
* Returns: the crc32, or 0 if there was an error.
*/
uint32_t file_crc32(uint32_t crc, const char *path) {
if(path == NULL)
return 0;
RFILE *file = NULL;
unsigned char *buf = NULL;
int i, nread;
file = filestream_open(path, RETRO_VFS_FILE_ACCESS_READ, 0);
if(file == NULL)
goto error;
buf = (char *)malloc(CRC32_BUFFER_SIZE);
if(buf == NULL)
goto error;
for(i = 0; i < CRC32_MAX_MB; i++) {
nread = filestream_read(file, buf, CRC32_BUFFER_SIZE);
if(nread < 0)
goto error;
crc = encoding_crc32(crc, buf, nread);
if(filestream_eof(file))
break;
}
free(buf);
filestream_close(file);
return crc;
error:
if(buf)
free(buf);
if(file)
filestream_close(file);
return 0;
}

View File

@ -31,6 +31,7 @@
RETRO_BEGIN_DECLS
uint32_t encoding_crc32(uint32_t crc, const uint8_t *buf, size_t len);
uint32_t file_crc32(uint32_t crc, const char *path);
RETRO_END_DECLS

View File

@ -482,7 +482,8 @@ int filestream_close(RFILE *stream)
*
* Read the contents of a file into @buf.
*
* Returns: number of items read, -1 on error.
* Returns: 1 on success, 0 on failure
* In the error case, the dereferenced buf is set to NULL and the len is set to -1.
*/
int64_t filestream_read_file(const char *path, void **buf, int64_t *len)
{

View File

@ -603,9 +603,6 @@ static bool content_file_load(
}
else
{
RARCH_LOG("%s\n",
msg_hash_to_str(
MSG_CONTENT_LOADING_SKIPPED_IMPLEMENTATION_WILL_DO_IT));
#ifdef HAVE_COMPRESSION
if ( !content_ctx->block_extract
@ -619,6 +616,9 @@ static bool content_file_load(
goto error;
#endif
}
RARCH_LOG("%s\n", msg_hash_to_str(MSG_CONTENT_LOADING_SKIPPED_IMPLEMENTATION_WILL_DO_IT));
content_rom_crc = file_crc32(0, path);
RARCH_LOG("CRC32: 0x%x .\n", (unsigned)content_rom_crc);
}
load_info.content = content;