summaryrefslogtreecommitdiff
path: root/src/music
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2020-12-06 21:11:44 +0100
committerMichael Lutz <michi@icosahedron.de>2020-12-27 13:19:25 +0100
commitf3326d34e78bd28fba6d8cfd3bc455a506b429fe (patch)
tree307a0608a7fb1c211fd72a8b8326cfe9bb1d37a2 /src/music
parent0c6e8a8123c9f74db757272f73adcbd8621e012d (diff)
downloadopenttd-f3326d34e78bd28fba6d8cfd3bc455a506b429fe.tar.xz
Codechange: Use std::string in FIO search path handling.
Diffstat (limited to 'src/music')
-rw-r--r--src/music/midifile.cpp33
1 files changed, 15 insertions, 18 deletions
diff --git a/src/music/midifile.cpp b/src/music/midifile.cpp
index 67cc7b192..b15a27911 100644
--- a/src/music/midifile.cpp
+++ b/src/music/midifile.cpp
@@ -1048,14 +1048,12 @@ bool MidiFile::WriteSMF(const char *filename)
std::string MidiFile::GetSMFFile(const MusicSongInfo &song)
{
if (song.filetype == MTT_STANDARDMIDI) {
- char filename[MAX_PATH];
- if (FioFindFullPath(filename, lastof(filename), Subdirectory::BASESET_DIR, song.filename)) {
- return std::string(filename);
- } else if (FioFindFullPath(filename, lastof(filename), Subdirectory::OLD_GM_DIR, song.filename)) {
- return std::string(filename);
- } else {
- return std::string();
- }
+ std::string filename = FioFindFullPath(Subdirectory::BASESET_DIR, song.filename);
+ if (!filename.empty()) return filename;
+ filename = FioFindFullPath(Subdirectory::OLD_GM_DIR, song.filename);
+ if (!filename.empty()) return filename;
+
+ return std::string();
}
if (song.filetype != MTT_MPSMIDI) return std::string();
@@ -1077,17 +1075,16 @@ std::string MidiFile::GetSMFFile(const MusicSongInfo &song)
*wp++ = '\0';
}
- char tempdirname[MAX_PATH];
- FioGetFullPath(tempdirname, lastof(tempdirname), Searchpath::SP_AUTODOWNLOAD_DIR, Subdirectory::BASESET_DIR, basename);
- if (!AppendPathSeparator(tempdirname, lastof(tempdirname))) return std::string();
- FioCreateDirectory(tempdirname);
+ std::string tempdirname = FioGetDirectory(Searchpath::SP_AUTODOWNLOAD_DIR, Subdirectory::BASESET_DIR);
+ tempdirname += basename;
+ AppendPathSeparator(tempdirname);
+ FioCreateDirectory(tempdirname.c_str());
- char output_filename[MAX_PATH];
- seprintf(output_filename, lastof(output_filename), "%s%d.mid", tempdirname, song.cat_index);
+ std::string output_filename = tempdirname + std::to_string(song.cat_index) + ".mid";
- if (FileExists(output_filename)) {
+ if (FileExists(output_filename.c_str())) {
/* If the file already exists, assume it's the correct decoded data */
- return std::string(output_filename);
+ return output_filename;
}
byte *data;
@@ -1102,8 +1099,8 @@ std::string MidiFile::GetSMFFile(const MusicSongInfo &song)
}
free(data);
- if (midifile.WriteSMF(output_filename)) {
- return std::string(output_filename);
+ if (midifile.WriteSMF(output_filename.c_str())) {
+ return output_filename;
} else {
return std::string();
}