/** * read_content_file: * @path : buffer of the content file. * @buf : size of the content file. * @length : size of the content file that has been read from. * * Read the content file. If read into memory, also performs soft patching * (see patch_content function) in case soft patching has not been * blocked by the enduser. * * Returns: true if successful, false on error. **/ static bool read_content_file(unsigned i, const char *path, void **buf, ssize_t *length) { uint8_t *ret_buf = NULL; global_t *global = global_get_ptr(); RARCH_LOG("%s: %s.\n", msg_hash_to_str(MSG_LOADING_CONTENT_FILE), path); if (!read_file(path, (void**) &ret_buf, length)) return false; if (*length < 0) return false; if (i != 0) return true; /* Attempt to apply a patch. */ if (!global->patch.block_patch) patch_content(&ret_buf, length); #ifdef HAVE_ZLIB global->content_crc = zlib_crc32_calculate(ret_buf, *length); RARCH_LOG("CRC32: 0x%x .\n", (unsigned)global->content_crc); #endif *buf = ret_buf; return true; }
/** * zlib_inflate_data_to_file: * @path : filename path of archive. * @valid_exts : Valid extensions of archive to be parsed. * If NULL, allow all. * @cdata : input data. * @csize : size of input data. * @size : output file size * @checksum : CRC32 checksum from input data. * * Decompress data to file. * * Returns: true (1) on success, otherwise false (0). **/ int zlib_inflate_data_to_file(zlib_file_handle_t *handle, int ret, const char *path, const char *valid_exts, const uint8_t *cdata, uint32_t csize, uint32_t size, uint32_t checksum) { if (handle) { zlib_stream_free(handle->stream); free(handle->stream); } if (!handle || ret == -1) { ret = 0; goto end; } handle->real_checksum = zlib_crc32_calculate(handle->data, size); #if 0 if (handle->real_checksum != checksum) { /* File CRC difers from ZIP CRC. */ printf("File CRC differs from ZIP CRC. File: 0x%x, ZIP: 0x%x.\n", (unsigned)handle->real_checksum, (unsigned)checksum); } #endif if (!zlib_write_file(path, handle->data, size)) GOTO_END_ERROR(); end: if (handle->data) free(handle->data); return ret; }
static int database_info_iterate_playlist( database_state_handle_t *db_state, database_info_handle_t *db, const char *name) { uint32_t extension_hash = 0; char parent_dir[PATH_MAX_LENGTH] = {0}; path_parent_dir(parent_dir); extension_hash = msg_hash_calculate(path_get_extension(name)); switch (extension_hash) { case HASH_EXTENSION_ZIP: #ifdef HAVE_ZLIB db->type = DATABASE_TYPE_ITERATE_ZIP; memset(&db->state, 0, sizeof(zlib_transfer_t)); db_state->zip_name[0] = '\0'; db->state.type = ZLIB_TRANSFER_INIT; return 1; #endif case HASH_EXTENSION_CUE: case HASH_EXTENSION_CUE_UPPERCASE: db_state->serial[0] = '\0'; cue_get_serial(db_state, db, name, db_state->serial); db->type = DATABASE_TYPE_SERIAL_LOOKUP; return 1; case HASH_EXTENSION_ISO: case HASH_EXTENSION_ISO_UPPERCASE: db_state->serial[0] = '\0'; iso_get_serial(db_state, db, name, db_state->serial); db->type = DATABASE_TYPE_SERIAL_LOOKUP; return 1; default: { ssize_t ret; int read_from = read_file(name, (void**)&db_state->buf, &ret); if (read_from != 1 || ret <= 0) return 0; #ifdef HAVE_ZLIB db_state->crc = zlib_crc32_calculate(db_state->buf, ret); #endif db->type = DATABASE_TYPE_CRC_LOOKUP; } break; } return 1; }