bool BuriedEngine::loadState(Common::SeekableReadStream *saveFile, Location &location, GlobalFlags &flags, Common::Array<int> &inventoryItems) { byte header[9]; saveFile->read(header, kSavedGameHeaderSize); // Only compare the first 6 bytes // Win95 version of the game output garbage as the last two bytes if (saveFile->eos() || memcmp(header, s_savedGameHeader, kSavedGameHeaderSizeAlt) != 0) return false; Common::Serializer s(saveFile, 0); if (!syncLocation(s, location)) return false; if (saveFile->eos()) return false; if (!syncGlobalFlags(s, flags)) return false; if (saveFile->eos()) return false; uint16 itemCount = saveFile->readUint16LE(); if (saveFile->eos()) return false; inventoryItems.clear(); for (uint16 i = 0; i < itemCount; i++) inventoryItems.push_back(saveFile->readUint16LE()); return !saveFile->eos(); }
QSharedPointer<SyncObject> DatabaseSync<SO>::syncEntries() { qDebug() << "Running sync for type: " + getType(); // make sure root groups are the same.It has to be if we are syncing the same // database Q_ASSERT(db1->rootGroup()->uuid() == db2->rootGroup()->uuid()); entries1 = getEntriesMap(db1); entries2 = getEntriesMap(db2); QList<SO *> missingEntries; Q_FOREACH(SO * cloudEntry, entries2) { if (!processEntry(db2, cloudEntry)) continue; // remote entry also exists in local database if (entries1.contains(cloudEntry->uuid())) { SO *localEntry = entries1[cloudEntry->uuid()]; syncEntry(localEntry, cloudEntry); syncLocation(localEntry, cloudEntry); } // entry exists only in remote database else { missingEntries.append(cloudEntry); } } if (missingEntries.length() > 0) addMissingEntries(missingEntries); // count whether any unique entry exist in local database // to further decide whether we need to update remote db Q_FOREACH(SO * localEntry, entries1) { if (!processEntry(db1, localEntry)) continue; if (!entries2.contains(localEntry->uuid())) { bool isRemoved = Tools::hasChild(db1->metadata()->recycleBin(), localEntry); if (isRemoved) { // entry should be created and removed to recycle bin in remote database getSyncObject()->increase(getObjectType(), SRemoved(), SRemote()); } else { // entry is missing in remote database getSyncObject()->increase(getObjectType(), SMissing(), SRemote()); } } } return DatabaseSync::syncObject; }
bool BuriedEngine::saveState(Common::WriteStream *saveFile, Location &location, GlobalFlags &flags, Common::Array<int> &inventoryItems) { saveFile->write(s_savedGameHeader, kSavedGameHeaderSize); Common::Serializer s(0, saveFile); if (!syncLocation(s, location)) return false; if (!syncGlobalFlags(s, flags)) return false; saveFile->writeUint16LE(inventoryItems.size()); for (uint16 i = 0; i < inventoryItems.size(); i++) saveFile->writeUint16LE(inventoryItems[i]); // Fill in remaining items with all zeroes uint16 fillItems = 50 - inventoryItems.size(); while (fillItems--) saveFile->writeUint16LE(0); return true; }