Fix: Better "temp" path for decoded MPSMIDI files when source filename has no path separators

This commit is contained in:
Niels Martin Hansen 2018-09-03 18:43:55 +02:00
parent 560b01f307
commit bb086f9240
1 changed files with 8 additions and 6 deletions

View File

@ -1020,16 +1020,18 @@ std::string MidiFile::GetSMFFile(const MusicSongInfo &song)
if (song.filetype != MTT_MPSMIDI) return std::string();
const char *lastpathsep = strrchr(song.filename, PATHSEPCHAR);
if (lastpathsep == NULL) {
lastpathsep = song.filename;
}
char basename[MAX_PATH];
{
const char *fnstart = strrchr(song.filename, PATHSEPCHAR);
if (fnstart == NULL) {
fnstart = song.filename;
} else {
fnstart++;
}
/* Remove all '.' characters from filename */
char *wp = basename;
for (const char *rp = lastpathsep + 1; *rp != '\0'; rp++) {
for (const char *rp = fnstart; *rp != '\0'; rp++) {
if (*rp != '.') *wp++ = *rp;
}
*wp++ = '\0';