Changeset - r27159:693b9615eaea
[Not reviewed]
master
0 8 0
Rubidium - 14 months ago 2023-04-18 20:21:17
rubidium@openttd.org
Codechange: use std::string for base media filename/warning storage
8 files changed with 39 insertions and 44 deletions:
0 comments (0 inline, 0 general)
src/base_media_base.h
Show inline comments
 
@@ -28,15 +28,15 @@ struct MD5File {
 
		CR_UNKNOWN,  ///< The file has not been checked yet
 
		CR_MATCH,    ///< The file did exist and the md5 checksum did match
 
		CR_MISMATCH, ///< The file did exist, just the md5 checksum did not match
 
		CR_NO_FILE,  ///< The file did not exist
 
	};
 

	
 
	const char *filename;        ///< filename
 
	std::string filename;        ///< filename
 
	uint8 hash[16];              ///< md5 sum of the file
 
	const char *missing_warning; ///< warning when this file is missing
 
	std::string missing_warning; ///< warning when this file is missing
 
	ChecksumResult check_result; ///< cached result of md5 check
 

	
 
	ChecksumResult CheckMD5(Subdirectory subdir, size_t max_size) const;
 
};
 

	
 
/**
 
@@ -70,17 +70,12 @@ struct BaseSet {
 

	
 
	T *next;                       ///< The next base set in this list
 

	
 
	/** Free everything we allocated */
 
	~BaseSet()
 
	{
 
		for (uint i = 0; i < NUM_FILES; i++) {
 
			free(this->files[i].filename);
 
			free(this->files[i].missing_warning);
 
		}
 

	
 
		delete this->next;
 
	}
 

	
 
	/**
 
	 * Get the number of missing files.
 
	 * @return the number
 
@@ -97,13 +92,13 @@ struct BaseSet {
 
	 */
 
	int GetNumInvalid() const
 
	{
 
		return Tnum_files - this->valid_files;
 
	}
 

	
 
	bool FillSetDetails(IniFile *ini, const char *path, const char *full_filename, bool allow_empty_filename = true);
 
	bool FillSetDetails(IniFile *ini, const std::string &path, const std::string &full_filename, bool allow_empty_filename = true);
 

	
 
	/**
 
	 * Get the description for the given ISO code.
 
	 * It falls back to the first two characters of the ISO code in case
 
	 * no match could be made with the full ISO code. If even then the
 
	 * matching fails the default is returned.
 
@@ -144,13 +139,13 @@ struct BaseSet {
 
	 * @param type The type of the textfile to search for.
 
	 * @return The filename for the textfile, \c nullptr otherwise.
 
	 */
 
	const char *GetTextfile(TextfileType type) const
 
	{
 
		for (uint i = 0; i < NUM_FILES; i++) {
 
			const char *textfile = ::GetTextfile(type, BASESET_DIR, this->files[i].filename);
 
			const char *textfile = ::GetTextfile(type, BASESET_DIR, this->files[i].filename.c_str());
 
			if (textfile != nullptr) {
 
				return textfile;
 
			}
 
		}
 
		return nullptr;
 
	}
 
@@ -246,13 +241,13 @@ enum BlitterType {
 

	
 
/** All data of a graphics set. */
 
struct GraphicsSet : BaseSet<GraphicsSet, MAX_GFT, true> {
 
	PaletteType palette;       ///< Palette of this graphics set
 
	BlitterType blitter;       ///< Blitter of this graphics set
 

	
 
	bool FillSetDetails(struct IniFile *ini, const char *path, const char *full_filename);
 
	bool FillSetDetails(struct IniFile *ini, const std::string &path, const std::string &full_filename);
 

	
 
	static MD5File::ChecksumResult CheckMD5(const MD5File *file, Subdirectory subdir);
 
};
 

	
 
/** All data/functions related with replacing the base graphics. */
 
class BaseGraphics : public BaseMedia<GraphicsSet> {
 
@@ -276,25 +271,25 @@ static const uint NUM_SONG_CLASSES    = 
 
static const uint NUM_SONGS_AVAILABLE = 1 + NUM_SONG_CLASSES * NUM_SONGS_CLASS;
 

	
 
/** Maximum number of songs in the (custom) playlist */
 
static const uint NUM_SONGS_PLAYLIST  = 32;
 

	
 
/* Functions to read DOS music CAT files, similar to but not quite the same as sound effect CAT files */
 
char *GetMusicCatEntryName(const char *filename, size_t entrynum);
 
byte *GetMusicCatEntryData(const char *filename, size_t entrynum, size_t &entrylen);
 
char *GetMusicCatEntryName(const std::string &filename, size_t entrynum);
 
byte *GetMusicCatEntryData(const std::string &filename, size_t entrynum, size_t &entrylen);
 

	
 
enum MusicTrackType {
 
	MTT_STANDARDMIDI, ///< Standard MIDI file
 
	MTT_MPSMIDI,      ///< MPS GM driver MIDI format (contained in a CAT file)
 
};
 

	
 
/** Metadata about a music track. */
 
struct MusicSongInfo {
 
	std::string songname;    ///< name of song displayed in UI
 
	byte tracknr;            ///< track number of song displayed in UI
 
	const char *filename;    ///< file on disk containing song (when used in MusicSet class, this pointer is owned by MD5File object for the file)
 
	std::string filename;    ///< file on disk containing song (when used in MusicSet class)
 
	MusicTrackType filetype; ///< decoder required for song file
 
	int cat_index;           ///< entry index in CAT file, for filetype==MTT_MPSMIDI
 
	bool loop;               ///< song should play in a tight loop if possible, never ending
 
	int override_start;      ///< MIDI ticks to skip over in beginning
 
	int override_end;        ///< MIDI tick to end the song at (0 if no override)
 
};
 
@@ -303,13 +298,13 @@ struct MusicSongInfo {
 
struct MusicSet : BaseSet<MusicSet, NUM_SONGS_AVAILABLE, false> {
 
	/** Data about individual songs in set. */
 
	MusicSongInfo songinfo[NUM_SONGS_AVAILABLE];
 
	/** Number of valid songs in set. */
 
	byte num_available;
 

	
 
	bool FillSetDetails(struct IniFile *ini, const char *path, const char *full_filename);
 
	bool FillSetDetails(struct IniFile *ini, const std::string &path, const std::string &full_filename);
 
};
 

	
 
/** All data/functions related with replacing the base music */
 
class BaseMusic : public BaseMedia<MusicSet> {
 
public:
 
};
src/base_media_func.h
Show inline comments
 
@@ -35,13 +35,13 @@ extern void CheckExternalFiles();
 
 * @param path     the path to this ini file (for filenames)
 
 * @param full_filename the full filename of the loaded file (for error reporting purposes)
 
 * @param allow_empty_filename empty filenames are valid
 
 * @return true if loading was successful.
 
 */
 
template <class T, size_t Tnum_files, bool Tsearch_in_tars>
 
bool BaseSet<T, Tnum_files, Tsearch_in_tars>::FillSetDetails(IniFile *ini, const char *path, const char *full_filename, bool allow_empty_filename)
 
bool BaseSet<T, Tnum_files, Tsearch_in_tars>::FillSetDetails(IniFile *ini, const std::string &path, const std::string &full_filename, bool allow_empty_filename)
 
{
 
	IniGroup *metadata = ini->GetGroup("metadata");
 
	IniItem *item;
 

	
 
	fetch_metadata("name");
 
	this->name = *item->value;
 
@@ -78,21 +78,21 @@ bool BaseSet<T, Tnum_files, Tsearch_in_t
 
		if (item == nullptr || (!item->value.has_value() && !allow_empty_filename)) {
 
			Debug(grf, 0, "No " SET_TYPE " file for: {} (in {})", BaseSet<T, Tnum_files, Tsearch_in_tars>::file_names[i], full_filename);
 
			return false;
 
		}
 

	
 
		if (!item->value.has_value()) {
 
			file->filename = nullptr;
 
			file->filename.clear();
 
			/* If we list no file, that file must be valid */
 
			this->valid_files++;
 
			this->found_files++;
 
			continue;
 
		}
 

	
 
		const char *filename = item->value->c_str();
 
		file->filename = str_fmt("%s%s", path, filename);
 
		const std::string &filename = item->value.value();
 
		file->filename = path + filename;
 

	
 
		/* Then find the MD5 checksum */
 
		item = md5s->GetItem(filename, false);
 
		if (item == nullptr || !item->value.has_value()) {
 
			Debug(grf, 0, "No MD5 checksum specified for: {} (in {})", filename, full_filename);
 
			return false;
 
@@ -119,15 +119,15 @@ bool BaseSet<T, Tnum_files, Tsearch_in_t
 

	
 
		/* Then find the warning message when the file's missing */
 
		item = origin->GetItem(filename, false);
 
		if (item == nullptr) item = origin->GetItem("default", false);
 
		if (item == nullptr || !item->value.has_value()) {
 
			Debug(grf, 1, "No origin warning message specified for: {}", filename);
 
			file->missing_warning = stredup("");
 
			file->missing_warning.clear();
 
		} else {
 
			file->missing_warning = stredup(item->value->c_str());
 
			file->missing_warning = item->value.value();
 
		}
 

	
 
		file->check_result = T::CheckMD5(file, BASESET_DIR);
 
		switch (file->check_result) {
 
			case MD5File::CR_UNKNOWN:
 
				break;
 
@@ -166,13 +166,13 @@ bool BaseMedia<Tbase_set>::AddFile(const
 
	if (psep != std::string::npos) {
 
		path.erase(psep + 1);
 
	} else {
 
		path.clear();
 
	}
 

	
 
	if (set->FillSetDetails(ini, path.c_str(), filename.c_str())) {
 
	if (set->FillSetDetails(ini, path, filename)) {
 
		Tbase_set *duplicate = nullptr;
 
		for (Tbase_set *c = BaseMedia<Tbase_set>::available_sets; c != nullptr; c = c->next) {
 
			if (c->name == set->name || c->shortname == set->shortname) {
 
				duplicate = c;
 
				break;
 
			}
 
@@ -279,22 +279,22 @@ template <class Tbase_set>
 
template <class Tbase_set> const char *TryGetBaseSetFile(const ContentInfo *ci, bool md5sum, const Tbase_set *s)
 
{
 
	for (; s != nullptr; s = s->next) {
 
		if (s->GetNumMissing() != 0) continue;
 

	
 
		if (s->shortname != ci->unique_id) continue;
 
		if (!md5sum) return  s->files[0].filename;
 
		if (!md5sum) return s->files[0].filename.c_str();
 

	
 
		byte md5[16];
 
		memset(md5, 0, sizeof(md5));
 
		for (uint i = 0; i < Tbase_set::NUM_FILES; i++) {
 
			for (uint j = 0; j < sizeof(md5); j++) {
 
				md5[j] ^= s->files[i].hash[j];
 
			}
 
		}
 
		if (memcmp(md5, ci->md5sum, sizeof(md5)) == 0) return s->files[0].filename;
 
		if (memcmp(md5, ci->md5sum, sizeof(md5)) == 0) return s->files[0].filename.c_str();
 
	}
 
	return nullptr;
 
}
 

	
 
template <class Tbase_set>
 
/* static */ bool BaseMedia<Tbase_set>::HasSet(const ContentInfo *ci, bool md5sum)
src/fileio.cpp
Show inline comments
 
@@ -137,13 +137,13 @@ void FioFCloseFile(FILE *f)
 
/**
 
 * Find a path to the filename in one of the search directories.
 
 * @param subdir Subdirectory to try.
 
 * @param filename Filename to look for.
 
 * @return String containing the path if the path was found, else an empty string.
 
 */
 
std::string FioFindFullPath(Subdirectory subdir, const char *filename)
 
std::string FioFindFullPath(Subdirectory subdir, const std::string &filename)
 
{
 
	assert(subdir < NUM_SUBDIRS);
 

	
 
	for (Searchpath sp : _valid_searchpaths) {
 
		std::string buf = FioGetDirectory(sp, subdir);
 
		buf += filename;
src/fileio_func.h
Show inline comments
 
@@ -15,13 +15,13 @@
 
#include <string>
 
#include <vector>
 

	
 
void FioFCloseFile(FILE *f);
 
FILE *FioFOpenFile(const std::string &filename, const char *mode, Subdirectory subdir, size_t *filesize = nullptr);
 
bool FioCheckFileExists(const std::string &filename, Subdirectory subdir);
 
std::string FioFindFullPath(Subdirectory subdir, const char *filename);
 
std::string FioFindFullPath(Subdirectory subdir, const std::string &filename);
 
std::string FioGetDirectory(Searchpath sp, Subdirectory subdir);
 
std::string FioFindDirectory(Subdirectory subdir);
 
void FioCreateDirectory(const std::string &name);
 

	
 
const char *FiosGetScreenshotDir();
 

	
src/gfxinit.cpp
Show inline comments
 
@@ -39,23 +39,23 @@ static const SpriteID * const _landscape
 
 * Load an old fashioned GRF file.
 
 * @param filename   The name of the file to open.
 
 * @param load_index The offset of the first sprite.
 
 * @param needs_palette_remap Whether the colours in the GRF file need a palette remap.
 
 * @return The number of loaded sprites.
 
 */
 
static uint LoadGrfFile(const char *filename, uint load_index, bool needs_palette_remap)
 
static uint LoadGrfFile(const std::string &filename, uint load_index, bool needs_palette_remap)
 
{
 
	uint load_index_org = load_index;
 
	uint sprite_id = 0;
 

	
 
	SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap);
 

	
 
	Debug(sprite, 2, "Reading grf-file '{}'", filename);
 

	
 
	byte container_ver = file.GetContainerVersion();
 
	if (container_ver == 0) usererror("Base grf '%s' is corrupt", filename);
 
	if (container_ver == 0) usererror("Base grf '%s' is corrupt", filename.c_str());
 
	ReadGRFSpriteOffsets(file);
 
	if (container_ver >= 2) {
 
		/* Read compression. */
 
		byte compression = file.ReadByte();
 
		if (compression != 0) usererror("Unsupported compression format");
 
	}
 
@@ -76,23 +76,23 @@ static uint LoadGrfFile(const char *file
 
 * Load an old fashioned GRF file to replace already loaded sprites.
 
 * @param filename   The name of the file to open.
 
 * @param index_tbl  The offsets of each of the sprites.
 
 * @param needs_palette_remap Whether the colours in the GRF file need a palette remap.
 
 * @return The number of loaded sprites.
 
 */
 
static void LoadGrfFileIndexed(const char *filename, const SpriteID *index_tbl, bool needs_palette_remap)
 
static void LoadGrfFileIndexed(const std::string &filename, const SpriteID *index_tbl, bool needs_palette_remap)
 
{
 
	uint start;
 
	uint sprite_id = 0;
 

	
 
	SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap);
 

	
 
	Debug(sprite, 2, "Reading indexed grf-file '{}'", filename);
 

	
 
	byte container_ver = file.GetContainerVersion();
 
	if (container_ver == 0) usererror("Base grf '%s' is corrupt", filename);
 
	if (container_ver == 0) usererror("Base grf '%s' is corrupt", filename.c_str());
 
	ReadGRFSpriteOffsets(file);
 
	if (container_ver >= 2) {
 
		/* Read compression. */
 
		byte compression = file.ReadByte();
 
		if (compression != 0) usererror("Unsupported compression format");
 
	}
 
@@ -134,25 +134,25 @@ void CheckExternalFiles()
 

	
 
	if (used_set->GetNumInvalid() != 0) {
 
		/* Not all files were loaded successfully, see which ones */
 
		add_pos += seprintf(add_pos, last, "Trying to load graphics set '%s', but it is incomplete. The game will probably not run correctly until you properly install this set or select another one. See section 4.1 of README.md.\n\nThe following files are corrupted or missing:\n", used_set->name.c_str());
 
		for (uint i = 0; i < GraphicsSet::NUM_FILES; i++) {
 
			MD5File::ChecksumResult res = GraphicsSet::CheckMD5(&used_set->files[i], BASESET_DIR);
 
			if (res != MD5File::CR_MATCH) add_pos += seprintf(add_pos, last, "\t%s is %s (%s)\n", used_set->files[i].filename, res == MD5File::CR_MISMATCH ? "corrupt" : "missing", used_set->files[i].missing_warning);
 
			if (res != MD5File::CR_MATCH) add_pos += seprintf(add_pos, last, "\t%s is %s (%s)\n", used_set->files[i].filename.c_str(), res == MD5File::CR_MISMATCH ? "corrupt" : "missing", used_set->files[i].missing_warning.c_str());
 
		}
 
		add_pos += seprintf(add_pos, last, "\n");
 
	}
 

	
 
	const SoundsSet *sounds_set = BaseSounds::GetUsedSet();
 
	if (sounds_set->GetNumInvalid() != 0) {
 
		add_pos += seprintf(add_pos, last, "Trying to load sound set '%s', but it is incomplete. The game will probably not run correctly until you properly install this set or select another one. See section 4.1 of README.md.\n\nThe following files are corrupted or missing:\n", sounds_set->name.c_str());
 

	
 
		static_assert(SoundsSet::NUM_FILES == 1);
 
		/* No need to loop each file, as long as there is only a single
 
		 * sound file. */
 
		add_pos += seprintf(add_pos, last, "\t%s is %s (%s)\n", sounds_set->files->filename, SoundsSet::CheckMD5(sounds_set->files, BASESET_DIR) == MD5File::CR_MISMATCH ? "corrupt" : "missing", sounds_set->files->missing_warning);
 
		add_pos += seprintf(add_pos, last, "\t%s is %s (%s)\n", sounds_set->files->filename.c_str(), SoundsSet::CheckMD5(sounds_set->files, BASESET_DIR) == MD5File::CR_MISMATCH ? "corrupt" : "missing", sounds_set->files->missing_warning.c_str());
 
	}
 

	
 
	if (add_pos != error_msg) ShowInfoI(error_msg);
 
}
 

	
 
/** Actually load the sprite tables. */
 
@@ -198,13 +198,13 @@ static void LoadSpriteTables()
 
	GRFConfig *master = new GRFConfig(master_filename);
 
	master->palette |= GRFP_GRF_DOS;
 
	FillGRFDetails(master, false, BASESET_DIR);
 
	ClrBit(master->flags, GCF_INIT_ONLY);
 

	
 
	/* Baseset extra graphics */
 
	GRFConfig *extra = new GRFConfig(used_set->files[GFT_EXTRA].filename);
 
	GRFConfig *extra = new GRFConfig(used_set->files[GFT_EXTRA].filename.c_str());
 

	
 
	/* We know the palette of the base set, so if the base NewGRF is not
 
	 * setting one, use the palette of the base set and not the global
 
	 * one which might be the wrong palette for this base NewGRF.
 
	 * The value set here might be overridden via action14 later. */
 
	switch (used_set->palette) {
 
@@ -352,13 +352,13 @@ void GfxLoadSprites()
 
	LoadSpriteTables();
 
	GfxInitPalettes();
 

	
 
	UpdateCursorSize();
 
}
 

	
 
bool GraphicsSet::FillSetDetails(IniFile *ini, const char *path, const char *full_filename)
 
bool GraphicsSet::FillSetDetails(IniFile *ini, const std::string &path, const std::string &full_filename)
 
{
 
	bool ret = this->BaseSet<GraphicsSet, MAX_GFT, true>::FillSetDetails(ini, path, full_filename, false);
 
	if (ret) {
 
		IniGroup *metadata = ini->GetGroup("metadata");
 
		IniItem *item;
 

	
src/music.cpp
Show inline comments
 
@@ -22,13 +22,13 @@
 
 * Read the name of a music CAT file entry.
 
 * @param filename Name of CAT file to read from
 
 * @param entrynum Index of entry whose name to read
 
 * @return Pointer to string, caller is responsible for freeing memory,
 
 *         nullptr if entrynum does not exist.
 
 */
 
char *GetMusicCatEntryName(const char *filename, size_t entrynum)
 
char *GetMusicCatEntryName(const std::string &filename, size_t entrynum)
 
{
 
	if (!FioCheckFileExists(filename, BASESET_DIR)) return nullptr;
 

	
 
	RandomAccessFile file(filename, BASESET_DIR);
 
	uint32 ofs = file.ReadDword();
 
	size_t entry_count = ofs / 8;
 
@@ -49,13 +49,13 @@ char *GetMusicCatEntryName(const char *f
 
 * @param filename Name of CAT file to read from.
 
 * @param entrynum Index of entry to read
 
 * @param[out] entrylen Receives length of data read
 
 * @return Pointer to buffer with data read, caller is responsible for freeind memory,
 
 *         nullptr if entrynum does not exist.
 
 */
 
byte *GetMusicCatEntryData(const char *filename, size_t entrynum, size_t &entrylen)
 
byte *GetMusicCatEntryData(const std::string &filename, size_t entrynum, size_t &entrylen)
 
{
 
	entrylen = 0;
 
	if (!FioCheckFileExists(filename, BASESET_DIR)) return nullptr;
 

	
 
	RandomAccessFile file(filename, BASESET_DIR);
 
	uint32 ofs = file.ReadDword();
 
@@ -113,24 +113,24 @@ template <class Tbase_set>
 
	}
 

	
 
	BaseMedia<Tbase_set>::used_set = best;
 
	return BaseMedia<Tbase_set>::used_set != nullptr;
 
}
 

	
 
bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_filename)
 
bool MusicSet::FillSetDetails(IniFile *ini, const std::string &path, const std::string &full_filename)
 
{
 
	bool ret = this->BaseSet<MusicSet, NUM_SONGS_AVAILABLE, false>::FillSetDetails(ini, path, full_filename);
 
	if (ret) {
 
		this->num_available = 0;
 
		IniGroup *names = ini->GetGroup("names");
 
		IniGroup *catindex = ini->GetGroup("catindex");
 
		IniGroup *timingtrim = ini->GetGroup("timingtrim");
 
		uint tracknr = 1;
 
		for (uint i = 0; i < lengthof(this->songinfo); i++) {
 
			const char *filename = this->files[i].filename;
 
			if (names == nullptr || StrEmpty(filename) || this->files[i].check_result == MD5File::CR_NO_FILE) {
 
			const std::string &filename = this->files[i].filename;
 
			if (filename.empty() || this->files[i].check_result == MD5File::CR_NO_FILE) {
 
				continue;
 
			}
 

	
 
			this->songinfo[i].filename = filename; // non-owned pointer
 

	
 
			IniItem *item = catindex->GetItem(_music_file_names[i], false);
 
@@ -146,13 +146,13 @@ bool MusicSet::FillSetDetails(IniFile *i
 
				this->songinfo[i].songname = songname;
 
				free(songname);
 
			} else {
 
				this->songinfo[i].filetype = MTT_STANDARDMIDI;
 
			}
 

	
 
			const char *trimmed_filename = filename;
 
			const char *trimmed_filename = filename.c_str();
 
			/* As we possibly add a path to the filename and we compare
 
			 * on the filename with the path as in the .obm, we need to
 
			 * keep stripping path elements until we find a match. */
 
			for (; trimmed_filename != nullptr; trimmed_filename = strchr(trimmed_filename, PATHSEPCHAR)) {
 
				/* Remove possible double path separator characters from
 
				 * the beginning, so we don't start reading e.g. root. */
src/music/midifile.cpp
Show inline comments
 
@@ -846,13 +846,13 @@ bool MidiFile::LoadMpsData(const byte *d
 
}
 

	
 
bool MidiFile::LoadSong(const MusicSongInfo &song)
 
{
 
	switch (song.filetype) {
 
		case MTT_STANDARDMIDI:
 
			return this->LoadFile(song.filename);
 
			return this->LoadFile(song.filename.c_str());
 
		case MTT_MPSMIDI:
 
		{
 
			size_t songdatalen = 0;
 
			byte *songdata = GetMusicCatEntryData(song.filename, song.cat_index, songdatalen);
 
			if (songdata != nullptr) {
 
				bool result = this->LoadMpsData(songdata, songdatalen);
 
@@ -1057,15 +1057,15 @@ std::string MidiFile::GetSMFFile(const M
 
	}
 

	
 
	if (song.filetype != MTT_MPSMIDI) return std::string();
 

	
 
	char basename[MAX_PATH];
 
	{
 
		const char *fnstart = strrchr(song.filename, PATHSEPCHAR);
 
		const char *fnstart = strrchr(song.filename.c_str(), PATHSEPCHAR);
 
		if (fnstart == nullptr) {
 
			fnstart = song.filename;
 
			fnstart = song.filename.c_str();
 
		} else {
 
			fnstart++;
 
		}
 

	
 
		/* Remove all '.' characters from filename */
 
		char *wp = basename;
src/sound.cpp
Show inline comments
 
@@ -20,24 +20,24 @@
 
#include "base_media_func.h"
 

	
 
#include "safeguards.h"
 

	
 
static SoundEntry _original_sounds[ORIGINAL_SAMPLE_COUNT];
 

	
 
static void OpenBankFile(const char *filename)
 
static void OpenBankFile(const std::string &filename)
 
{
 
	/**
 
	 * The sound file for the original sounds, i.e. those not defined/overridden by a NewGRF.
 
	 * Needs to be kept alive during the game as _original_sounds[n].file refers to this.
 
	 */
 
	static std::unique_ptr<RandomAccessFile> original_sound_file;
 

	
 
	memset(_original_sounds, 0, sizeof(_original_sounds));
 

	
 
	/* If there is no sound file (nosound set), don't load anything */
 
	if (filename == nullptr) return;
 
	if (filename.empty()) return;
 

	
 
	original_sound_file.reset(new RandomAccessFile(filename, BASESET_DIR));
 
	size_t pos = original_sound_file->GetPos();
 
	uint count = original_sound_file->ReadDword();
 

	
 
	/* The new format has the highest bit always set */
0 comments (0 inline, 0 general)