CLOUD: Make DefaultSaveFileManager ignore syncing files

MetaEngines don't get "locked" files in the list, so won't try to open
these.

Save/Load dialog updates save list every time SavesSyncRequest tells it
to.
This commit is contained in:
Alexander Tkachev 2016-06-05 22:26:51 +06:00
parent 0ce7be17d3
commit 9eb4aad7fd
6 changed files with 57 additions and 13 deletions

View file

@ -214,11 +214,11 @@ void SavesSyncRequest::downloadNextFile() {
return;
}
sendCommand(kSavesSyncProgressCmd, (int)(getDownloadingProgress() * 100));
_currentDownloadingFile = _filesToDownload.back();
_filesToDownload.pop_back();
sendCommand(kSavesSyncProgressCmd, (int)(getDownloadingProgress() * 100));
///////
debug("downloading %s (%d %%)", _currentDownloadingFile.name().c_str(), (int)(getProgress() * 100));
///////

View file

@ -59,19 +59,33 @@ void DefaultSaveFileManager::checkPath(const Common::FSNode &dir) {
}
}
void DefaultSaveFileManager::updateSavefilesList(Common::StringArray &lockedFiles) {
//make it refresh the cache next time it lists the saves
_cachedDirectory = "";
//remember the locked files list because some of these files don't exist yet
_lockedFiles = lockedFiles;
}
Common::StringArray DefaultSaveFileManager::listSavefiles(const Common::String &pattern) {
// Assure the savefile name cache is up-to-date.
assureCached(getSavePath());
if (getError().getCode() != Common::kNoError)
return Common::StringArray();
Common::StringArray results;
for (SaveFileCache::const_iterator file = _saveFileCache.begin(), end = _saveFileCache.end(); file != end; ++file) {
if (file->_key.matchString(pattern, true)) {
results.push_back(file->_key);
Common::HashMap<Common::String, bool> locked;
for (Common::StringArray::const_iterator i = _lockedFiles.begin(), end = _lockedFiles.end(); i != end; ++i) {
if (i->matchString(pattern, true)) {
locked[*i] = true;
}
}
Common::StringArray results;
for (SaveFileCache::const_iterator file = _saveFileCache.begin(), end = _saveFileCache.end(); file != end; ++file) {
if (!locked.contains(file->_key) && file->_key.matchString(pattern, true)) {
results.push_back(file->_key);
}
}
return results;
}

View file

@ -37,6 +37,7 @@ public:
DefaultSaveFileManager();
DefaultSaveFileManager(const Common::String &defaultSavepath);
virtual void updateSavefilesList(Common::StringArray &lockedFiles);
virtual Common::StringArray listSavefiles(const Common::String &pattern);
virtual Common::InSaveFile *openRawFile(const Common::String &filename);
virtual Common::InSaveFile *openForLoading(const Common::String &filename);
@ -75,6 +76,12 @@ protected:
*/
SaveFileCache _saveFileCache;
/**
* List of "locked" files. These cannot be used for saving/loading
* because CloudManager is downloading those.
*/
Common::StringArray _lockedFiles;
private:
/**
* The currently cached directory.

View file

@ -183,6 +183,13 @@ public:
* @see Common::matchString()
*/
virtual StringArray listSavefiles(const String &pattern) = 0;
/**
* Refreshes the save files list (because some new files could've been added)
* and remembers the "locked" files list. These files could not be used
* for saving or loading because they are being synced by CloudManager.
*/
virtual void updateSavefilesList(StringArray &lockedFiles) = 0;
};
} // End of namespace Common

View file

@ -35,6 +35,7 @@
#include "gui/widgets/edittext.h"
#include "graphics/scaler.h"
#include <common/savefile.h>
namespace GUI {
@ -202,11 +203,8 @@ void SaveLoadChooserDialog::handleCommand(CommandSender *sender, uint32 cmd, uin
//this dialog only gets these commands if the progress dialog was shown and user clicked "run in background"
switch (cmd) {
case kSavesSyncProgressCmd:
//TODO: unlock that save which was downloaded
break;
case kSavesSyncEndedCmd:
//TODO: ?
updateSaveList();
break;
}
}
@ -237,6 +235,7 @@ void SaveLoadChooserDialog::handleTickle() {
}
CloudMan.setSyncTarget(this);
_dialogWasShown = true;
updateSaveList();
}
}
Dialog::handleTickle();
@ -259,6 +258,11 @@ void SaveLoadChooserDialog::reflowLayout() {
Dialog::reflowLayout();
}
void SaveLoadChooserDialog::updateSaveList() {
Common::Array<Common::String> files = CloudMan.getSyncingFiles(); //returns empty array if not syncing
g_system->getSavefileManager()->updateSavefilesList(files);
}
#ifndef DISABLE_SAVELOADCHOOSER_GRID
void SaveLoadChooserDialog::addChooserButtons() {
if (_listButton) {
@ -570,6 +574,7 @@ void SaveLoadChooserSimple::close() {
}
void SaveLoadChooserSimple::updateSaveList() {
SaveLoadChooserDialog::updateSaveList();
_saveList = _metaEngine->listSaves(_target.c_str());
int curSlot = 0;
@ -631,6 +636,7 @@ void SaveLoadChooserSimple::updateSaveList() {
}
_list->setList(saveNames, &colors);
draw();
}
// SaveLoadChooserGrid implementation
@ -726,6 +732,13 @@ void SaveLoadChooserGrid::handleMouseWheel(int x, int y, int direction) {
}
}
void SaveLoadChooserGrid::updateSaveList() {
SaveLoadChooserDialog::updateSaveList();
_saveList = _metaEngine->listSaves(_target.c_str());
updateSaves();
draw();
}
void SaveLoadChooserGrid::open() {
SaveLoadChooserDialog::open();

View file

@ -84,6 +84,7 @@ public:
protected:
virtual int runIntern() = 0;
virtual void updateSaveList();
const bool _saveMode;
const MetaEngine *_metaEngine;
@ -122,6 +123,8 @@ public:
virtual void open();
virtual void close();
protected:
virtual void updateSaveList();
private:
virtual int runIntern();
@ -137,7 +140,6 @@ private:
SaveStateList _saveList;
String _resultString;
void updateSaveList();
void updateSelection(bool redraw);
};
@ -180,6 +182,7 @@ public:
protected:
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
virtual void handleMouseWheel(int x, int y, int direction);
virtual void updateSaveList();
private:
virtual int runIntern();