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 "engines/advancedDetector.h"
24 
25 #include "common/savefile.h"
26 #include "common/system.h"
27 
28 #include "queen/queen.h"
29 #include "queen/resource.h"
30 #include "queen/detection.h"
31 
32 class QueenMetaEngine : public AdvancedMetaEngine {
33 public:
getName() const34 	const char *getName() const override {
35 		return "queen";
36 	}
37 
38 	bool hasFeature(MetaEngineFeature f) const override;
39 	Common::Error createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const override;
40 	SaveStateList listSaves(const char *target) const override;
getMaximumSaveSlot() const41 	int getMaximumSaveSlot() const override { return 99; }
42 	void removeSaveState(const char *target, int slot) const override;
getAutosaveSlot() const43 	int getAutosaveSlot() const override { return 99; }
44 };
45 
hasFeature(MetaEngineFeature f) const46 bool QueenMetaEngine::hasFeature(MetaEngineFeature f) const {
47 	return
48 		(f == kSupportsListSaves) ||
49 		(f == kSupportsLoadingDuringStartup) ||
50 		(f == kSupportsDeleteSave);
51 }
52 
listSaves(const char * target) const53 SaveStateList QueenMetaEngine::listSaves(const char *target) const {
54 	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
55 	Common::StringArray filenames;
56 	char saveDesc[32];
57 	Common::String pattern("queen.s##");
58 
59 	filenames = saveFileMan->listSavefiles(pattern);
60 
61 	SaveStateList saveList;
62 	for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
63 		// Obtain the last 2 digits of the filename, since they correspond to the save slot
64 		int slotNum = atoi(file->c_str() + file->size() - 2);
65 
66 		if (slotNum >= 0 && slotNum <= 99) {
67 			Common::InSaveFile *in = saveFileMan->openForLoading(*file);
68 			if (in) {
69 				for (int i = 0; i < 4; i++)
70 					in->readUint32BE();
71 				in->read(saveDesc, 32);
72 				saveList.push_back(SaveStateDescriptor(this, slotNum, saveDesc));
73 				delete in;
74 			}
75 		}
76 	}
77 
78 	// Sort saves based on slot number.
79 	Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
80 	return saveList;
81 }
82 
removeSaveState(const char * target,int slot) const83 void QueenMetaEngine::removeSaveState(const char *target, int slot) const {
84 	Common::String filename = Common::String::format("queen.s%02d", slot);
85 
86 	g_system->getSavefileManager()->removeSavefile(filename);
87 }
88 
createInstance(OSystem * syst,Engine ** engine,const ADGameDescription * desc) const89 Common::Error QueenMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
90 	*engine = new Queen::QueenEngine(syst); //FIXME , (const Queen::QueenGameDescription *)desc);
91 	return Common::kNoError;
92 }
93 
94 #if PLUGIN_ENABLED_DYNAMIC(QUEEN)
95 	REGISTER_PLUGIN_DYNAMIC(QUEEN, PLUGIN_TYPE_ENGINE, QueenMetaEngine);
96 #else
97 	REGISTER_PLUGIN_STATIC(QUEEN, PLUGIN_TYPE_ENGINE, QueenMetaEngine);
98 #endif
99 
100