fix a resman method and make saving work using SaveFileManager
svn-id: r9828
This commit is contained in:
parent
5e0f61a8b2
commit
4df7dd406f
4 changed files with 51 additions and 60 deletions
|
@ -489,7 +489,8 @@ uint32 resMan::Res_fetch_len( uint32 res ) //Tony27Jan96
|
|||
{
|
||||
//returns the total file length of a resource - i.e. all headers are included too
|
||||
|
||||
FILE *fh=0; //file pointer
|
||||
//FILE *fh=0; //file pointer
|
||||
File fh;
|
||||
uint16 parent_res_file;
|
||||
uint16 actual_res;
|
||||
uint32 len;
|
||||
|
@ -503,17 +504,17 @@ uint32 resMan::Res_fetch_len( uint32 res ) //Tony27Jan96
|
|||
// first we have to find the file via the res_conv_table
|
||||
|
||||
|
||||
fh = fopen(resource_files[parent_res_file],"rb"); //open the cluster file
|
||||
if (fh==NULL)
|
||||
// open the cluster file
|
||||
if (fh.open(resource_files[parent_res_file],g_sword2->getGameDataPath()) == false)
|
||||
Con_fatal_error("Res_fetch_len cannot *OPEN* %s", resource_files[parent_res_file]);
|
||||
|
||||
|
||||
fread( &table_offset, sizeof(char), sizeof(uint32), fh); //1st DWORD of a cluster is an offset to the look-up table
|
||||
fh.read( &table_offset, sizeof(uint32)); //1st DWORD of a cluster is an offset to the look-up table
|
||||
|
||||
|
||||
fseek(fh, table_offset+(actual_res*8)+4, SEEK_SET); //2 dwords per resource + skip the position dword
|
||||
fh.seek(table_offset+(actual_res*8)+4, SEEK_SET); //2 dwords per resource + skip the position dword
|
||||
//fread( &pos, sizeof(char), 4, fh); //get position of our resource within the cluster file
|
||||
fread( &len, sizeof(char), 4, fh); //read the length
|
||||
fh.read( &len, 4); //read the length
|
||||
|
||||
|
||||
return(len);
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "save_rest.h"
|
||||
#include "scroll.h" // for Set_scrolling()
|
||||
#include "sound.h"
|
||||
#include "sword2.h"
|
||||
#include "walker.h"
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
@ -179,33 +180,27 @@ void FillSaveBuffer(mem *buffer, uint32 size, uint8 *desc)
|
|||
uint32 SaveData(uint16 slotNo, uint8 *buffer, uint32 bufferSize)
|
||||
{
|
||||
char saveFileName[MAX_FILENAME_LEN];
|
||||
FILE *fp;
|
||||
uint32 itemsWritten;
|
||||
SaveFile *out;
|
||||
SaveFileManager *mgr = g_system->get_savefile_manager();
|
||||
|
||||
sprintf(saveFileName, "%s.%.3d", g_sword2->_game_name, slotNo); // construct filename
|
||||
|
||||
//create saves directory just in case not there
|
||||
scumm_mkdir("saves");
|
||||
|
||||
|
||||
sprintf(saveFileName, "saves\\savegame.%.3d", slotNo); // construct filename
|
||||
|
||||
fp = fopen(saveFileName, "wb"); // attempt to open file for writing
|
||||
|
||||
if (fp==NULL)
|
||||
{
|
||||
if (!(out = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), true)))
|
||||
return(SR_ERR_FILEOPEN); // error: couldn't open file
|
||||
}
|
||||
else
|
||||
{
|
||||
// itemsWritten = fwrite(sourceAddress, size, count, fp);
|
||||
itemsWritten = fwrite(buffer, 1, bufferSize, fp); // write the buffer
|
||||
fclose(fp); // close savegame file
|
||||
|
||||
|
||||
itemsWritten = out->write(buffer, bufferSize); // write the buffer
|
||||
|
||||
delete out;
|
||||
delete mgr;
|
||||
|
||||
|
||||
if (itemsWritten == bufferSize) // if we successfully wrote it all
|
||||
return(SR_OK); // buffer saved ok
|
||||
else
|
||||
return(SR_ERR_WRITEFAIL); // write failed for some reason (could be hard drive full)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
@ -253,30 +248,26 @@ uint32 RestoreGame(uint16 slotNo) // (James05feb97)
|
|||
uint32 RestoreData(uint16 slotNo, uint8 *buffer, uint32 bufferSize)
|
||||
{
|
||||
char saveFileName[MAX_FILENAME_LEN];
|
||||
FILE *fp;
|
||||
SaveFile *in;
|
||||
SaveFileManager *mgr = g_system->get_savefile_manager();
|
||||
uint32 itemsRead;
|
||||
|
||||
sprintf(saveFileName, "%s.%.3d", g_sword2->_game_name, slotNo); // construct filename
|
||||
|
||||
sprintf(saveFileName, "saves\\savegame.%.3d", slotNo); // construct filename
|
||||
|
||||
fp = fopen(saveFileName, "rb"); // attempt to open file for reading
|
||||
|
||||
if (fp==NULL)
|
||||
{
|
||||
if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false)))
|
||||
return(SR_ERR_FILEOPEN); // error: couldn't open file
|
||||
}
|
||||
else
|
||||
{
|
||||
// itemsRead = fread(destAddress, size, count, fp);
|
||||
itemsRead = fread(buffer, 1, bufferSize, fp); // read savegame into the buffer
|
||||
|
||||
itemsRead = in->read(buffer, bufferSize); // read savegame into the buffer
|
||||
|
||||
if (itemsRead == bufferSize) // if we successfully read it all
|
||||
{
|
||||
fclose(fp); // close savegame file
|
||||
delete in;
|
||||
delete mgr;
|
||||
return(SR_OK); // file read ok
|
||||
}
|
||||
else // didn't read the expected amount of data for some reason
|
||||
{
|
||||
/*
|
||||
if (ferror(fp)) // if it was a genuine read error, before reaching the end of the file
|
||||
{
|
||||
fclose(fp); // close savegame file
|
||||
|
@ -284,10 +275,11 @@ uint32 RestoreData(uint16 slotNo, uint8 *buffer, uint32 bufferSize)
|
|||
}
|
||||
else // we reached the end of the file before we filled the savegame buffer (ie. incompatible savegame file!)
|
||||
{
|
||||
fclose(fp); // close savegame file
|
||||
*/
|
||||
delete in;
|
||||
delete mgr;
|
||||
return(SR_ERR_INCOMPATIBLE); // error: incompatible save-data - can't use!
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -393,25 +385,21 @@ uint32 GetSaveDescription(uint16 slotNo, uint8 *description) // (James05feb97)
|
|||
{
|
||||
char saveFileName[MAX_FILENAME_LEN];
|
||||
_savegameHeader dummy;
|
||||
FILE *fp;
|
||||
SaveFile *in;
|
||||
SaveFileManager *mgr = g_system->get_savefile_manager();
|
||||
|
||||
sprintf(saveFileName, "saves\\savegame.%.3d", slotNo); // construct filename
|
||||
sprintf(saveFileName, "%s.%.3d", g_sword2->_game_name, slotNo); // construct filename
|
||||
|
||||
fp = fopen(saveFileName, "rb"); // attempt to open file for reading
|
||||
|
||||
if (fp==NULL)
|
||||
{
|
||||
if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false)))
|
||||
return(SR_ERR_FILEOPEN); // error: couldn't open file
|
||||
}
|
||||
else
|
||||
{
|
||||
// fread(destAddress, size, count, fp);
|
||||
fread(&dummy, sizeof(_savegameHeader), 1, fp); // read header
|
||||
fclose(fp);
|
||||
|
||||
|
||||
in->read(&dummy, sizeof(_savegameHeader)); // read header
|
||||
delete in;
|
||||
delete mgr;
|
||||
sprintf((char*)description, dummy.description);
|
||||
return(SR_OK);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------------
|
||||
|
|
|
@ -106,6 +106,7 @@ Sword2State::Sword2State(GameDetector *detector, OSystem *syst)
|
|||
g_sword2 = this;
|
||||
_features = detector->_game.features;
|
||||
_gameId = detector->_game.id;
|
||||
_game_name = strdup(detector->_gameFileName.c_str());
|
||||
_bootParam = detector->_bootParam;
|
||||
|
||||
// Setup mixer
|
||||
|
|
|
@ -60,6 +60,7 @@ class Sword2State : public Engine {
|
|||
GameDetector *_detector;
|
||||
uint32 _features;
|
||||
byte _gameId;
|
||||
char *_game_name; // target name for saves
|
||||
Sword2Sound *_sound;
|
||||
OSystem::MutexRef _paletteMutex; // put in a gfx class?
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue