[Scummvm-cvs-logs] CVS: scummvm/saga game.cpp,1.1,1.2 rscfile.cpp,1.1,1.2 rscfile.h,1.1,1.2

Jonathan Gray khalek at users.sourceforge.net
Fri Apr 23 04:42:14 CEST 2004


Update of /cvsroot/scummvm/scummvm/saga
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17998

Modified Files:
	game.cpp rscfile.cpp rscfile.h 
Log Message:
convert the file routines to use the File class

Index: game.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/game.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- game.cpp	12 Apr 2004 21:40:47 -0000	1.1
+++ game.cpp	23 Apr 2004 11:40:51 -0000	1.2
@@ -31,6 +31,7 @@
 #include "reinherit.h"
 
 #include "yslib.h"
+#include "common/file.h"
 
 /*
  * Uses the following modules:
@@ -446,7 +447,7 @@
 	char lang_path[R_MAXPATH];
 	uint game_n;
 
-	FILE *test_fp;
+	File test_file;
 
 	game_n = GameModule.game_number;
 
@@ -457,12 +458,7 @@
 		    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 @@
 			return R_SUCCESS;
 		}
 
-		fclose(test_fp);
+		test_file.close();
 
 		if (INTERFACE_RegisterLang() != R_SUCCESS) {
 			R_printf(R_STDERR,
@@ -554,7 +550,7 @@
 	uint file_count;
 	uint file_n;
 
-	FILE *test_fp;
+	File test_file;
 
 	int file_missing = 0;
 	int found_game = 0;
@@ -574,18 +570,12 @@
 		/* 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 @@
 
 		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 @@
 
 	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;
 	}
 

Index: rscfile.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/rscfile.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rscfile.cpp	12 Apr 2004 21:40:47 -0000	1.1
+++ rscfile.cpp	23 Apr 2004 11:40:51 -0000	1.2
@@ -47,7 +47,11 @@
 
 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 @@
 	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_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 @@
 
 	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 @@
 
 	/* 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 @@
 		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 @@
 		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 @@
 	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;
 	}

Index: rscfile.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/rscfile.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rscfile.h	12 Apr 2004 21:40:47 -0000	1.1
+++ rscfile.h	23 Apr 2004 11:40:51 -0000	1.2
@@ -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 @@
 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;





More information about the Scummvm-git-logs mailing list