Logo Search packages:      
Sourcecode: scummvm version File versions  Download package

bool Agi::WagFileParser::checkWagVersion ( Common::SeekableReadStream stream ) [protected]

Checks if stream has a valid WinAGI version string in its end.

streamThe stream to be checked.
True if reading was successful and stream contains a valid WinAGI version string, false otherwise.

Definition at line 152 of file wagparser.cpp.

References Common::SeekableReadStream::pos(), Common::ReadStream::read(), Common::SeekableReadStream::seek(), Common::SeekableReadStream::size(), and WINAGI_VERSION_LENGTH.

Referenced by parse().

      if (stream.size() >= WINAGI_VERSION_LENGTH) { // Stream has space to contain the WinAGI version string
            // Read the last WINAGI_VERSION_LENGTH bytes of the stream and make a string out of it
            char str[WINAGI_VERSION_LENGTH+1]; // Allocate space for the trailing zero also
            uint32 oldStreamPos = stream.pos(); // Save the old stream position
            stream.seek(stream.size() - WINAGI_VERSION_LENGTH);
            uint32 readBytes = stream.read(str, WINAGI_VERSION_LENGTH);
            stream.seek(oldStreamPos); // Seek back to the old stream position
            str[readBytes] = 0; // Set the trailing zero to finish the C-style string
            if (readBytes != WINAGI_VERSION_LENGTH) { // Check that we got the whole version string
                  debug(3, "WagFileParser::checkWagVersion: Error reading WAG file version from stream");
                  return false;
            debug(3, "WagFileParser::checkWagVersion: Read WinAGI version string (\"%s\")", str);

            // Check that the WinAGI version string is one of the two version strings
            // WinAGI 1.1.21 recognizes as acceptable in the end of a *.wag file.
            // Note that they are all of length 16 and are padded with spaces to be that long.
            return scumm_stricmp(str, "WINAGI v1.0     ") == 0 ||
                  scumm_stricmp(str, "1.0 BETA        ") == 0;
      } else { // Stream is too small to contain the WinAGI version string
            debug(3, "WagFileParser::checkWagVersion: Stream is too small to contain a valid WAG file");
            return false;

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  Doxygen 1.6.0   Back to index