mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-19 00:04:04 +01:00
txtm: add option to read file position in .txtm
This commit is contained in:
parent
f9c6115ebf
commit
f5cefd544e
@ -1123,9 +1123,14 @@ fail:
|
|||||||
}
|
}
|
||||||
|
|
||||||
STREAMFILE* read_filemap_file(STREAMFILE* sf, int file_num) {
|
STREAMFILE* read_filemap_file(STREAMFILE* sf, int file_num) {
|
||||||
|
return read_filemap_file_pos(sf, file_num, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
STREAMFILE* read_filemap_file_pos(STREAMFILE* sf, int file_num, int* p_pos) {
|
||||||
char filename[PATH_LIMIT];
|
char filename[PATH_LIMIT];
|
||||||
off_t txt_offset, file_size;
|
off_t txt_offset, file_size;
|
||||||
STREAMFILE* sf_map = NULL;
|
STREAMFILE* sf_map = NULL;
|
||||||
|
int file_pos = 0;
|
||||||
|
|
||||||
sf_map = open_streamfile_by_filename(sf, ".txtm");
|
sf_map = open_streamfile_by_filename(sf, ".txtm");
|
||||||
if (!sf_map) goto fail;
|
if (!sf_map) goto fail;
|
||||||
@ -1136,10 +1141,10 @@ STREAMFILE* read_filemap_file(STREAMFILE* sf, int file_num) {
|
|||||||
file_size = get_streamfile_size(sf_map);
|
file_size = get_streamfile_size(sf_map);
|
||||||
|
|
||||||
/* skip BOM if needed */
|
/* skip BOM if needed */
|
||||||
if ((uint16_t)read_16bitLE(0x00, sf_map) == 0xFFFE ||
|
if (read_u16le(0x00, sf_map) == 0xFFFE ||
|
||||||
(uint16_t)read_16bitLE(0x00, sf_map) == 0xFEFF) {
|
read_u16le(0x00, sf_map) == 0xFEFF) {
|
||||||
txt_offset = 0x02;
|
txt_offset = 0x02;
|
||||||
} else if (((uint32_t)read_32bitBE(0x00, sf_map) & 0xFFFFFF00) == 0xEFBBBF00) {
|
} else if ((read_u32be(0x00, sf_map) & 0xFFFFFF00) == 0xEFBBBF00) {
|
||||||
txt_offset = 0x03;
|
txt_offset = 0x03;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1174,8 +1179,9 @@ STREAMFILE* read_filemap_file(STREAMFILE* sf, int file_num) {
|
|||||||
if (ok != 1)
|
if (ok != 1)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (i == file_num)
|
if (i == file_num) {
|
||||||
{
|
if (p_pos) *p_pos = file_pos;
|
||||||
|
|
||||||
close_streamfile(sf_map);
|
close_streamfile(sf_map);
|
||||||
return open_streamfile_by_filename(sf, subval);
|
return open_streamfile_by_filename(sf, subval);
|
||||||
}
|
}
|
||||||
@ -1185,6 +1191,7 @@ STREAMFILE* read_filemap_file(STREAMFILE* sf, int file_num) {
|
|||||||
current++;
|
current++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
file_pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
@ -361,7 +361,9 @@ size_t read_key_file(uint8_t* buf, size_t buf_size, STREAMFILE* sf);
|
|||||||
|
|
||||||
/* Opens .txtm file containing file:companion file(-s) mappings and tries to see if there's a match
|
/* Opens .txtm file containing file:companion file(-s) mappings and tries to see if there's a match
|
||||||
* then loads the associated companion file if one is found */
|
* then loads the associated companion file if one is found */
|
||||||
STREAMFILE *read_filemap_file(STREAMFILE *sf, int file_num);
|
STREAMFILE* read_filemap_file(STREAMFILE *sf, int file_num);
|
||||||
|
STREAMFILE* read_filemap_file_pos(STREAMFILE *sf, int file_num, int* p_pos);
|
||||||
|
|
||||||
|
|
||||||
/* hack to allow relative paths in various OSs */
|
/* hack to allow relative paths in various OSs */
|
||||||
void fix_dir_separators(char* filename);
|
void fix_dir_separators(char* filename);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user