2010-03-18 15:09:48 +00:00
|
|
|
/* 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.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2010-03-18 15:09:48 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2010-03-18 15:09:48 +00:00
|
|
|
* 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 "engines/savestate.h"
|
2021-08-10 20:34:51 +00:00
|
|
|
#include "engines/engine.h"
|
2021-10-19 06:28:14 +00:00
|
|
|
#include "engines/metaengine.h"
|
2010-03-18 15:09:48 +00:00
|
|
|
#include "graphics/surface.h"
|
2021-08-10 20:34:51 +00:00
|
|
|
#include "common/config-manager.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/textconsole.h"
|
2020-02-11 02:55:31 +00:00
|
|
|
#include "common/translation.h"
|
2010-03-18 15:09:48 +00:00
|
|
|
|
2011-07-02 18:25:32 +00:00
|
|
|
SaveStateDescriptor::SaveStateDescriptor()
|
|
|
|
// FIXME: default to 0 (first slot) or to -1 (invalid slot) ?
|
|
|
|
: _slot(-1), _description(), _isDeletable(true), _isWriteProtected(false),
|
2020-02-11 02:55:31 +00:00
|
|
|
_isLocked(false), _saveDate(), _saveTime(), _playTime(), _playTimeMSecs(0),
|
|
|
|
_thumbnail(), _saveType(kSaveTypeUndetermined) {
|
2010-03-18 15:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-10-19 06:28:14 +00:00
|
|
|
SaveStateDescriptor::SaveStateDescriptor(const MetaEngine *metaEngine, int slot, const Common::U32String &d)
|
2021-08-10 20:34:51 +00:00
|
|
|
: _slot(slot), _description(d), _isLocked(false), _playTimeMSecs(0) {
|
2021-10-19 06:28:14 +00:00
|
|
|
initSaveType(metaEngine);
|
2010-03-18 15:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-10-19 06:28:14 +00:00
|
|
|
SaveStateDescriptor::SaveStateDescriptor(const MetaEngine *metaEngine, int slot, const Common::String &d)
|
2021-08-10 20:34:51 +00:00
|
|
|
: _slot(slot), _description(Common::U32String(d)), _isLocked(false), _playTimeMSecs(0) {
|
2021-10-19 06:28:14 +00:00
|
|
|
initSaveType(metaEngine);
|
2021-08-10 20:34:51 +00:00
|
|
|
}
|
|
|
|
|
2021-10-19 06:28:14 +00:00
|
|
|
void SaveStateDescriptor::initSaveType(const MetaEngine *metaEngine) {
|
2021-08-10 20:34:51 +00:00
|
|
|
// Do not allow auto-save slot to be deleted or overwritten.
|
2021-10-19 06:28:14 +00:00
|
|
|
if (!metaEngine && g_engine)
|
|
|
|
metaEngine = g_engine->getMetaEngine();
|
2021-08-10 20:34:51 +00:00
|
|
|
const bool autosave =
|
2021-10-19 06:28:14 +00:00
|
|
|
metaEngine && ConfMan.getInt("autosave_period") && _slot == metaEngine->getAutosaveSlot();
|
2021-08-10 20:34:51 +00:00
|
|
|
_isWriteProtected = autosave;
|
|
|
|
_saveType = autosave ? kSaveTypeAutosave : kSaveTypeRegular;
|
|
|
|
_isDeletable = !autosave;
|
2020-06-16 19:57:23 +00:00
|
|
|
}
|
|
|
|
|
2011-07-02 18:25:32 +00:00
|
|
|
void SaveStateDescriptor::setThumbnail(Graphics::Surface *t) {
|
|
|
|
if (_thumbnail.get() == t)
|
|
|
|
return;
|
2010-03-18 15:09:48 +00:00
|
|
|
|
2017-11-18 05:28:15 +00:00
|
|
|
_thumbnail = Common::SharedPtr<Graphics::Surface>(t, Graphics::SurfaceDeleter());
|
2010-03-18 15:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SaveStateDescriptor::setSaveDate(int year, int month, int day) {
|
2017-06-01 03:32:32 +00:00
|
|
|
_saveDate = Common::String::format("%.4d-%.2d-%.2d", year, month, day);
|
2010-03-18 15:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SaveStateDescriptor::setSaveTime(int hour, int min) {
|
2011-07-02 18:25:32 +00:00
|
|
|
_saveTime = Common::String::format("%.2d:%.2d", hour, min);
|
2010-03-18 15:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SaveStateDescriptor::setPlayTime(int hours, int minutes) {
|
2018-07-13 02:13:22 +00:00
|
|
|
_playTimeMSecs = ((hours * 60 + minutes) * 60) * 1000;
|
2011-07-02 18:25:32 +00:00
|
|
|
_playTime = Common::String::format("%.2d:%.2d", hours, minutes);
|
2010-03-18 15:09:48 +00:00
|
|
|
}
|
2010-10-29 16:41:30 +00:00
|
|
|
|
|
|
|
void SaveStateDescriptor::setPlayTime(uint32 msecs) {
|
2018-07-13 02:13:22 +00:00
|
|
|
_playTimeMSecs = msecs;
|
2010-10-29 16:41:30 +00:00
|
|
|
uint minutes = msecs / 60000;
|
|
|
|
setPlayTime(minutes / 60, minutes % 60);
|
|
|
|
}
|
2020-02-11 02:55:31 +00:00
|
|
|
|
|
|
|
void SaveStateDescriptor::setAutosave(bool autosave) {
|
|
|
|
_saveType = autosave ? kSaveTypeAutosave : kSaveTypeRegular;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SaveStateDescriptor::isAutosave() const {
|
|
|
|
if (_saveType != kSaveTypeUndetermined) {
|
|
|
|
return _saveType == kSaveTypeAutosave;
|
|
|
|
} else {
|
2021-08-16 20:38:35 +00:00
|
|
|
return hasAutosaveName();
|
2020-02-11 02:55:31 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-16 20:38:35 +00:00
|
|
|
|
|
|
|
bool SaveStateDescriptor::hasAutosaveName() const
|
|
|
|
{
|
|
|
|
return _description.contains(_("Autosave"));
|
|
|
|
}
|
2021-11-23 05:37:45 +00:00
|
|
|
|
|
|
|
bool SaveStateDescriptor::isValid() const
|
|
|
|
{
|
|
|
|
return _slot >= 0 && !_description.empty();
|
|
|
|
}
|