aboutsummaryrefslogtreecommitdiff
path: root/saga
diff options
context:
space:
mode:
authorJonathan Gray2004-04-23 11:40:51 +0000
committerJonathan Gray2004-04-23 11:40:51 +0000
commit8f8d1967c942f5eb6ba1b01ade037bb938f99d64 (patch)
tree169182858db035e40230eec8ef615667648b3a5f /saga
parent0ac8c4bd3f87399856ed0b5549877c01cd6d3506 (diff)
downloadscummvm-rg350-8f8d1967c942f5eb6ba1b01ade037bb938f99d64.tar.gz
scummvm-rg350-8f8d1967c942f5eb6ba1b01ade037bb938f99d64.tar.bz2
scummvm-rg350-8f8d1967c942f5eb6ba1b01ade037bb938f99d64.zip
convert the file routines to use the File class
svn-id: r13607
Diffstat (limited to 'saga')
-rw-r--r--saga/game.cpp33
-rw-r--r--saga/rscfile.cpp55
-rw-r--r--saga/rscfile.h6
3 files changed, 33 insertions, 61 deletions
diff --git a/saga/game.cpp b/saga/game.cpp
index 2f07cee1cd..bac6da92bc 100644
--- a/saga/game.cpp
+++ b/saga/game.cpp
@@ -31,6 +31,7 @@
#include "reinherit.h"
#include "yslib.h"
+#include "common/file.h"
/*
* Uses the following modules:
@@ -446,7 +447,7 @@ int LoadLanguage(void)
char lang_path[R_MAXPATH];
uint game_n;
- FILE *test_fp;
+ File test_file;
game_n = GameModule.game_number;
@@ -457,12 +458,7 @@ int LoadLanguage(void)
R_GAME_ITE_LANG_PREFIX,
GameModule.game_language, R_GAME_LANG_EXT);
- SYSFS_GetFQFN(GameModule.data_dir,
- lang_file, lang_path, R_MAXPATH);
-
- test_fp = fopen(lang_path, "r");
- if (test_fp == NULL) {
-
+ if (!test_file.open(lang_file)) {
R_printf(R_STDOUT,
"Couldn't open language file %s. "
"Using default (US English)\n", lang_path);
@@ -470,7 +466,7 @@ int LoadLanguage(void)
return R_SUCCESS;
}
- fclose(test_fp);
+ test_file.close();
if (INTERFACE_RegisterLang() != R_SUCCESS) {
R_printf(R_STDERR,
@@ -554,7 +550,7 @@ int DetectGame(const char *game_dir, uint * game_n_p)
uint file_count;
uint file_n;
- FILE *test_fp;
+ File test_file;
int file_missing = 0;
int found_game = 0;
@@ -574,18 +570,12 @@ int DetectGame(const char *game_dir, uint * game_n_p)
/* Try to open all files for this game */
for (file_n = 0; file_n < file_count; file_n++) {
- SYSFS_GetFQFN(game_dir,
- GameDescs[game_n].gd_filedescs[file_n].gf_fname,
- game_fpath, R_GAME_PATH_LIMIT);
- test_fp = fopen(game_fpath, "rb");
- if (test_fp == NULL) {
-
+ if (!test_file.open(GameDescs[game_n].gd_filedescs[file_n].gf_fname)) {
file_missing = 1;
-
break;
}
- fclose(test_fp);
+ test_file.close();
}
/* Try the next game, couldn't find all files for the current
@@ -654,10 +644,7 @@ int LoadGame(const char *game_dir, uint game_n)
game_fname = GameDescs[game_n].gd_filedescs[i].gf_fname;
- SYSFS_GetFQFN(game_dir,
- game_fname, game_fpath, R_GAME_PATH_LIMIT);
-
- if (RSC_OpenContext(load_ctxt, game_fpath) != R_SUCCESS) {
+ if (RSC_OpenContext(load_ctxt, game_fname) != R_SUCCESS) {
return R_FAILURE;
}
@@ -781,9 +768,7 @@ int Verify_ITEDISK(const char *game_dir)
test_ctx = RSC_CreateContext();
- SYSFS_GetFQFN(game_dir, "ITE.RSC", fpath, R_GAME_PATH_LIMIT);
-
- if (RSC_OpenContext(test_ctx, fpath) != R_SUCCESS) {
+ if (RSC_OpenContext(test_ctx, "ITE.RSC") != R_SUCCESS) {
return R_FAILURE;
}
diff --git a/saga/rscfile.cpp b/saga/rscfile.cpp
index b96a694b32..5a9ec29afa 100644
--- a/saga/rscfile.cpp
+++ b/saga/rscfile.cpp
@@ -47,7 +47,11 @@ namespace Saga {
R_RSCFILE_CONTEXT *RSC_CreateContext(void)
{
- R_RSCFILE_CONTEXT empty_context = { 0 };
+ R_RSCFILE_CONTEXT empty_context;
+ empty_context.rc_file_fspec = NULL;
+ empty_context.rc_file_loaded = 0;
+ empty_context.rc_res_table = NULL;
+ empty_context.rc_res_ct = 0;
R_RSCFILE_CONTEXT *new_context;
new_context = (R_RSCFILE_CONTEXT *)malloc(sizeof *new_context);
@@ -60,34 +64,23 @@ R_RSCFILE_CONTEXT *RSC_CreateContext(void)
return new_context;
}
-int RSC_OpenContext(R_RSCFILE_CONTEXT * rsc_context, const char *fspec)
+int RSC_OpenContext(R_RSCFILE_CONTEXT *rsc_context, const char *fspec)
{
- FILE *rsc_fp;
- int result;
-
- rsc_fp = fopen(fspec, "rb");
- if (rsc_fp == NULL) {
+ if (rsc_context->rc_file.isOpen()) {
return R_FAILURE;
}
- if (rsc_context->rc_file_open) {
+ if (!rsc_context->rc_file.open(fspec)) {
+
return R_FAILURE;
}
rsc_context->rc_file_fspec = fspec;
- rsc_context->rc_file_p = rsc_fp;
-
- result = ys_get_filesize(rsc_fp, &rsc_context->rc_file_size, NULL);
- if (result != YS_E_SUCCESS) {
- fclose(rsc_fp);
- return R_FAILURE;
- }
if (RSC_LoadRSC(rsc_context) != R_SUCCESS) {
return R_FAILURE;
}
- rsc_context->rc_file_open = 1;
rsc_context->rc_file_loaded = 1;
return R_SUCCESS;
@@ -95,12 +88,10 @@ int RSC_OpenContext(R_RSCFILE_CONTEXT * rsc_context, const char *fspec)
int RSC_CloseContext(R_RSCFILE_CONTEXT * rsc_context)
{
- if (rsc_context->rc_file_open) {
- fclose(rsc_context->rc_file_p);
+ if (rsc_context->rc_file.isOpen()) {
+ rsc_context->rc_file.close();
}
- rsc_context->rc_file_open = 0;
-
RSC_FreeRSC(rsc_context);
rsc_context->rc_file_loaded = 0;
@@ -137,17 +128,15 @@ int RSC_LoadRSC(R_RSCFILE_CONTEXT * rsc)
read_p = tblinfo_buf;
- if (rsc->rc_file_size < RSC_MIN_FILESIZE) {
+ if (rsc->rc_file.size() < RSC_MIN_FILESIZE) {
return R_FAILURE;
}
/* Read resource table info from the rear end of file
* \*------------------------------------------------------------- */
- fseek(rsc->rc_file_p, (long)(rsc->rc_file_size - 8), SEEK_SET);
-
- if (fread(tblinfo_buf,
- 1, RSC_TABLEINFO_SIZE, rsc->rc_file_p) != RSC_TABLEINFO_SIZE) {
+ rsc->rc_file.seek((long)(rsc->rc_file.size() - 8), SEEK_SET);
+ if (rsc->rc_file.read(tblinfo_buf, RSC_TABLEINFO_SIZE) != RSC_TABLEINFO_SIZE) {
return R_FAILURE;
}
@@ -156,7 +145,7 @@ int RSC_LoadRSC(R_RSCFILE_CONTEXT * rsc)
/* Check for sane table offset
* \*------------------------------------------------------------- */
- if (res_tbl_offset != rsc->rc_file_size - RSC_TABLEINFO_SIZE -
+ if (res_tbl_offset != rsc->rc_file.size() - RSC_TABLEINFO_SIZE -
RSC_TABLEENTRY_SIZE * res_tbl_ct) {
return R_FAILURE;
@@ -171,9 +160,9 @@ int RSC_LoadRSC(R_RSCFILE_CONTEXT * rsc)
return R_FAILURE;
}
- fseek(rsc->rc_file_p, (long)res_tbl_offset, SEEK_SET);
+ rsc->rc_file.seek((long)res_tbl_offset, SEEK_SET);
- if (fread(tbl_buf, 1, tbl_len, rsc->rc_file_p) != tbl_len) {
+ if (rsc->rc_file.read(tbl_buf, tbl_len) != tbl_len) {
free(tbl_buf);
return R_FAILURE;
}
@@ -191,8 +180,8 @@ int RSC_LoadRSC(R_RSCFILE_CONTEXT * rsc)
rsc_restbl[i].res_offset = ys_read_u32_le(read_p, &read_p);
rsc_restbl[i].res_size = ys_read_u32_le(read_p, &read_p);
- if ((rsc_restbl[i].res_offset > rsc->rc_file_size) ||
- (rsc_restbl[i].res_size > rsc->rc_file_size)) {
+ if ((rsc_restbl[i].res_offset > rsc->rc_file.size()) ||
+ (rsc_restbl[i].res_size > rsc->rc_file.size())) {
free(tbl_buf);
free(rsc_restbl);
@@ -276,16 +265,14 @@ RSC_LoadResource(R_RSCFILE_CONTEXT * rsc,
res_offset = rsc->rc_res_table[res_num].res_offset;
res_size = rsc->rc_res_table[res_num].res_size;
- if (fseek(rsc->rc_file_p, (long)res_offset, SEEK_SET) != 0) {
- return R_FAILURE;
- }
+ rsc->rc_file.seek((long)res_offset, SEEK_SET);
res_buf = (uchar *)malloc(res_size);
if (res_buf == NULL) {
return R_MEM;
}
- if (fread(res_buf, 1, res_size, rsc->rc_file_p) != res_size) {
+ if (rsc->rc_file.read(res_buf, res_size) != res_size) {
free(res_buf);
return R_FAILURE;
}
diff --git a/saga/rscfile.h b/saga/rscfile.h
index 6a9e7e423f..ef1bda2e10 100644
--- a/saga/rscfile.h
+++ b/saga/rscfile.h
@@ -32,6 +32,8 @@
#ifndef SAGA_RSCFILE_H__
#define SAGA_RSCFILE_H__
+#include "common/file.h"
+
namespace Saga {
#define RSC_TABLEINFO_SIZE 8
@@ -51,9 +53,7 @@ typedef struct R_RSCFILE_RESOURCE_tag {
struct R_RSCFILE_CONTEXT_tag {
const char *rc_file_fspec;
- FILE *rc_file_p;
- int rc_file_open;
- unsigned long rc_file_size;
+ File rc_file;
int rc_file_loaded;
R_RSCFILE_RESOURCE *rc_res_table;