merge with master, remove alignment test code
This commit is contained in:
commit
dbbd49f9f9
|
@ -237,7 +237,8 @@ static int file_archive_extract_cb(const char *name, const char *valid_exts,
|
||||||
uint32_t checksum, void *userdata)
|
uint32_t checksum, void *userdata)
|
||||||
{
|
{
|
||||||
const char *ext = path_get_extension(name);
|
const char *ext = path_get_extension(name);
|
||||||
struct archive_extract_userdata *data = (struct archive_extract_userdata*)userdata;
|
struct archive_extract_userdata *data = (struct archive_extract_userdata*)
|
||||||
|
userdata;
|
||||||
|
|
||||||
/* Extract first file that matches our list. */
|
/* Extract first file that matches our list. */
|
||||||
if (ext && string_list_find_elem(data->ext, ext))
|
if (ext && string_list_find_elem(data->ext, ext))
|
||||||
|
@ -264,11 +265,12 @@ static int file_archive_extract_cb(const char *name, const char *valid_exts,
|
||||||
int file_archive_parse_file_init(file_archive_transfer_t *state,
|
int file_archive_parse_file_init(file_archive_transfer_t *state,
|
||||||
const char *file)
|
const char *file)
|
||||||
{
|
{
|
||||||
|
char *last = NULL;
|
||||||
char path[PATH_MAX_LENGTH] = {0};
|
char path[PATH_MAX_LENGTH] = {0};
|
||||||
|
|
||||||
strlcpy(path, file, sizeof(path));
|
strlcpy(path, file, sizeof(path));
|
||||||
|
|
||||||
char *last = (char*)path_get_archive_delim(path);
|
last = (char*)path_get_archive_delim(path);
|
||||||
|
|
||||||
if (last)
|
if (last)
|
||||||
*last = '\0';
|
*last = '\0';
|
||||||
|
@ -382,7 +384,8 @@ int file_archive_parse_file_iterate(
|
||||||
break;
|
break;
|
||||||
case ARCHIVE_TRANSFER_ITERATE:
|
case ARCHIVE_TRANSFER_ITERATE:
|
||||||
{
|
{
|
||||||
const struct file_archive_file_backend *backend = file_archive_get_file_backend(file);
|
const struct file_archive_file_backend *backend =
|
||||||
|
file_archive_get_file_backend(file);
|
||||||
|
|
||||||
if (backend)
|
if (backend)
|
||||||
{
|
{
|
||||||
|
@ -393,7 +396,7 @@ int file_archive_parse_file_iterate(
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
state->type = ARCHIVE_TRANSFER_DEINIT_ERROR;
|
state->type = ARCHIVE_TRANSFER_DEINIT_ERROR;
|
||||||
|
|
||||||
// early return to prevent deinit from never firing
|
/* early return to prevent deinit from never firing */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -620,6 +623,7 @@ int file_archive_compressed_read(
|
||||||
const char * path, void **buf,
|
const char * path, void **buf,
|
||||||
const char* optional_filename, ssize_t *length)
|
const char* optional_filename, ssize_t *length)
|
||||||
{
|
{
|
||||||
|
const struct file_archive_file_backend *backend = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct string_list *str_list = file_archive_filename_split(path);
|
struct string_list *str_list = file_archive_filename_split(path);
|
||||||
|
|
||||||
|
@ -645,8 +649,7 @@ int file_archive_compressed_read(
|
||||||
if (str_list->size <= 1)
|
if (str_list->size <= 1)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
const struct file_archive_file_backend *backend =
|
backend = file_archive_get_file_backend(str_list->elems[0].data);
|
||||||
file_archive_get_file_backend(str_list->elems[0].data);
|
|
||||||
|
|
||||||
*length = backend->compressed_file_read(str_list->elems[0].data,
|
*length = backend->compressed_file_read(str_list->elems[0].data,
|
||||||
str_list->elems[1].data, buf, optional_filename);
|
str_list->elems[1].data, buf, optional_filename);
|
||||||
|
@ -658,7 +661,7 @@ int file_archive_compressed_read(
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
//RARCH_ERR("Could not extract string and substring from: %s.\n", path);
|
/* could not extract string and substring. */
|
||||||
string_list_free(str_list);
|
string_list_free(str_list);
|
||||||
*length = 0;
|
*length = 0;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -720,39 +723,48 @@ error:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct file_archive_file_backend *file_archive_get_zlib_file_backend()
|
const struct file_archive_file_backend *file_archive_get_zlib_file_backend(void)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_ZLIB
|
||||||
return &zlib_backend;
|
return &zlib_backend;
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct file_archive_file_backend *file_archive_get_7z_file_backend()
|
const struct file_archive_file_backend *file_archive_get_7z_file_backend(void)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_7ZIP
|
||||||
return &sevenzip_backend;
|
return &sevenzip_backend;
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct file_archive_file_backend* file_archive_get_file_backend(const char *path)
|
const struct file_archive_file_backend* file_archive_get_file_backend(const char *path)
|
||||||
{
|
{
|
||||||
const char *file_ext = NULL;
|
const char *file_ext = NULL;
|
||||||
|
char *last = NULL;
|
||||||
char newpath[PATH_MAX_LENGTH] = {0};
|
char newpath[PATH_MAX_LENGTH] = {0};
|
||||||
|
|
||||||
strlcpy(newpath, path, sizeof(newpath));
|
strlcpy(newpath, path, sizeof(newpath));
|
||||||
|
|
||||||
char *last = (char*)path_get_archive_delim(newpath);
|
last = (char*)path_get_archive_delim(newpath);
|
||||||
|
|
||||||
if (last)
|
if (last)
|
||||||
*last = '\0';
|
*last = '\0';
|
||||||
|
|
||||||
file_ext = path_get_extension(newpath);
|
file_ext = path_get_extension(newpath);
|
||||||
|
|
||||||
|
#ifdef HAVE_7ZIP
|
||||||
if (string_is_equal_noncase(file_ext, "7z"))
|
if (string_is_equal_noncase(file_ext, "7z"))
|
||||||
{
|
|
||||||
return &sevenzip_backend;
|
return &sevenzip_backend;
|
||||||
}
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_ZLIB
|
||||||
if (string_is_equal_noncase(file_ext, "zip"))
|
if (string_is_equal_noncase(file_ext, "zip"))
|
||||||
{
|
|
||||||
return &zlib_backend;
|
return &zlib_backend;
|
||||||
}
|
#endif
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,11 +101,9 @@ static int sevenzip_file_read(
|
||||||
allocTempImp.Alloc = SzAllocTemp;
|
allocTempImp.Alloc = SzAllocTemp;
|
||||||
allocTempImp.Free = SzFreeTemp;
|
allocTempImp.Free = SzFreeTemp;
|
||||||
|
|
||||||
|
/* Could not open 7zip archive? */
|
||||||
if (InFile_Open(&archiveStream.file, path))
|
if (InFile_Open(&archiveStream.file, path))
|
||||||
{
|
|
||||||
//RARCH_ERR("Could not open %s as 7z archive\n.", path);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
FileInStream_CreateVTable(&archiveStream);
|
FileInStream_CreateVTable(&archiveStream);
|
||||||
LookToRead_CreateVTable(&lookStream, False);
|
LookToRead_CreateVTable(&lookStream, False);
|
||||||
|
@ -212,13 +210,10 @@ static int sevenzip_file_read(
|
||||||
|
|
||||||
if (!(file_found && res == SZ_OK))
|
if (!(file_found && res == SZ_OK))
|
||||||
{
|
{
|
||||||
/* Error handling */
|
/* Error handling
|
||||||
/*if (!file_found)
|
*
|
||||||
RARCH_ERR("%s: %s in %s.\n",
|
* Failed to open compressed file inside 7zip archive.
|
||||||
msg_hash_to_str(MSG_FILE_NOT_FOUND),
|
*/
|
||||||
needle, path);*/
|
|
||||||
|
|
||||||
//RARCH_ERR("Failed to open compressed file inside 7zip archive.\n");
|
|
||||||
|
|
||||||
outsize = -1;
|
outsize = -1;
|
||||||
}
|
}
|
||||||
|
@ -271,19 +266,18 @@ static int sevenzip_stream_decompress_data_to_file_iterate(void *data)
|
||||||
static int sevenzip_parse_file_init(file_archive_transfer_t *state,
|
static int sevenzip_parse_file_init(file_archive_transfer_t *state,
|
||||||
const char *file)
|
const char *file)
|
||||||
{
|
{
|
||||||
|
struct sevenzip_context_t *sevenzip_context = NULL;
|
||||||
if (state->archive_size < SEVENZIP_MAGIC_LEN)
|
if (state->archive_size < SEVENZIP_MAGIC_LEN)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (memcmp(state->data, SEVENZIP_MAGIC, SEVENZIP_MAGIC_LEN) != 0)
|
if (memcmp(state->data, SEVENZIP_MAGIC, SEVENZIP_MAGIC_LEN) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
struct sevenzip_context_t *sevenzip_context = sevenzip_stream_new();
|
sevenzip_context = sevenzip_stream_new();
|
||||||
|
|
||||||
|
/* could not open 7zip archive? */
|
||||||
if (InFile_Open(&sevenzip_context->archiveStream.file, file))
|
if (InFile_Open(&sevenzip_context->archiveStream.file, file))
|
||||||
{
|
|
||||||
//RARCH_ERR("Could not open as 7zip archive: %s.\n",path);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
FileInStream_CreateVTable(&sevenzip_context->archiveStream);
|
FileInStream_CreateVTable(&sevenzip_context->archiveStream);
|
||||||
LookToRead_CreateVTable(&sevenzip_context->lookStream, False);
|
LookToRead_CreateVTable(&sevenzip_context->lookStream, False);
|
||||||
|
@ -292,7 +286,8 @@ static int sevenzip_parse_file_init(file_archive_transfer_t *state,
|
||||||
CrcGenerateTable();
|
CrcGenerateTable();
|
||||||
SzArEx_Init(&sevenzip_context->db);
|
SzArEx_Init(&sevenzip_context->db);
|
||||||
|
|
||||||
SzArEx_Open(&sevenzip_context->db, &sevenzip_context->lookStream.s, &sevenzip_context->allocImp, &sevenzip_context->allocTempImp);
|
SzArEx_Open(&sevenzip_context->db, &sevenzip_context->lookStream.s,
|
||||||
|
&sevenzip_context->allocImp, &sevenzip_context->allocTempImp);
|
||||||
|
|
||||||
state->stream = sevenzip_context;
|
state->stream = sevenzip_context;
|
||||||
|
|
||||||
|
@ -315,6 +310,7 @@ static int sevenzip_parse_file_iterate_step_internal(
|
||||||
|
|
||||||
if (len < PATH_MAX_LENGTH && !file->IsDir)
|
if (len < PATH_MAX_LENGTH && !file->IsDir)
|
||||||
{
|
{
|
||||||
|
SRes res = SZ_ERROR_FAIL;
|
||||||
char infile[PATH_MAX_LENGTH] = {0};
|
char infile[PATH_MAX_LENGTH] = {0};
|
||||||
uint16_t *temp = (uint16_t*)malloc(len * sizeof(uint16_t));
|
uint16_t *temp = (uint16_t*)malloc(len * sizeof(uint16_t));
|
||||||
|
|
||||||
|
@ -323,8 +319,6 @@ static int sevenzip_parse_file_iterate_step_internal(
|
||||||
|
|
||||||
SzArEx_GetFileNameUtf16(&sevenzip_context->db, sevenzip_context->index, temp);
|
SzArEx_GetFileNameUtf16(&sevenzip_context->db, sevenzip_context->index, temp);
|
||||||
|
|
||||||
SRes res = SZ_ERROR_FAIL;
|
|
||||||
|
|
||||||
if (temp)
|
if (temp)
|
||||||
{
|
{
|
||||||
res = utf16_to_char_string(temp, infile, sizeof(infile))
|
res = utf16_to_char_string(temp, infile, sizeof(infile))
|
||||||
|
@ -358,6 +352,7 @@ static int sevenzip_parse_file_iterate_step(file_archive_transfer_t *state,
|
||||||
uint32_t csize = 0;
|
uint32_t csize = 0;
|
||||||
unsigned cmode = 0;
|
unsigned cmode = 0;
|
||||||
unsigned payload = 0;
|
unsigned payload = 0;
|
||||||
|
struct sevenzip_context_t *sevenzip_context = NULL;
|
||||||
char filename[PATH_MAX_LENGTH] = {0};
|
char filename[PATH_MAX_LENGTH] = {0};
|
||||||
int ret = sevenzip_parse_file_iterate_step_internal(state, filename,
|
int ret = sevenzip_parse_file_iterate_step_internal(state, filename,
|
||||||
&cdata, &cmode, &size, &csize,
|
&cdata, &cmode, &size, &csize,
|
||||||
|
@ -370,8 +365,7 @@ static int sevenzip_parse_file_iterate_step(file_archive_transfer_t *state,
|
||||||
csize, size, checksum, userdata))
|
csize, size, checksum, userdata))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
struct sevenzip_context_t *sevenzip_context =
|
sevenzip_context = (struct sevenzip_context_t*)state->stream;
|
||||||
(struct sevenzip_context_t*)state->stream;
|
|
||||||
|
|
||||||
sevenzip_context->index += payload;
|
sevenzip_context->index += payload;
|
||||||
|
|
||||||
|
|
|
@ -239,11 +239,9 @@ static bool zip_file_decompressed_handle(
|
||||||
handle->data, size);
|
handle->data, size);
|
||||||
|
|
||||||
if (handle->real_checksum != crc32)
|
if (handle->real_checksum != crc32)
|
||||||
{
|
|
||||||
//RARCH_ERR("%s\n", msg_hash_to_str(MSG_INFLATED_CHECKSUM_DID_NOT_MATCH_CRC32));
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (handle->stream)
|
if (handle->stream)
|
||||||
free(handle->stream);
|
free(handle->stream);
|
||||||
|
|
||||||
|
@ -257,8 +255,8 @@ error:
|
||||||
|
|
||||||
handle->stream = NULL;
|
handle->stream = NULL;
|
||||||
handle->data = NULL;
|
handle->data = NULL;
|
||||||
#endif
|
|
||||||
return false;
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extract the relative path (needle) from a
|
/* Extract the relative path (needle) from a
|
||||||
|
@ -280,7 +278,9 @@ static int zip_file_decompressed(
|
||||||
if (name[strlen(name) - 1] == '/' || name[strlen(name) - 1] == '\\')
|
if (name[strlen(name) - 1] == '/' || name[strlen(name) - 1] == '\\')
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
//RARCH_LOG("[deflate] Path: %s, CRC32: 0x%x\n", name, crc32);
|
#if 0
|
||||||
|
RARCH_LOG("[deflate] Path: %s, CRC32: 0x%x\n", name, crc32);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (strstr(name, st->needle))
|
if (strstr(name, st->needle))
|
||||||
{
|
{
|
||||||
|
@ -416,23 +416,23 @@ static int zip_parse_file_iterate_step_internal(
|
||||||
if (signature != CENTRAL_FILE_HEADER_SIGNATURE)
|
if (signature != CENTRAL_FILE_HEADER_SIGNATURE)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
*cmode = read_le(state->directory + 10, 2); // compression mode, 0 = store, 8 = deflate
|
*cmode = read_le(state->directory + 10, 2); /* compression mode, 0 = store, 8 = deflate */
|
||||||
*checksum = read_le(state->directory + 16, 4); // CRC32
|
*checksum = read_le(state->directory + 16, 4); /* CRC32 */
|
||||||
*csize = read_le(state->directory + 20, 4); // compressed size
|
*csize = read_le(state->directory + 20, 4); /* compressed size */
|
||||||
*size = read_le(state->directory + 24, 4); // uncompressed size
|
*size = read_le(state->directory + 24, 4); /* uncompressed size */
|
||||||
|
|
||||||
namelength = read_le(state->directory + 28, 2); // file name length
|
namelength = read_le(state->directory + 28, 2); /* file name length */
|
||||||
extralength = read_le(state->directory + 30, 2); // extra field length
|
extralength = read_le(state->directory + 30, 2); /* extra field length */
|
||||||
commentlength = read_le(state->directory + 32, 2); // file comment length
|
commentlength = read_le(state->directory + 32, 2); /* file comment length */
|
||||||
|
|
||||||
if (namelength >= PATH_MAX_LENGTH)
|
if (namelength >= PATH_MAX_LENGTH)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
memcpy(filename, state->directory + 46, namelength); // file name
|
memcpy(filename, state->directory + 46, namelength); /* file name */
|
||||||
|
|
||||||
offset = read_le(state->directory + 42, 4); // relative offset of local file header
|
offset = read_le(state->directory + 42, 4); /* relative offset of local file header */
|
||||||
offsetNL = read_le(state->data + offset + 26, 2); // file name length
|
offsetNL = read_le(state->data + offset + 26, 2); /* file name length */
|
||||||
offsetEL = read_le(state->data + offset + 28, 2); // extra field length
|
offsetEL = read_le(state->data + offset + 28, 2); /* extra field length */
|
||||||
|
|
||||||
*cdata = state->data + offset + 30 + offsetNL + offsetEL;
|
*cdata = state->data + offset + 30 + offsetNL + offsetEL;
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ struct string_list_elem
|
||||||
union string_list_elem_attr attr;
|
union string_list_elem_attr attr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct __attribute__ ((aligned(1))) string_list
|
struct string_list
|
||||||
{
|
{
|
||||||
struct string_list_elem *elems;
|
struct string_list_elem *elems;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
|
@ -715,6 +715,8 @@ static bool init_content_file_extract(
|
||||||
|
|
||||||
for (i = 0; i < content->size; i++)
|
for (i = 0; i < content->size; i++)
|
||||||
{
|
{
|
||||||
|
char temp_content[PATH_MAX_LENGTH] = {0};
|
||||||
|
char new_path[PATH_MAX_LENGTH] = {0};
|
||||||
bool compressed = NULL;
|
bool compressed = NULL;
|
||||||
const char *valid_ext = system->info.valid_extensions;
|
const char *valid_ext = system->info.valid_extensions;
|
||||||
|
|
||||||
|
@ -730,9 +732,6 @@ static bool init_content_file_extract(
|
||||||
if (!compressed)
|
if (!compressed)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
char new_path[PATH_MAX_LENGTH] = {0};
|
|
||||||
char temp_content[PATH_MAX_LENGTH] = {0};
|
|
||||||
|
|
||||||
strlcpy(temp_content, content->elems[i].data,
|
strlcpy(temp_content, content->elems[i].data,
|
||||||
sizeof(temp_content));
|
sizeof(temp_content));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue