mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-18 07:44:43 +01:00
Rename open_stream_ext/name to open_streamfile_by_ext/filename (cleanup)
This commit is contained in:
parent
dce00d6d27
commit
92b9992552
@ -59,7 +59,7 @@ static STREAMFILE* setup_atx_streamfile(STREAMFILE *streamFile) {
|
||||
size_t subfile_size;
|
||||
|
||||
filename[filename_len - 5] = ('0'+i+1); /* ghetto digit conversion */
|
||||
new_streamFile = open_stream_name(streamFile, filename);
|
||||
new_streamFile = open_streamfile_by_filename(streamFile, filename);
|
||||
if (!new_streamFile) goto fail;
|
||||
segment_streamFiles[i] = new_streamFile;
|
||||
|
||||
|
@ -103,16 +103,16 @@ static int get_falcom_looping(STREAMFILE *streamFile, int *out_loop_start, int *
|
||||
|
||||
|
||||
/* try one of the many loop files */
|
||||
if ((streamText = open_stream_name(streamFile,"bgm.tbl")) != NULL) {
|
||||
if ((streamText = open_streamfile_by_filename(streamFile,"bgm.tbl")) != NULL) {
|
||||
type = XANADU_NEXT;
|
||||
}
|
||||
else if ((streamText = open_stream_name(streamFile,"bgm.scr")) != NULL) {
|
||||
else if ((streamText = open_streamfile_by_filename(streamFile,"bgm.scr")) != NULL) {
|
||||
type = ZWEI;
|
||||
}
|
||||
else if ((streamText = open_stream_name(streamFile,"loop.txt")) != NULL) { /* actual name in Shift JIS, 0x838B815B8376 */
|
||||
else if ((streamText = open_streamfile_by_filename(streamFile,"loop.txt")) != NULL) { /* actual name in Shift JIS, 0x838B815B8376 */
|
||||
type = DINOSAUR_RESURRECTION;
|
||||
}
|
||||
else if ((streamText = open_stream_name(streamFile,"map.itm")) != NULL) {
|
||||
else if ((streamText = open_streamfile_by_filename(streamFile,"map.itm")) != NULL) {
|
||||
type = GURUMIN;
|
||||
}
|
||||
else {
|
||||
|
@ -29,7 +29,7 @@ VGMSTREAM * init_vgmstream_ea_snr_sns(STREAMFILE * streamFile) {
|
||||
if (!vgmstream) goto fail;
|
||||
}
|
||||
else {
|
||||
streamData = open_stream_ext(streamFile,"sns");
|
||||
streamData = open_streamfile_by_ext(streamFile,"sns");
|
||||
if (!streamData) goto fail;
|
||||
|
||||
vgmstream = init_vgmstream_eaaudiocore_header(streamFile, streamData, 0x00, 0x00, meta_EA_SNR_SNS);
|
||||
|
@ -16,7 +16,7 @@ VGMSTREAM * init_vgmstream_gsp_gsb(STREAMFILE *streamFile) {
|
||||
if (!check_extensions(streamFile,"gsb"))
|
||||
goto fail;
|
||||
|
||||
streamFileGSP = open_stream_ext(streamFile, "gsp");
|
||||
streamFileGSP = open_streamfile_by_ext(streamFile, "gsp");
|
||||
if (!streamFileGSP) goto fail;
|
||||
|
||||
/* check header */
|
||||
|
@ -74,7 +74,7 @@ static int get_adm_loop_info(STREAMFILE *streamFile, off_t *loop_start_offset) {
|
||||
int i, name_index = -1, loop_flag;
|
||||
off_t offset;
|
||||
|
||||
streamExe = open_stream_name(streamFile, "SLPM_655.55");
|
||||
streamExe = open_streamfile_by_filename(streamFile, "SLPM_655.55");
|
||||
if (!streamExe) goto fail;
|
||||
|
||||
get_streamfile_filename(streamFile, file_name, PATH_LIMIT);
|
||||
|
@ -24,7 +24,7 @@ VGMSTREAM * init_vgmstream_ps2_rxws(STREAMFILE *streamFile) {
|
||||
(read_32bitBE(0x00,streamFile) == 0x444E4257)) /* "DNBW" (BE) */
|
||||
goto fail;
|
||||
|
||||
streamHeader = open_stream_ext(streamFile, "xwh");
|
||||
streamHeader = open_streamfile_by_ext(streamFile, "xwh");
|
||||
if (!streamHeader) goto fail;
|
||||
} else {
|
||||
streamHeader = streamFile;
|
||||
|
@ -109,7 +109,7 @@ static void get_stream_name(char * stream_name, STREAMFILE *streamFile, int targ
|
||||
size_t name_size = 0;
|
||||
off_t name_offset = 0x10;
|
||||
|
||||
streamInfo = open_stream_ext(streamFile, "sob");
|
||||
streamInfo = open_streamfile_by_ext(streamFile, "sob");
|
||||
if (!streamInfo) goto end;
|
||||
if (read_32bitBE(0x00,streamInfo) != 0x43544632) /* "CTF2" */
|
||||
goto end;
|
||||
|
@ -24,7 +24,7 @@ VGMSTREAM * init_vgmstream_sgxd(STREAMFILE *streamFile) {
|
||||
|
||||
/* SGB+SGH: use SGH as header; otherwise use the current file as header */
|
||||
if (is_sgb) {
|
||||
streamHeader = open_stream_ext(streamFile, "sgh");
|
||||
streamHeader = open_streamfile_by_ext(streamFile, "sgh");
|
||||
if (!streamHeader) goto fail;
|
||||
} else {
|
||||
streamHeader = streamFile;
|
||||
|
@ -25,7 +25,7 @@ VGMSTREAM * init_vgmstream_sxd(STREAMFILE *streamFile) {
|
||||
if (is_dual) {
|
||||
if (read_32bitBE(0x00,streamFile) != 0x53584453) /* "SXDS" */
|
||||
goto fail;
|
||||
streamHeader = open_stream_ext(streamFile, "sxd1");
|
||||
streamHeader = open_streamfile_by_ext(streamFile, "sxd1");
|
||||
if (!streamHeader) goto fail;
|
||||
} else {
|
||||
streamHeader = streamFile;
|
||||
|
@ -90,7 +90,7 @@ VGMSTREAM * init_vgmstream_ubi_sb(STREAMFILE *streamFile) {
|
||||
if (sb.autodetect_external) { /* works most of the time but could give false positives */
|
||||
VGM_LOG("UBI SB: autodetecting external stream '%s'\n", sb.stream_name);
|
||||
|
||||
streamData = open_stream_name(streamFile,sb.stream_name);
|
||||
streamData = open_streamfile_by_filename(streamFile,sb.stream_name);
|
||||
if (!streamData) {
|
||||
streamData = streamFile; /* assume internal */
|
||||
if (sb.stream_size > get_streamfile_size(streamData)) {
|
||||
@ -102,7 +102,7 @@ VGMSTREAM * init_vgmstream_ubi_sb(STREAMFILE *streamFile) {
|
||||
}
|
||||
}
|
||||
else if (sb.is_external) {
|
||||
streamData = open_stream_name(streamFile,sb.stream_name);
|
||||
streamData = open_streamfile_by_filename(streamFile,sb.stream_name);
|
||||
if (!streamData) {
|
||||
VGM_LOG("UBI SB: external stream '%s' not found\n", sb.stream_name);
|
||||
goto fail;
|
||||
@ -674,7 +674,7 @@ static int config_sb_header_version(ubi_sb_header * sb, STREAMFILE *streamFile)
|
||||
|
||||
/* two games with same id; use project file as identifier */
|
||||
if (sb->version == 0x0012000C && is_sb4) {
|
||||
STREAMFILE * streamTest = open_stream_name(streamFile, "BIAAUDIO.SP4");
|
||||
STREAMFILE * streamTest = open_streamfile_by_filename(streamFile, "BIAAUDIO.SP4");
|
||||
if (streamTest) {
|
||||
is_biadd_psp = 1;
|
||||
close_streamfile(streamTest);
|
||||
|
@ -601,7 +601,7 @@ static int get_xsb_name(char * buf, size_t maxsize, int target_subsong, xwb_head
|
||||
xsb_header xsb = {0};
|
||||
|
||||
|
||||
streamFile = open_stream_ext(streamXwb, "xsb");
|
||||
streamFile = open_streamfile_by_ext(streamXwb, "xsb");
|
||||
if (!streamFile) goto fail;
|
||||
|
||||
/* check header */
|
||||
|
@ -684,6 +684,37 @@ fail:
|
||||
|
||||
/* **************************************************** */
|
||||
|
||||
STREAMFILE * open_streamfile_by_ext(STREAMFILE *streamFile, const char * ext) {
|
||||
char filename_ext[PATH_LIMIT];
|
||||
|
||||
streamFile->get_name(streamFile,filename_ext,sizeof(filename_ext));
|
||||
strcpy(filename_ext + strlen(filename_ext) - strlen(filename_extension(filename_ext)), ext);
|
||||
|
||||
return streamFile->open(streamFile,filename_ext,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
STREAMFILE * open_streamfile_by_filename(STREAMFILE *streamFile, const char * name) {
|
||||
char foldername[PATH_LIMIT];
|
||||
char filename[PATH_LIMIT];
|
||||
const char *path;
|
||||
|
||||
streamFile->get_name(streamFile,foldername,sizeof(foldername));
|
||||
|
||||
path = strrchr(foldername,DIR_SEPARATOR);
|
||||
if (path!=NULL) path = path+1;
|
||||
|
||||
if (path) {
|
||||
strcpy(filename, foldername);
|
||||
filename[path-foldername] = '\0';
|
||||
strcat(filename, name);
|
||||
} else {
|
||||
strcpy(filename, name);
|
||||
}
|
||||
|
||||
return streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
|
||||
/* Read a line into dst. The source files are lines separated by CRLF (Windows) / LF (Unux) / CR (Mac).
|
||||
* The line will be null-terminated and CR/LF removed if found.
|
||||
*
|
||||
@ -762,37 +793,6 @@ fail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Opens an stream using the base streamFile name plus a new extension (ex. for headers in a separate file) */
|
||||
STREAMFILE * open_stream_ext(STREAMFILE *streamFile, const char * ext) {
|
||||
char filename_ext[PATH_LIMIT];
|
||||
|
||||
streamFile->get_name(streamFile,filename_ext,sizeof(filename_ext));
|
||||
strcpy(filename_ext + strlen(filename_ext) - strlen(filename_extension(filename_ext)), ext);
|
||||
|
||||
return streamFile->open(streamFile,filename_ext,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
/* Opens an stream using the passed name, in the same folder */
|
||||
STREAMFILE * open_stream_name(STREAMFILE *streamFile, const char * name) {
|
||||
char foldername[PATH_LIMIT];
|
||||
char filename[PATH_LIMIT];
|
||||
const char *path;
|
||||
|
||||
streamFile->get_name(streamFile,foldername,sizeof(foldername));
|
||||
|
||||
path = strrchr(foldername,DIR_SEPARATOR);
|
||||
if (path!=NULL) path = path+1;
|
||||
|
||||
if (path) {
|
||||
strcpy(filename, foldername);
|
||||
filename[path-foldername] = '\0';
|
||||
strcat(filename, name);
|
||||
} else {
|
||||
strcpy(filename, name);
|
||||
}
|
||||
|
||||
return streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
/* Opens a file containing decryption keys and copies to buffer.
|
||||
* Tries combinations of keynames based on the original filename.
|
||||
|
@ -65,40 +65,50 @@ typedef struct _STREAMFILE {
|
||||
|
||||
} STREAMFILE;
|
||||
|
||||
/* create a STREAMFILE from path */
|
||||
STREAMFILE * open_stdio_streamfile(const char * filename);
|
||||
/* Opens a standard STREAMFILE, opening from path.
|
||||
* Uses stdio (FILE) for operations, thus plugins may not want to use it. */
|
||||
STREAMFILE *open_stdio_streamfile(const char * filename);
|
||||
|
||||
/* create a STREAMFILE from pre-opened file path */
|
||||
STREAMFILE * open_stdio_streamfile_by_file(FILE * file, const char * filename);
|
||||
/* Opens a standard STREAMFILE from a pre-opened FILE. */
|
||||
STREAMFILE *open_stdio_streamfile_by_file(FILE * file, const char * filename);
|
||||
|
||||
/* A STREAMFILE that doesn't close the underlying stream.
|
||||
/* Opens a STREAMFILE that doesn't close the underlying streamfile.
|
||||
* Calls to open won't wrap the new SF (assumes it needs to be closed).
|
||||
* Can be used in metas to test custom IO without closing the external SF. */
|
||||
STREAMFILE *open_wrap_streamfile(STREAMFILE *streamfile);
|
||||
|
||||
/* A STREAMFILE that clamps IO to a section of a larger stream.
|
||||
* Can be used with subfiles inside a bigger file, so it looks standard to a meta. */
|
||||
/* Opens a STREAMFILE that clamps reads to a section of a larger streamfile.
|
||||
* Can be used with subfiles inside a bigger file (to fool metas, or to simplify custom IO). */
|
||||
STREAMFILE *open_clamp_streamfile(STREAMFILE *streamfile, off_t start, size_t size);
|
||||
|
||||
/* A STREAMFILE with custom IO, that clamps IO to a section of a larger stream.
|
||||
* Can be used with subfiles inside a bigger file, so it looks standard to a meta. */
|
||||
/* Opens a STREAMFILE that uses custom IO for streamfile reads.
|
||||
* Can be used to modify data on the fly (ex. decryption), or even transform it from a format to another. */
|
||||
STREAMFILE *open_io_streamfile(STREAMFILE *streamfile, void* data, size_t data_size, void* read_callback);//void* size_callback, void* seek_callback);
|
||||
|
||||
/* A STREAMFILE that reports a fake name, but still re-opens itself properly.
|
||||
/* Opens a STREAMFILE that reports a fake name, but still re-opens itself properly.
|
||||
* Can be used to trick a meta's extension check (to call from another, with a modified SF).
|
||||
* When fakename isn't supplied it's read from the streamfile, and the extension swapped with fakeext.
|
||||
* If the fakename is an existing file, open won't work on it as it'll reopen the fake-named streamfile. */
|
||||
STREAMFILE *open_fakename_streamfile(STREAMFILE *streamfile, const char * fakename, const char * fakeext);
|
||||
|
||||
/* A streamfile formed from multiple streamfiles, their data joined during reads.
|
||||
//todo probably could simply use custom IO
|
||||
/* Opens streamfile formed from multiple streamfiles, their data joined during reads.
|
||||
* Can be used when data is segmented in multiple separate files.
|
||||
* The first streamfile is used to get names, stream index and so on. */
|
||||
STREAMFILE *open_multifile_streamfile(STREAMFILE **streamfiles, size_t streamfiles_size);
|
||||
|
||||
/* Opens a STREAMFILE from a base pathname + new extension
|
||||
* Can be used to get companion headers. */
|
||||
STREAMFILE * open_streamfile_by_ext(STREAMFILE *streamFile, const char * ext);
|
||||
|
||||
/* Opens a STREAMFILE from a base path + new filename
|
||||
* Can be used to get companion files. */
|
||||
STREAMFILE * open_streamfile_by_filename(STREAMFILE *streamFile, const char * filename);
|
||||
|
||||
|
||||
/* close a file, destroy the STREAMFILE object */
|
||||
static inline void close_streamfile(STREAMFILE * streamfile) {
|
||||
if (streamfile==NULL) return;
|
||||
if (streamfile!=NULL)
|
||||
streamfile->close(streamfile);
|
||||
}
|
||||
|
||||
@ -164,9 +174,6 @@ static inline int8_t read_8bit(off_t offset, STREAMFILE * streamfile) {
|
||||
|
||||
size_t get_streamfile_text_line(int dst_length, char * dst, off_t offset, STREAMFILE * streamfile, int *line_done_ptr);
|
||||
|
||||
STREAMFILE * open_stream_ext(STREAMFILE *streamFile, const char * ext);
|
||||
STREAMFILE * open_stream_name(STREAMFILE *streamFile, const char * ext);
|
||||
|
||||
size_t read_string(char * buf, size_t bufsize, off_t offset, STREAMFILE *streamFile);
|
||||
|
||||
size_t read_key_file(uint8_t * buf, size_t bufsize, STREAMFILE *streamFile);
|
||||
|
Loading…
x
Reference in New Issue
Block a user