void DefaultSaveFileManager::saveTimestamps(Common::HashMap<Common::String, uint32> ×tamps) { Common::DumpFile f; Common::String filename = concatWithSavesPath(TIMESTAMPS_FILENAME); if (!f.open(filename, true)) { warning("DefaultSaveFileManager: failed to open '%s' file to save timestamps", filename.c_str()); return; } for (Common::HashMap<Common::String, uint32>::iterator i = timestamps.begin(); i != timestamps.end(); ++i) { Common::String data = i->_key + Common::String::format(" %u\n", i->_value); if (f.write(data.c_str(), data.size()) != data.size()) { warning("DefaultSaveFileManager: failed to write timestamps data into '%s'", filename.c_str()); return; } } f.flush(); f.finalize(); f.close(); }
void SavesSyncRequest::directoryListedCallback(Storage::ListDirectoryResponse response) { _workingRequest = nullptr; if (_ignoreCallback) return; if (response.request) _date = response.request->date(); Common::HashMap<Common::String, bool> localFileNotAvailableInCloud; for (Common::HashMap<Common::String, uint32>::iterator i = _localFilesTimestamps.begin(); i != _localFilesTimestamps.end(); ++i) { localFileNotAvailableInCloud[i->_key] = true; } //determine which files to download and which files to upload Common::Array<StorageFile> &remoteFiles = response.value; uint64 totalSize = 0; for (uint32 i = 0; i < remoteFiles.size(); ++i) { StorageFile &file = remoteFiles[i]; if (file.isDirectory()) continue; totalSize += file.size(); if (file.name() == DefaultSaveFileManager::TIMESTAMPS_FILENAME) continue; Common::String name = file.name(); if (!_localFilesTimestamps.contains(name)) { _filesToDownload.push_back(file); } else { localFileNotAvailableInCloud[name] = false; if (_localFilesTimestamps[name] == file.timestamp()) continue; //we actually can have some files not only with timestamp < remote //but also with timestamp > remote (when we have been using ANOTHER CLOUD and then switched back) if (_localFilesTimestamps[name] > file.timestamp() || _localFilesTimestamps[name] == DefaultSaveFileManager::INVALID_TIMESTAMP) _filesToUpload.push_back(file.name()); else _filesToDownload.push_back(file); } } CloudMan.setStorageUsedSpace(CloudMan.getStorageIndex(), totalSize); //upload files which are unavailable in cloud for (Common::HashMap<Common::String, bool>::iterator i = localFileNotAvailableInCloud.begin(); i != localFileNotAvailableInCloud.end(); ++i) { if (i->_key == DefaultSaveFileManager::TIMESTAMPS_FILENAME) continue; if (i->_value) _filesToUpload.push_back(i->_key); } debug(9, "\nSavesSyncRequest: download files:"); for (uint32 i = 0; i < _filesToDownload.size(); ++i) { debug(9, "%s", _filesToDownload[i].name().c_str()); } debug(9, "\nSavesSyncRequest: upload files:"); for (uint32 i = 0; i < _filesToUpload.size(); ++i) { debug(9, "%s", _filesToUpload[i].c_str()); } _totalFilesToHandle = _filesToDownload.size() + _filesToUpload.size(); //start downloading files downloadNextFile(); }
void dumpEveryResultAction(const Common::String &destFile) { Common::HashMap<Common::String, byte> count; Common::HashMap<Common::String, bool> fileAlreadyUsed; Common::DumpFile output; output.open(destFile); // Find scr files Common::ArchiveMemberList list; SearchMan.listMatchingMembers(list, "*.scr"); for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) { Common::SeekableReadStream *stream = (*iter)->createReadStream(); Common::String line = stream->readLine(); trimCommentsAndWhiteSpace(&line); while (!stream->eos()) { if (line.matchString("*:add*", true)) { tryToDumpLine("add", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:animplay*", true)) { tryToDumpLine("animplay", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:animpreload*", true)) { tryToDumpLine("animpreload", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:animunload*", true)) { tryToDumpLine("animunload", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:attenuate*", true)) { tryToDumpLine("attenuate", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:assign*", true)) { tryToDumpLine("assign", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:change_location*", true)) { tryToDumpLine("change_location", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:crossfade*", true) && !fileAlreadyUsed["add"]) { tryToDumpLine("crossfade", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:debug*", true)) { tryToDumpLine("debug", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:delay_render*", true)) { tryToDumpLine("delay_render", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:disable_control*", true)) { tryToDumpLine("disable_control", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:disable_venus*", true)) { tryToDumpLine("disable_venus", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:display_message*", true)) { tryToDumpLine("display_message", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:dissolve*", true)) { tryToDumpLine("dissolve", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:distort*", true)) { tryToDumpLine("distort", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:enable_control*", true)) { tryToDumpLine("enable_control", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:flush_mouse_events*", true)) { tryToDumpLine("flush_mouse_events", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:inventory*", true)) { tryToDumpLine("inventory", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:kill*", true)) { tryToDumpLine("kill", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:menu_bar_enable*", true)) { tryToDumpLine("menu_bar_enable", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:music*", true)) { tryToDumpLine("music", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:pan_track*", true)) { tryToDumpLine("pan_track", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:playpreload*", true)) { tryToDumpLine("playpreload", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:preferences*", true)) { tryToDumpLine("preferences", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:quit*", true)) { tryToDumpLine("quit", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:random*", true)) { tryToDumpLine("random", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:region*", true)) { tryToDumpLine("region", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:restore_game*", true)) { tryToDumpLine("restore_game", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:rotate_to*", true)) { tryToDumpLine("rotate_to", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:save_game*", true)) { tryToDumpLine("save_game", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:set_partial_screen*", true)) { tryToDumpLine("set_partial_screen", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:set_screen*", true)) { tryToDumpLine("set_screen", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:set_venus*", true)) { tryToDumpLine("set_venus", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:stop*", true)) { tryToDumpLine("stop", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:streamvideo*", true)) { tryToDumpLine("streamvideo", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:syncsound*", true)) { tryToDumpLine("syncsound", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:timer*", true)) { tryToDumpLine("timer", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:ttytext*", true)) { tryToDumpLine("ttytext", line, &count, &fileAlreadyUsed, output); } else if (line.matchString("*:universe_music*", true)) { tryToDumpLine("universe_music", line, &count, &fileAlreadyUsed, output); } line = stream->readLine(); trimCommentsAndWhiteSpace(&line); } for (Common::HashMap<Common::String, bool>::iterator fileUsedIter = fileAlreadyUsed.begin(); fileUsedIter != fileAlreadyUsed.end(); ++fileUsedIter) { fileUsedIter->_value = false; } } output.close(); }