diff options
author | Max Horn | 2008-09-30 16:53:04 +0000 |
---|---|---|
committer | Max Horn | 2008-09-30 16:53:04 +0000 |
commit | e798561013039ec6b61d6ef3c358a8f06bc41dc4 (patch) | |
tree | 7e821f35de777648d37eac0c17b4f26364eed27c /engines/agi | |
parent | e5dbb3f901789f820a8fa67c52514434ed27920c (diff) | |
download | scummvm-rg350-e798561013039ec6b61d6ef3c358a8f06bc41dc4.tar.gz scummvm-rg350-e798561013039ec6b61d6ef3c358a8f06bc41dc4.tar.bz2 scummvm-rg350-e798561013039ec6b61d6ef3c358a8f06bc41dc4.zip |
AGI: Simplify WagFileParser by not reading data into a memory stream first (this was there to improve performance on systems with slow seeking; those systems should use another approach, see scummvm-devel)
svn-id: r34711
Diffstat (limited to 'engines/agi')
-rw-r--r-- | engines/agi/wagparser.cpp | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/engines/agi/wagparser.cpp b/engines/agi/wagparser.cpp index 5a49951183..b0cc400e4e 100644 --- a/engines/agi/wagparser.cpp +++ b/engines/agi/wagparser.cpp @@ -174,39 +174,35 @@ bool WagFileParser::checkWagVersion(Common::SeekableReadStream &stream) { } bool WagFileParser::parse(const Common::FilesystemNode &node) { - Common::File file; WagProperty property; // Temporary property used for reading - Common::MemoryReadStream *stream = NULL; // The file is to be read fully into memory and handled using this + Common::SeekableReadStream *stream = NULL; // The file stream _parsedOk = false; // We haven't parsed the file yet - if (file.open(node)) { // Open the file - stream = file.readStream(file.size()); // Read the file into memory - if (stream != NULL && stream->size() == file.size()) { // Check that the whole file was read into memory - if (checkWagVersion(*stream)) { // Check that WinAGI version string is valid - // It seems we've got a valid *.wag file so let's parse its properties from the start. - stream->seek(0); // Rewind the stream - if (!_propList.empty()) _propList.clear(); // Clear out old properties (If any) - - do { // Parse the properties - if (property.read(*stream)) { // Read the property and check it was read ok - _propList.push_back(property); // Add read property to properties list - debug(4, "WagFileParser::parse: Read property with code %d, type %d, number %d, size %d, data \"%s\"", - property.getCode(), property.getType(), property.getNumber(), property.getSize(), property.getData()); - } else // Reading failed, let's bail out - break; - } while (!endOfProperties(*stream)); // Loop until the end of properties - - // File was parsed successfully only if we got to the end of properties - // and all the properties were read successfully (Also the last). - _parsedOk = endOfProperties(*stream) && property.readOk(); - - if (!_parsedOk) // Error parsing stream - warning("Error parsing WAG file (%s). WAG file ignored", node.getPath().c_str()); - } else // Invalid WinAGI version string or it couldn't be read - warning("Invalid WAG file (%s) version or error reading it. WAG file ignored", node.getPath().c_str()); - } else // Couldn't fully read file into memory - warning("Error reading WAG file (%s) into memory. WAG file ignored", node.getPath().c_str()); + stream = node.openForReading(); // Open the file + if (stream) { // Check that opening the file was succesful + if (checkWagVersion(*stream)) { // Check that WinAGI version string is valid + // It seems we've got a valid *.wag file so let's parse its properties from the start. + stream->seek(0); // Rewind the stream + if (!_propList.empty()) _propList.clear(); // Clear out old properties (If any) + + do { // Parse the properties + if (property.read(*stream)) { // Read the property and check it was read ok + _propList.push_back(property); // Add read property to properties list + debug(4, "WagFileParser::parse: Read property with code %d, type %d, number %d, size %d, data \"%s\"", + property.getCode(), property.getType(), property.getNumber(), property.getSize(), property.getData()); + } else // Reading failed, let's bail out + break; + } while (!endOfProperties(*stream)); // Loop until the end of properties + + // File was parsed successfully only if we got to the end of properties + // and all the properties were read successfully (Also the last). + _parsedOk = endOfProperties(*stream) && property.readOk(); + + if (!_parsedOk) // Error parsing stream + warning("Error parsing WAG file (%s). WAG file ignored", node.getPath().c_str()); + } else // Invalid WinAGI version string or it couldn't be read + warning("Invalid WAG file (%s) version or error reading it. WAG file ignored", node.getPath().c_str()); } else // Couldn't open file warning("Couldn't open WAG file (%s). WAG file ignored", node.getPath().c_str()); |