use File::size() method were it makes sense; one small change to simon.cpp based on comment on bug #595813

svn-id: r5210
This commit is contained in:
Max Horn 2002-10-21 12:34:54 +00:00
parent 46a3039f70
commit 31c773923e
3 changed files with 9 additions and 29 deletions

View file

@ -1300,8 +1300,7 @@ int Sound::getCachedTrack(int track) {
mad_frame_finish(&frame); mad_frame_finish(&frame);
mad_stream_finish(&stream); mad_stream_finish(&stream);
// Get file size // Get file size
file->seek(0, SEEK_END); _mp3_size[current_index] = file->size();
_mp3_size[current_index] = file->pos();
_mp3_tracks[current_index] = file; _mp3_tracks[current_index] = file;
return current_index; return current_index;

View file

@ -123,13 +123,11 @@ bool SimonState::loadGamePcFile(const char *filename)
if (in->isOpen() == false) if (in->isOpen() == false)
return false; return false;
in->seek(0, SEEK_END); file_size = in->size();
file_size = in->pos();
_tbl_list = (byte *)malloc(file_size); _tbl_list = (byte *)malloc(file_size);
if (_tbl_list == NULL) if (_tbl_list == NULL)
error("Out of memory for strip table list"); error("Out of memory for strip table list");
in->seek(0, SEEK_SET);
in->read(_tbl_list, file_size); in->read(_tbl_list, file_size);
in->close(); in->close();
@ -143,12 +141,10 @@ bool SimonState::loadGamePcFile(const char *filename)
if (in->isOpen() == false) if (in->isOpen() == false)
return false; return false;
in->seek(0, SEEK_END); file_size = in->size();
file_size = in->pos();
_stripped_txt_mem = (byte *)malloc(file_size); _stripped_txt_mem = (byte *)malloc(file_size);
if (_stripped_txt_mem == NULL) if (_stripped_txt_mem == NULL)
error("Out of memory for strip text list"); error("Out of memory for strip text list");
in->seek(0, SEEK_SET);
in->read(_stripped_txt_mem, file_size); in->read(_stripped_txt_mem, file_size);
in->close(); in->close();

View file

@ -869,9 +869,7 @@ uint SimonState::loadTextFile_simon1(const char *filename, byte *dst)
if (fo.isOpen() == false) if (fo.isOpen() == false)
error("loadTextFile: Cannot open '%s'", filename); error("loadTextFile: Cannot open '%s'", filename);
fo.seek(0, SEEK_END); size = fo.size();
size = fo.pos();
fo.seek(0, SEEK_SET);
if (fo.read(dst, size) != size) if (fo.read(dst, size) != size)
error("loadTextFile: fread failed"); error("loadTextFile: fread failed");
@ -1421,15 +1419,12 @@ void SimonState::loadIconFile()
if (in.isOpen() == false) if (in.isOpen() == false)
error("Cannot open icon.dat"); error("Cannot open icon.dat");
in.seek(0, SEEK_END); size = in.size();
size = in.pos();
_icon_file_ptr = (byte *)malloc(size); _icon_file_ptr = (byte *)malloc(size);
if (_icon_file_ptr == NULL) if (_icon_file_ptr == NULL)
error("Out of icon memory"); error("Out of icon memory");
in.seek(0, SEEK_SET);
in.read(_icon_file_ptr, size); in.read(_icon_file_ptr, size);
in.close(); in.close();
} }
@ -3276,10 +3271,7 @@ void SimonState::readSfxFile(const char *filename)
return; return;
} }
in.seek(0, SEEK_END); size = in.size();
size = in.pos();
in.seek(0, SEEK_SET);
/* stop all sounds */ /* stop all sounds */
_mixer->stopAll(); _mixer->stopAll();
@ -4036,9 +4028,7 @@ void SimonState::read_vga_from_datfile_1(uint vga_id)
return; return;
} }
in.seek(0, SEEK_END); size = in.size();
size = in.pos();
in.seek(0, SEEK_SET);
if (in.read(_vga_buffer_pointers[11].vgaFile2, size) != size) if (in.read(_vga_buffer_pointers[11].vgaFile2, size) != size)
error("read_vga_from_datfile_1: read failed"); error("read_vga_from_datfile_1: read failed");
@ -4066,9 +4056,7 @@ byte *SimonState::read_vga_from_datfile_2(uint id)
if (in.isOpen() == false) if (in.isOpen() == false)
error("read_vga_from_datfile_2: cannot open %s", buf); error("read_vga_from_datfile_2: cannot open %s", buf);
in.seek(0, SEEK_END); size = in.size();
size = in.pos();
in.seek(0, SEEK_SET);
dst = setup_vga_destination(size); dst = setup_vga_destination(size);
@ -4880,10 +4868,7 @@ void SimonState::playMusic(uint music)
/* FIXME: not properly implemented */ /* FIXME: not properly implemented */
if (_game & GAME_WIN) { if (_game & GAME_WIN) {
int32 offset = _game_offsets_ptr[gss->MUSIC_INDEX_BASE + music]; _game_file->seek(_game_offsets_ptr[gss->MUSIC_INDEX_BASE + music], SEEK_SET);
if (_game & GAME_SIMON2)
offset--;
_game_file->seek(offset, SEEK_SET);
File *f = _game_file; File *f = _game_file;
midi.read_all_songs(f); midi.read_all_songs(f);
} else { } else {