1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "groovie/groovie.h"
24 #include "groovie/saveload.h"
25 
26 #include "common/system.h"
27 #include "common/translation.h"
28 
29 #include "engines/advancedDetector.h"
30 #include "groovie/detection.h"
31 
32 namespace Groovie {
33 
34 class GroovieMetaEngine : public AdvancedMetaEngine {
35 public:
getName() const36 	const char *getName() const override {
37 		return "groovie";
38 	}
39 
40 	Common::Error createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const override;
41 	bool hasFeature(MetaEngineFeature f) const override;
42 
43 	SaveStateList listSaves(const char *target) const override;
44 	int getMaximumSaveSlot() const override;
45 	void removeSaveState(const char *target, int slot) const override;
46 	SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const override;
47 };
48 
createInstance(OSystem * syst,Engine ** engine,const ADGameDescription * gd) const49 Common::Error GroovieMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const {
50 #ifndef ENABLE_GROOVIE2
51 	if (((const GroovieGameDescription *)gd)->version == kGroovieV2)
52 		return Common::Error(Common::kUnsupportedGameidError, _s("GroovieV2 support is not compiled in"));
53 #endif
54 
55 	*engine = new GroovieEngine(syst, (const GroovieGameDescription *)gd);
56 	return Common::kNoError;
57 }
58 
hasFeature(MetaEngineFeature f) const59 bool GroovieMetaEngine::hasFeature(MetaEngineFeature f) const {
60 	return
61 		(f == kSupportsListSaves) ||
62 		(f == kSupportsLoadingDuringStartup) ||
63 		(f == kSupportsDeleteSave) ||
64 		(f == kSimpleSavesNames) ||
65 		(f == kSavesSupportMetaInfo);
66 }
67 
listSaves(const char * target) const68 SaveStateList GroovieMetaEngine::listSaves(const char *target) const {
69 	return SaveLoad::listValidSaves(target);
70 }
71 
getMaximumSaveSlot() const72 int GroovieMetaEngine::getMaximumSaveSlot() const {
73 	return SaveLoad::getMaximumSlot();
74 }
75 
removeSaveState(const char * target,int slot) const76 void GroovieMetaEngine::removeSaveState(const char *target, int slot) const {
77 	if (!SaveLoad::isSlotValid(slot)) {
78 		// Invalid slot, do nothing
79 		return;
80 	}
81 
82 	Common::String filename = SaveLoad::getSlotSaveName(target, slot);
83 	g_system->getSavefileManager()->removeSavefile(filename);
84 }
85 
querySaveMetaInfos(const char * target,int slot) const86 SaveStateDescriptor GroovieMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
87 	SaveStateDescriptor desc;
88 
89 	Common::InSaveFile *savefile = SaveLoad::openForLoading(target, slot, &desc);
90 	delete savefile;
91 
92 	return desc;
93 }
94 
95 } // End of namespace Groovie
96 
97 #if PLUGIN_ENABLED_DYNAMIC(GROOVIE)
98 	REGISTER_PLUGIN_DYNAMIC(GROOVIE, PLUGIN_TYPE_ENGINE, Groovie::GroovieMetaEngine);
99 #else
100 	REGISTER_PLUGIN_STATIC(GROOVIE, PLUGIN_TYPE_ENGINE, Groovie::GroovieMetaEngine);
101 #endif
102