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

WFUTError WFUT::WFUTClient::calculateUpdates ( const ChannelFileList &  server,
const ChannelFileList &  system,
const ChannelFileList &  local,
ChannelFileList &  updates,
const std::string &  prefix 
)

This function takes three sets of channel file lists and calculates which files need updating. The server list is the server side file list. The system list is intended for data stored in a read only location. This may be empty i no such location exists. The local list is the list of files stored in a writable location. This may be empty if no files have yet been downloaded. The updates list is the list of FileObjects in the server list that require downloading. The prefix argument is the path prefix to the local files so that the CRC32 value maybe checked. This process also doubles up to check to see if local files have been deleted and need re-downloading.

Definition at line 176 of file WFUT.cpp.

                                                                                                                                                                                    {
  const FileMap &server_map = server.getFiles();
  const FileMap &system_map = system.getFiles();
  const FileMap &local_map = local.getFiles();

  FileMap::const_iterator I = server_map.begin();
  FileMap::const_iterator Iend = server_map.end();

  for (; I !=  Iend; ++I) {
    const FileObject &server_obj = I->second;
    // find the matching local one
    FileMap::const_iterator sys_iter = system_map.find(I->first);
    FileMap::const_iterator loc_iter = local_map.find(I->first);

    if (loc_iter == local_map.end()) {
      if (sys_iter == system_map.end()) {
printf("Adding %s as no local version\n", server_obj.filename.c_str());
        updates.addFile(server_obj);
      } else if (server_obj.version > sys_iter->second.version) {
printf("Updating %s as server is newer than sys\n", server_obj.filename.c_str());
        updates.addFile(server_obj);
      } else {
        // Assume the sys location is valid, so no need to update
      }
    } else if (server_obj.version > loc_iter->second.version) {
printf("Updating %s as server is newer than local\n", server_obj.filename.c_str());
      updates.addFile(server_obj);
    } else {
      // According to xml files, the local version is the same as the server
      // Lets check that it exists and has a matching CRC value.
      uLong crc32;
      if (calcCRC32(prefix + loc_iter->second.filename.c_str(), crc32) == -1) {
        // Can't read file, so lets add it
printf("Adding %s as local is missing\n", server_obj.filename.c_str());
        updates.addFile(server_obj);
      } else {
        // Do a CRC check and warn user that the file is modified.
        if (crc32 != server_obj.crc32) {
          // Modified!
          printf("File %s is modified. Remove to update.\n", loc_iter->second.filename.c_str());
        }
      }
    }
  }
  return WFUT_NO_ERROR;
}


Generated by  Doxygen 1.6.0   Back to index