SCI: Got rid of resource_dir & work_dir (temporarily disabled f_open_mirrored for that)
svn-id: r38807
This commit is contained in:
parent
6147bd3ed9
commit
2413a5690e
6 changed files with 14 additions and 80 deletions
|
@ -445,8 +445,6 @@ EngineState::EngineState() {
|
|||
|
||||
widget_serial_counter = 0;
|
||||
|
||||
resource_dir = 0;
|
||||
work_dir = 0;
|
||||
resmgr = 0;
|
||||
|
||||
game_name = 0;
|
||||
|
|
|
@ -45,10 +45,6 @@
|
|||
|
||||
namespace Sci {
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
# define FO_BINARY "b"
|
||||
#else
|
||||
|
@ -71,19 +67,14 @@ static struct _savegame_index_struct {
|
|||
** Otherwise, the new file is then opened for reading or writing.
|
||||
*/
|
||||
static FILE *f_open_mirrored(EngineState *s, char *fname) {
|
||||
int fd;
|
||||
char *buf = NULL;
|
||||
int fsize;
|
||||
|
||||
|
||||
debug(3, "f_open_mirrored(%s)", fname);
|
||||
|
||||
#if 0
|
||||
// TODO/FIXME: Use s->resource_dir to locate the file???
|
||||
File file;
|
||||
Common::File file;
|
||||
if (!file.open(fname))
|
||||
return NULL;
|
||||
|
||||
fsize = file.size();
|
||||
int fsize = file.size();
|
||||
if (fsize > 0) {
|
||||
buf = (char *)sci_malloc(fsize);
|
||||
file.read(buf, fsize);
|
||||
|
@ -91,58 +82,17 @@ static FILE *f_open_mirrored(EngineState *s, char *fname) {
|
|||
|
||||
file.close();
|
||||
|
||||
....
|
||||
copy the file to a savegame -> only makes sense to perform this change
|
||||
if we at the same time change the code for loading files to look among the
|
||||
savestates, and also change *all* file writing code to write to savestates,
|
||||
as it should
|
||||
...
|
||||
|
||||
Also, we may have to change the filename when creating a matchin savegame,
|
||||
e.g. prefix it with the target name
|
||||
#endif
|
||||
|
||||
chdir(s->resource_dir);
|
||||
fd = sci_open(fname, O_RDONLY | O_BINARY);
|
||||
if (!IS_VALID_FD(fd)) {
|
||||
chdir(s->work_dir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fsize = sci_fd_size(fd);
|
||||
if (fsize > 0) {
|
||||
buf = (char*)sci_malloc(fsize);
|
||||
read(fd, buf, fsize);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
chdir(s->work_dir);
|
||||
|
||||
// Visual C++ doesn't allow to specify O_BINARY with creat()
|
||||
#ifdef _MSC_VER
|
||||
fd = _open(fname, O_CREAT | O_BINARY | O_RDWR, S_IREAD | S_IWRITE);
|
||||
#else
|
||||
fd = open(fname, O_CREAT | O_BINARY | O_RDWR, S_IREAD | S_IWRITE);
|
||||
#endif
|
||||
|
||||
if (!IS_VALID_FD(fd) && buf) {
|
||||
free(buf);
|
||||
sciprintf("kfile.c: f_open_mirrored(): Warning: Could not create '%s' in '%s' (%d bytes to copy)\n", fname, s->work_dir, fsize);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fsize) {
|
||||
int ret;
|
||||
ret = write(fd, buf, fsize);
|
||||
if (ret < fsize) {
|
||||
sciprintf("kfile.c: f_open_mirrored(): Warning: Could not write all %ld bytes to '%s' in '%s' (only wrote %d)\n",
|
||||
(long)fsize, fname, s->work_dir, ret);
|
||||
}
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return sci_fopen(fname, "r" FO_BINARY "+");
|
||||
// FIXME: for now we just pretend this has failed
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define _K_FILE_MODE_OPEN_OR_CREATE 0
|
||||
|
@ -372,7 +322,7 @@ reg_t kDeviceInfo(EngineState *s, int funct_nr, int argc, reg_t *argv) {
|
|||
output_s = kernel_dereference_char_pointer(s, argv[1], 0);
|
||||
game_prefix = kernel_dereference_char_pointer(s, argv[2], 0);
|
||||
|
||||
sprintf(output_s, "%s/__throwaway", s->work_dir);
|
||||
sprintf(output_s, "__throwaway");
|
||||
debug(3, "K_DEVICE_INFO_GET_SAVECAT_NAME(%s) -> %s", game_prefix, output_s);
|
||||
}
|
||||
|
||||
|
@ -381,9 +331,9 @@ reg_t kDeviceInfo(EngineState *s, int funct_nr, int argc, reg_t *argv) {
|
|||
output_s = kernel_dereference_char_pointer(s, argv[1], 0);
|
||||
game_prefix = kernel_dereference_char_pointer(s, argv[2], 0);
|
||||
int savegame_id = UKPV(3);
|
||||
sprintf(output_s, "%s/__throwaway", s->work_dir);
|
||||
delete_savegame(s, savegame_id);
|
||||
sprintf(output_s, "__throwaway");
|
||||
debug(3, "K_DEVICE_INFO_GET_SAVEFILE_NAME(%s,%d) -> %s", game_prefix, savegame_id, output_s);
|
||||
delete_savegame(s, savegame_id);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -1143,8 +1143,6 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
|
|||
|
||||
retval->debug_mode = s->debug_mode;
|
||||
|
||||
retval->resource_dir = s->resource_dir;
|
||||
retval->work_dir = s->work_dir;
|
||||
retval->kernel_opt_flags = 0;
|
||||
retval->have_mouse_flag = 1;
|
||||
|
||||
|
|
|
@ -5272,8 +5272,6 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
|
|||
|
||||
retval->debug_mode = s->debug_mode;
|
||||
|
||||
retval->resource_dir = s->resource_dir;
|
||||
retval->work_dir = s->work_dir;
|
||||
retval->kernel_opt_flags = 0;
|
||||
retval->have_mouse_flag = 1;
|
||||
|
||||
|
@ -5326,7 +5324,7 @@ bool get_savegame_metadata(Common::SeekableReadStream* stream, SavegameMetadata*
|
|||
}
|
||||
}
|
||||
// End of auto-generated CFSML data reader code
|
||||
#line 1169 "engines/sci/engine/savegame.cfsml"
|
||||
#line 1167 "engines/sci/engine/savegame.cfsml"
|
||||
|
||||
if (read_eof)
|
||||
return false;
|
||||
|
|
|
@ -100,8 +100,6 @@ struct EngineState {
|
|||
|
||||
int widget_serial_counter; /* Used for savegames */
|
||||
|
||||
char *resource_dir; /* Directory the resource files are kept in */
|
||||
char *work_dir; /* Directory the game metadata should be written to */
|
||||
ResourceManager *resmgr; /* The resource manager */
|
||||
|
||||
char *game_name; /* Designation of the primary object (which inherits from Game) */
|
||||
|
|
|
@ -213,14 +213,10 @@ Common::Error SciEngine::go() {
|
|||
|
||||
version = getVersion();
|
||||
|
||||
char resource_dir[MAXPATHLEN+1] = "";
|
||||
getcwd(resource_dir, MAXPATHLEN); // Store resource directory
|
||||
|
||||
_resmgr = new ResourceManager(res_version, 256 * 1024);
|
||||
|
||||
if (!_resmgr) {
|
||||
printf("No resources found in '%s'.\nAborting...\n",
|
||||
resource_dir);
|
||||
printf("No resources found, aborting...\n");
|
||||
return Common::kNoGameDataFoundError;
|
||||
}
|
||||
|
||||
|
@ -249,9 +245,6 @@ Common::Error SciEngine::go() {
|
|||
// Set the savegame dir
|
||||
script_set_gamestate_save_dir(gamestate, ConfMan.get("savepath").c_str());
|
||||
|
||||
// Originally, work_dir tried to be ~/.freesci/game_name
|
||||
gamestate->work_dir = sci_strdup(ConfMan.get("savepath").c_str());
|
||||
gamestate->resource_dir = resource_dir;
|
||||
gamestate->port_serial = 0;
|
||||
gamestate->have_mouse_flag = 1;
|
||||
gamestate->animation_delay = 5;
|
||||
|
@ -310,7 +303,6 @@ Common::Error SciEngine::go() {
|
|||
game_exit(gamestate);
|
||||
script_free_engine(gamestate); // Uninitialize game state
|
||||
script_free_breakpoints(gamestate);
|
||||
free(gamestate->work_dir);
|
||||
|
||||
delete gamestate;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue