aboutsummaryrefslogtreecommitdiff
path: root/gui/saveload.cpp
blob: 2ac68dd8f9175bd0758fde02d851be224d473113 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "common/config-manager.h"
#include "common/system.h"

#include "gui/saveload.h"
#include "gui/saveload-dialog.h"

#include "engines/metaengine.h"

namespace GUI {

SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode)
	: _impl(0), _title(title), _buttonLabel(buttonLabel), _saveMode(saveMode) {
}

SaveLoadChooser::~SaveLoadChooser() {
	delete _impl;
	_impl = 0;
}

void SaveLoadChooser::selectChooser(const MetaEngine &engine) {
#ifndef DISABLE_SAVELOADCHOOSER_GRID
	const SaveLoadChooserType requestedType = getRequestedSaveLoadDialog(engine);
	if (!_impl || _impl->getType() != requestedType) {
		delete _impl;
		_impl = 0;

		switch (requestedType) {
		case kSaveLoadDialogGrid:
			_impl = new SaveLoadChooserGrid(_title, _saveMode);
			break;

		case kSaveLoadDialogList:
#endif // !DISABLE_SAVELOADCHOOSER_GRID
			_impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode);
#ifndef DISABLE_SAVELOADCHOOSER_GRID
			break;
		}
	}
#endif // !DISABLE_SAVELOADCHOOSER_GRID
}

Common::String SaveLoadChooser::createDefaultSaveDescription(const int slot) const {
#if defined(USE_SAVEGAME_TIMESTAMP)
	TimeDate curTime;
	g_system->getTimeAndDate(curTime);
	curTime.tm_year += 1900; // fixup year
	curTime.tm_mon++; // fixup month
	return Common::String::format("%04d.%02d.%02d / %02d:%02d:%02d", curTime.tm_year, curTime.tm_mon, curTime.tm_mday, curTime.tm_hour, curTime.tm_min, curTime.tm_sec);
#else
	return Common::String::format("Save %d", slot + 1);
#endif
}

int SaveLoadChooser::runModalWithCurrentTarget() {
	const Common::String gameId = ConfMan.get("gameid");

	const EnginePlugin *plugin = 0;
	EngineMan.findGame(gameId, &plugin);

	return runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
}

int SaveLoadChooser::runModalWithPluginAndTarget(const EnginePlugin *plugin, const String &target) {
	selectChooser(**plugin);
	if (!_impl)
		return -1;

#if defined(USE_CLOUD) && defined(USE_LIBCURL)
	_impl->runSaveSync(ConfMan.hasKey("savepath", target));
#endif

	// Set up the game domain as newly active domain, so
	// target specific savepath will be checked
	String oldDomain = ConfMan.getActiveDomainName();
	ConfMan.setActiveDomain(target);

	int ret;
	do {
		ret = _impl->run(target, &(**plugin));
#ifndef DISABLE_SAVELOADCHOOSER_GRID
		if (ret == kSwitchSaveLoadDialog) {
			selectChooser(**plugin);
		}
#endif // !DISABLE_SAVELOADCHOOSER_GRID
	} while (ret < -1);

	// Revert to the old active domain
	ConfMan.setActiveDomain(oldDomain);

	return ret;
}

const Common::String &SaveLoadChooser::getResultString() const {
	assert(_impl);
	return _impl->getResultString();
}

} // End of namespace GUI