Fix companion files in relative folders for foobar [Rayman M (PS2)]

Also extra relative check for .isd and Ubi SB
This commit is contained in:
bnnm 2019-09-24 00:51:12 +02:00
parent 3090c08e18
commit 4010c3bd1b
4 changed files with 53 additions and 17 deletions

View File

@ -326,8 +326,15 @@ VGMSTREAM * init_vgmstream_ogg_vorbis(STREAMFILE *streamFile) {
if (isl_name) { if (isl_name) {
STREAMFILE *islFile = NULL; STREAMFILE *islFile = NULL;
//todo could try in ../(file) first since that's how the .isl is stored
islFile = open_streamfile_by_filename(streamFile, isl_name); islFile = open_streamfile_by_filename(streamFile, isl_name);
if (!islFile) {
/* try in ../(file) too since that's how the .isl is stored on disc */
char isl_path[PATH_LIMIT];
snprintf(isl_path, sizeof(isl_path), "../%s", isl_name);
islFile = open_streamfile_by_filename(streamFile, isl_path);
}
if (islFile) { if (islFile) {
STREAMFILE *dec_sf = NULL; STREAMFILE *dec_sf = NULL;

View File

@ -2399,6 +2399,8 @@ static int config_sb_version(ubi_sb_header * sb, STREAMFILE *streamFile) {
/* two configs with same id; use project file as identifier */ /* two configs with same id; use project file as identifier */
if (sb->version == 0x000A0007 && sb->platform == UBI_PS2) { if (sb->version == 0x000A0007 && sb->platform == UBI_PS2) {
STREAMFILE * streamTest = open_streamfile_by_filename(streamFile, "BIAAUDIO.SP1"); STREAMFILE * streamTest = open_streamfile_by_filename(streamFile, "BIAAUDIO.SP1");
if (!streamTest) /* try again for localized subfolders */
streamTest = open_streamfile_by_filename(streamFile, "../BIAAUDIO.SP1");
if (streamTest) { if (streamTest) {
is_bia_ps2 = 1; is_bia_ps2 = 1;
close_streamfile(streamTest); close_streamfile(streamTest);

View File

@ -800,25 +800,51 @@ STREAMFILE * open_streamfile_by_ext(STREAMFILE *streamFile, const char * ext) {
return streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); return streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
} }
STREAMFILE * open_streamfile_by_filename(STREAMFILE *streamFile, const char * name) { STREAMFILE * open_streamfile_by_filename(STREAMFILE *streamFile, const char * filename) {
char foldername[PATH_LIMIT]; char fullname[PATH_LIMIT];
char filename[PATH_LIMIT]; char partname[PATH_LIMIT];
const char *path; char *path, *name;
streamFile->get_name(streamFile,foldername,sizeof(foldername)); streamFile->get_name(streamFile, fullname, sizeof(fullname));
path = strrchr(foldername,DIR_SEPARATOR);
if (path!=NULL) path = path+1;
//todo normalize separators in a better way, safeops, improve copying
path = strrchr(fullname,DIR_SEPARATOR);
if (path) { if (path) {
strcpy(filename, foldername); path[1] = '\0'; /* remove name after separator */
filename[path-foldername] = '\0';
strcat(filename, name); strcpy(partname, filename);
} else { fix_dir_separators(partname);
strcpy(filename, name);
/* normalize relative paths as don't work ok in some plugins */
if (partname[0]=='.' && partname[1] == DIR_SEPARATOR) { /* './name' */
name = partname + 2; /* ignore './' */
}
else if (partname[0]=='.' && partname[1]=='.' && partname[2] == DIR_SEPARATOR) { /* '../name' */
char *pathprev;
path[0] = '\0'; /* remove last separator so next call works */
pathprev = strrchr(fullname,DIR_SEPARATOR);
if (pathprev) {
pathprev[1] = '\0'; /* remove prev dir after separator */
name = partname + 3; /* ignore '../' */
}
else { /* let plugin handle? */
path[0] = DIR_SEPARATOR;
name = partname;
}
/* could work with more relative paths but whatevs */
}
else {
name = partname;
}
strcat(fullname, name);
}
else {
strcpy(fullname, filename);
} }
return streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); return streamFile->open(streamFile, fullname, STREAMFILE_DEFAULT_BUFFER_SIZE);
} }
STREAMFILE * reopen_streamfile(STREAMFILE *streamFile, size_t buffer_size) { STREAMFILE * reopen_streamfile(STREAMFILE *streamFile, size_t buffer_size) {

View File

@ -119,8 +119,9 @@ STREAMFILE * open_streamfile(STREAMFILE *streamFile, const char * pathname);
* Can be used to get companion headers. */ * Can be used to get companion headers. */
STREAMFILE * open_streamfile_by_ext(STREAMFILE *streamFile, const char * ext); STREAMFILE * open_streamfile_by_ext(STREAMFILE *streamFile, const char * ext);
/* Opens a STREAMFILE from a base path + new filename /* Opens a STREAMFILE from a base path + new filename.
* Can be used to get companion files. */ * Can be used to get companion files. Relative paths like
* './filename', '../filename', 'dir/filename' also work. */
STREAMFILE * open_streamfile_by_filename(STREAMFILE *streamFile, const char * filename); STREAMFILE * open_streamfile_by_filename(STREAMFILE *streamFile, const char * filename);
/* Reopen a STREAMFILE with a different buffer size, for fine-tuned bigfile parsing. /* Reopen a STREAMFILE with a different buffer size, for fine-tuned bigfile parsing.