aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sword2/resman.cpp13
-rw-r--r--sword2/save_rest.cpp92
-rw-r--r--sword2/sword2.cpp1
-rw-r--r--sword2/sword2.h1
4 files changed, 49 insertions, 58 deletions
diff --git a/sword2/resman.cpp b/sword2/resman.cpp
index d1c661cc4a..ff90daeadb 100644
--- a/sword2/resman.cpp
+++ b/sword2/resman.cpp
@@ -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);
diff --git a/sword2/save_rest.cpp b/sword2/save_rest.cpp
index f22b3234e3..4b041592c2 100644
--- a/sword2/save_rest.cpp
+++ b/sword2/save_rest.cpp
@@ -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
+
+ if (!(out = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), true)))
+ return(SR_ERR_FILEOPEN); // error: couldn't open file
+
-//create saves directory just in case not there
- scumm_mkdir("saves");
-
-
- sprintf(saveFileName, "saves\\savegame.%.3d", slotNo); // construct filename
+ itemsWritten = out->write(buffer, bufferSize); // write the buffer
- fp = fopen(saveFileName, "wb"); // attempt to open file for writing
+ delete out;
+ delete mgr;
+
- if (fp==NULL)
- {
- return(SR_ERR_FILEOPEN); // error: couldn't open file
- }
+ if (itemsWritten == bufferSize) // if we successfully wrote it all
+ return(SR_OK); // buffer saved ok
else
- {
-// itemsWritten = fwrite(sourceAddress, size, count, fp);
- itemsWritten = fwrite(buffer, 1, bufferSize, fp); // write the buffer
- fclose(fp); // close savegame file
-
- 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)
- }
+ 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, "saves\\savegame.%.3d", slotNo); // construct filename
-
- fp = fopen(saveFileName, "rb"); // attempt to open file for reading
+ sprintf(saveFileName, "%s.%.3d", g_sword2->_game_name, slotNo); // construct filename
- 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,11 +275,12 @@ 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,24 +385,20 @@ 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 (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false)))
+ return(SR_ERR_FILEOPEN); // error: couldn't open file
- if (fp==NULL)
- {
- 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);
- sprintf((char*)description, dummy.description);
- return(SR_OK);
- }
+
+ in->read(&dummy, sizeof(_savegameHeader)); // read header
+ delete in;
+ delete mgr;
+ sprintf((char*)description, dummy.description);
+ return(SR_OK);
}
//------------------------------------------------------------------------------------
diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp
index 1e765f3237..649269b76b 100644
--- a/sword2/sword2.cpp
+++ b/sword2/sword2.cpp
@@ -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
diff --git a/sword2/sword2.h b/sword2/sword2.h
index d8eb4512fc..e229376a63 100644
--- a/sword2/sword2.h
+++ b/sword2/sword2.h
@@ -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: