Improve error reporting for read_sndfile

Move error reporting down into read_sndfile, so that individual failure
paths can have specific error messages.
This commit is contained in:
Kp 2021-07-25 23:00:56 +00:00
parent a7cbf60922
commit b2968c55da
3 changed files with 14 additions and 10 deletions

View file

@ -152,7 +152,7 @@ void load_d1_bitmap_replacements();
*/
grs_bitmap *read_extra_bitmap_d1_pig(const char *name, grs_bitmap &out);
int read_hamfile();
int read_sndfile();
void read_sndfile(int required);
#endif
}

View file

@ -894,7 +894,7 @@ int load_mission_ham()
{
// re-read sounds in case mission has custom .sXX
Num_sound_files = 0;
read_sndfile();
read_sndfile(0);
piggy_read_sounds();
}

View file

@ -1075,7 +1075,7 @@ int read_hamfile()
return 1;
}
int read_sndfile()
void read_sndfile(const int required)
{
int snd_id,snd_version;
int N_sounds;
@ -1087,15 +1087,22 @@ int read_sndfile()
char temp_name_read[16];
int sbytes = 0;
auto snd_fp = PHYSFSX_openReadBuffered(DEFAULT_SNDFILE);
const auto filename = DEFAULT_SNDFILE;
auto snd_fp = PHYSFSX_openReadBuffered(filename);
if (!snd_fp)
return 0;
{
if (required)
Error("Cannot open sound file: %s\n", filename);
return;
}
//make sure soundfile is valid type file & is up-to-date
snd_id = PHYSFSX_readInt(snd_fp);
snd_version = PHYSFSX_readInt(snd_fp);
if (snd_id != SNDFILE_ID || snd_version != SNDFILE_VERSION) {
return 0;
if (required)
Error("Cannot load sound file: expected (id=%.8lx version=%.8x), found (id=%.8x version=%.8x) in \"%s\"", SNDFILE_ID, SNDFILE_VERSION, snd_id, snd_version, filename);
return;
}
N_sounds = PHYSFSX_readInt(snd_fp);
@ -1117,7 +1124,6 @@ int read_sndfile()
sbytes += sndh.length;
}
SoundBits = std::make_unique<ubyte[]>(sbytes + 16);
return 1;
}
int properties_init(void)
@ -1159,9 +1165,7 @@ int properties_init(void)
if (Piggy_hamfile_version >= 3)
{
snd_ok = read_sndfile();
if (!snd_ok)
Error("Cannot open sound file: %s\n", DEFAULT_SNDFILE);
read_sndfile(1);
}
return (ham_ok && snd_ok); //read ok