~ubuntu-branches/ubuntu/raring/scummvm/raring

« back to all changes in this revision

Viewing changes to engines/hugo/detection.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Moritz Muehlenhoff
  • Date: 2011-05-25 19:02:23 UTC
  • mto: (21.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: james.westby@ubuntu.com-20110525190223-fiqm0oaec714xk31
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * along with this program; if not, write to the Free Software
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
20
 *
21
 
 * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-1-2-1/engines/hugo/detection.cpp $
22
 
 * $Id: detection.cpp 52525 2010-09-04 16:02:16Z strangerke $
 
21
 * $URL$
 
22
 * $Id$
23
23
 *
24
24
 */
25
25
 
26
26
#include "engines/advancedDetector.h"
 
27
#include "common/system.h"
 
28
#include "common/savefile.h"
 
29
#include "common/textconsole.h"
 
30
#include "graphics/thumbnail.h"
 
31
#include "graphics/surface.h"
27
32
 
28
33
#include "hugo/hugo.h"
29
34
 
38
43
        return _gameDescription->desc.flags;
39
44
}
40
45
 
 
46
const char *HugoEngine::getGameId() const {
 
47
        return _gameDescription->desc.gameid;
 
48
}
 
49
 
 
50
 
41
51
static const PlainGameDescriptor hugoGames[] = {
42
52
        // Games
43
53
        {"hugo1", "Hugo 1: Hugo's House of Horrors"},
44
 
        {"hugo2", "Hugo 2: Hugo's Mystery Adventure"},
45
 
        {"hugo3", "Hugo 3: Hugo's Amazon Adventure"},
 
54
        {"hugo2", "Hugo 2: Whodunit?"},
 
55
        {"hugo3", "Hugo 3: Jungle of Doom"},
46
56
        {0, 0}
47
57
};
48
58
 
162
172
        }
163
173
 
164
174
        bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const;
165
 
 
166
175
        bool hasFeature(MetaEngineFeature f) const;
 
176
 
 
177
        int getMaximumSaveSlot() const;
 
178
        SaveStateList listSaves(const char *target) const;
 
179
        SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const;
 
180
        void removeSaveState(const char *target, int slot) const;
167
181
};
168
182
 
169
183
bool HugoMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const {
175
189
}
176
190
 
177
191
bool HugoMetaEngine::hasFeature(MetaEngineFeature f) const {
178
 
        return false;
179
 
}
180
 
 
 
192
        return
 
193
            (f == kSupportsListSaves) ||
 
194
            (f == kSupportsLoadingDuringStartup) ||
 
195
            (f == kSupportsDeleteSave) ||
 
196
            (f == kSavesSupportMetaInfo) ||
 
197
            (f == kSavesSupportThumbnail) ||
 
198
            (f == kSavesSupportCreationDate);
 
199
}
 
200
 
 
201
int HugoMetaEngine::getMaximumSaveSlot() const { return 99; }
 
202
 
 
203
SaveStateList HugoMetaEngine::listSaves(const char *target) const {
 
204
        Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
 
205
        Common::StringArray filenames;
 
206
        Common::String pattern = target;
 
207
        pattern += "-??.SAV";
 
208
 
 
209
        filenames = saveFileMan->listSavefiles(pattern);
 
210
        sort(filenames.begin(), filenames.end());   // Sort (hopefully ensuring we are sorted numerically..)
 
211
 
 
212
        SaveStateList saveList;
 
213
        char slot[3];
 
214
        int slotNum = 0;
 
215
        for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) {
 
216
                slot[0] = filename->c_str()[filename->size() - 6];
 
217
                slot[1] = filename->c_str()[filename->size() - 5];
 
218
                slot[2] = '\0';
 
219
                // Obtain the last 2 digits of the filename (without extension), since they correspond to the save slot
 
220
                slotNum = atoi(slot);
 
221
                if (slotNum >= 0 && slotNum <= getMaximumSaveSlot()) {
 
222
                        Common::InSaveFile *file = saveFileMan->openForLoading(*filename);
 
223
                        if (file) {
 
224
                                int saveVersion = file->readByte();
 
225
 
 
226
                                if (saveVersion != kSavegameVersion) {
 
227
                                        warning("Savegame of incompatible version");
 
228
                                        delete file;
 
229
                                        continue;
 
230
                                }
 
231
 
 
232
                                // read name
 
233
                                uint16 nameSize = file->readUint16BE();
 
234
                                if (nameSize >= 255) {
 
235
                                        delete file;
 
236
                                        continue;
 
237
                                }
 
238
                                char name[256];
 
239
                                file->read(name, nameSize);
 
240
                                name[nameSize] = 0;
 
241
 
 
242
                                saveList.push_back(SaveStateDescriptor(slotNum, name));
 
243
                                delete file;
 
244
                        }
 
245
                }
 
246
        }
 
247
 
 
248
        return saveList;
 
249
}
 
250
 
 
251
SaveStateDescriptor HugoMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
 
252
        Common::String fileName = Common::String::format("%s-%02d.SAV", target, slot);
 
253
        Common::InSaveFile *file = g_system->getSavefileManager()->openForLoading(fileName);
 
254
 
 
255
        if (file) {
 
256
                int saveVersion = file->readByte();
 
257
 
 
258
                if (saveVersion != kSavegameVersion) {
 
259
                        warning("Savegame of incompatible version");
 
260
                        delete file;
 
261
                        return SaveStateDescriptor();
 
262
                }
 
263
 
 
264
                uint32 saveNameLength = file->readUint16BE();
 
265
                char saveName[256];
 
266
                file->read(saveName, saveNameLength);
 
267
                saveName[saveNameLength] = 0;
 
268
 
 
269
                SaveStateDescriptor desc(slot, saveName);
 
270
 
 
271
                Graphics::Surface *thumbnail = new Graphics::Surface();
 
272
                assert(thumbnail);
 
273
                if (!Graphics::loadThumbnail(*file, *thumbnail)) {
 
274
                        delete thumbnail;
 
275
                        thumbnail = 0;
 
276
                }
 
277
                desc.setThumbnail(thumbnail);
 
278
 
 
279
                desc.setDeletableFlag(true);
 
280
                desc.setWriteProtectedFlag(false);
 
281
 
 
282
                uint32 saveDate = file->readUint32BE();
 
283
                uint16 saveTime = file->readUint16BE();
 
284
 
 
285
                int day = (saveDate >> 24) & 0xFF;
 
286
                int month = (saveDate >> 16) & 0xFF;
 
287
                int year = saveDate & 0xFFFF;
 
288
 
 
289
                desc.setSaveDate(year, month, day);
 
290
 
 
291
                int hour = (saveTime >> 8) & 0xFF;
 
292
                int minutes = saveTime & 0xFF;
 
293
 
 
294
                desc.setSaveTime(hour, minutes);
 
295
 
 
296
                // Slot 0 is used for the 'restart game' save in all Hugo games, thus
 
297
                // we prevent it from being deleted.
 
298
                desc.setDeletableFlag(slot != 0);
 
299
                desc.setWriteProtectedFlag(slot == 0);
 
300
 
 
301
                delete file;
 
302
                return desc;
 
303
        }
 
304
        return SaveStateDescriptor();
 
305
}
 
306
 
 
307
void HugoMetaEngine::removeSaveState(const char *target, int slot) const {
 
308
        Common::String fileName = Common::String::format("%s-%02d.SAV", target, slot);
 
309
        g_system->getSavefileManager()->removeSavefile(fileName);
 
310
}
181
311
} // End of namespace Hugo
182
312
 
183
313
#if PLUGIN_ENABLED_DYNAMIC(HUGO)
189
319
namespace Hugo {
190
320
 
191
321
void HugoEngine::initGame(const HugoGameDescription *gd) {
192
 
        char tmpStr[8];
193
 
 
194
322
        _gameType = gd->gameType;
195
323
        _platform = gd->desc.platform;
196
324
        _packedFl = (getFeatures() & GF_PACKED);
197
325
        _gameVariant = _gameType - 1 + ((_platform == Common::kPlatformWindows) ? 0 : 3);
198
 
 
199
 
//Generate filenames
200
 
        if (gd->desc.platform == Common::kPlatformWindows)
201
 
                sprintf(tmpStr, "%s%c", gd->desc.gameid, 'w');
202
 
        else
203
 
                sprintf(tmpStr, "%s%c", gd->desc.gameid, 'd');
204
 
 
205
 
        sprintf(_initFilename, "%s-00.SAV", tmpStr);
206
 
        sprintf(_saveFilename, "%s-%s.SAV", tmpStr, "%d");
207
326
}
208
327
 
209
328
} // End of namespace Hugo