From 080430b3bda2bec05362119447d51b6c37f1cfc1 Mon Sep 17 00:00:00 2001 From: Steven Fuller Date: Tue, 18 Dec 2001 05:08:52 +0000 Subject: Redid the most of the file loading/saving. Now uses $HOME/.avp/ and $AVP_DIR to look for files. --- src/win95/awtexld.cpp | 40 ++++++++++----------- src/win95/awtexld.hpp | 4 +-- src/win95/bmpnames.cpp | 10 +++--- src/win95/chnkload.cpp | 36 ++++++++----------- src/win95/chnktexi.cpp | 11 +++--- src/win95/db.c | 11 +++--- src/win95/iff_ilbm.cpp | 20 ++--------- src/win95/media.hpp | 9 +++-- src/win95/mishchnk.cpp | 97 +++++++++++++++++++++----------------------------- src/win95/sprchunk.cpp | 43 ++++++++++------------ 10 files changed, 121 insertions(+), 160 deletions(-) (limited to 'src/win95') diff --git a/src/win95/awtexld.cpp b/src/win95/awtexld.cpp index 337e1d0..bef0b26 100644 --- a/src/win95/awtexld.cpp +++ b/src/win95/awtexld.cpp @@ -156,20 +156,20 @@ namespace AwTl { public: inline CreateTextureParms() - : fileNameS(NULL) - , fileH(INVALID_HANDLE_VALUE) + : loadTextureB(false) + , fileNameS(NULL) + , fileH(NULL) , dataP(NULL) , restoreH(NULL) , maxReadBytes(UINT_MAX) , bytesReadP(NULL) , flags(AW_TLF_DEFAULT) - , originalWidthP(NULL) - , originalHeightP(NULL) , widthP(NULL) , heightP(NULL) + , originalWidthP(NULL) + , originalHeightP(NULL) , prevTexP(static_cast(NULL)) , prevTexB(false) - , loadTextureB(false) , callbackF(NULL) , rectA(NULL) { @@ -180,7 +180,7 @@ namespace AwTl bool loadTextureB; char *fileNameS; - HANDLE fileH; + FILE *fileH; PtrUnionConst dataP; AW_BACKUPTEXTUREHANDLE restoreH; @@ -228,7 +228,7 @@ namespace AwTl db_log1(("AW: Potential Memory Leaks Detected!!!")); } #ifdef _CPPRTTI - #pragma message("Run-Time Type Identification (RTTI) is enabled") + #warning "Run-Time Type Identification (RTTI) is enabled" for (Iterator itLeak(*this) ; !itLeak.Done() ; itLeak.Next()) { db_logf1(("\tAW Object not deallocated: Type: %s RefCnt: %u",typeid(*itLeak.Get()).name(),itLeak.Get()->m_nRefCnt)); @@ -238,7 +238,7 @@ namespace AwTl db_log1(("AW: Object dump complete")); } #else // ! _CPPRTTI - #pragma message("Run-Time Type Identification (RTTI) is not enabled - memory leak checking will not report types") + #warning "Run-Time Type Identification (RTTI) is not enabled - memory leak checking will not report types" unsigned nRefs(0); for (Iterator itLeak(*this) ; !itLeak.Done() ; itLeak.Next()) { @@ -1762,9 +1762,9 @@ namespace AwTl { SurfUnion CreateTextureParms::DoCreate() const { - if (INVALID_HANDLE_VALUE!=fileH) + if (NULL != fileH) { - MediaWinFileMedium * pMedium = new MediaWinFileMedium; + MediaStdFileMedium * pMedium = new MediaStdFileMedium; pMedium->Attach(fileH); SurfUnion pTex = LoadTexture(pMedium,*this); pMedium->Detach(); @@ -1802,7 +1802,7 @@ namespace AwTl { switch (*_argFormatS++) { case 's': - if (pParams->fileNameS || INVALID_HANDLE_VALUE!=pParams->fileH || pParams->dataP || pParams->restoreH) + if (pParams->fileNameS || NULL!=pParams->fileH || pParams->dataP || pParams->restoreH) bad_parmsB = true; else { @@ -1811,16 +1811,16 @@ namespace AwTl { } break; case 'h': - if (pParams->fileNameS || INVALID_HANDLE_VALUE!=pParams->fileH || pParams->dataP || pParams->restoreH) + if (pParams->fileNameS || NULL!=pParams->fileH || pParams->dataP || pParams->restoreH) bad_parmsB = true; else { - pParams->fileH = va_arg(ap,HANDLE); - db_logf4(("\tFile HANDLE = 0x%08x",pParams->fileH)); + pParams->fileH = va_arg(ap,FILE *); + db_logf4(("\tFile HANDLE = %p",pParams->fileH)); } break; case 'p': - if (pParams->fileNameS || INVALID_HANDLE_VALUE!=pParams->fileH || pParams->dataP || pParams->restoreH) + if (pParams->fileNameS || NULL!=pParams->fileH || pParams->dataP || pParams->restoreH) bad_parmsB = true; else { @@ -1829,7 +1829,7 @@ namespace AwTl { } break; case 'r': - if (pParams->fileNameS || INVALID_HANDLE_VALUE!=pParams->fileH || pParams->dataP || pParams->restoreH || UINT_MAX!=pParams->maxReadBytes || pParams->bytesReadP) + if (pParams->fileNameS || NULL!=pParams->fileH || pParams->dataP || pParams->restoreH || UINT_MAX!=pParams->maxReadBytes || pParams->bytesReadP) bad_parmsB = true; else { @@ -1948,7 +1948,7 @@ namespace AwTl { } } - if (!pParams->fileNameS && INVALID_HANDLE_VALUE==pParams->fileH && !pParams->dataP && !pParams->restoreH) + if (!pParams->fileNameS && NULL==pParams->fileH && !pParams->dataP && !pParams->restoreH) { awTlLastErr = AW_TLE_BADPARMS; db_log2("AwCreateGraphic(): ERROR: No data medium is specified"); @@ -1973,9 +1973,9 @@ namespace AwTl { { if (pParams->fileNameS) { - pParams->fileH = CreateFile(pParams->fileNameS,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); + pParams->fileH = OpenGameFile(pParams->fileNameS, FILEMODE_READONLY, FILETYPE_PERM); - if (INVALID_HANDLE_VALUE==pParams->fileH) + if (NULL==pParams->fileH) { awTlLastErr = AW_TLE_CANTOPENFILE; // awTlLastWinErr = GetLastError(); @@ -1986,7 +1986,7 @@ namespace AwTl { SurfUnion textureP = pParams->DoCreate(); - CloseHandle(pParams->fileH); + fclose(pParams->fileH); return textureP; } diff --git a/src/win95/awtexld.hpp b/src/win95/awtexld.hpp index e41400c..e9c70fb 100644 --- a/src/win95/awtexld.hpp +++ b/src/win95/awtexld.hpp @@ -254,7 +254,7 @@ namespace AwTl { case 4: { unsigned shift=0; - unsigned val; + unsigned val=0; --_dstRowP.byteP; // decrement here because we increment before the first write for (unsigned colcount = _srcWidth; colcount; --colcount) { @@ -441,7 +441,7 @@ namespace AwTl { class TypicalTexFileLoader : public TexFileLoader { protected: - TypicalTexFileLoader() : m_pRowBuf(NULL), m_ppPixMap(NULL), m_pPalette(NULL) {} + TypicalTexFileLoader() : m_pPalette(NULL), m_ppPixMap(NULL), m_pRowBuf(NULL) {} virtual ~TypicalTexFileLoader(); diff --git a/src/win95/bmpnames.cpp b/src/win95/bmpnames.cpp index 92cb05a..63e139b 100644 --- a/src/win95/bmpnames.cpp +++ b/src/win95/bmpnames.cpp @@ -23,7 +23,7 @@ FORCE_CHUNK_INCLUDE_IMPLEMENT(bmpnames) BMP_Name::BMP_Name (const char * fname, int const gbnc_version) -: flags((BMPN_Flags)DEFAULT_BMPN_FLAGS), index(0), version_num (gbnc_version << BMPNAME_PARENT_VER_SHIFT), priority (DEFAULT_BMPN_PRIORITY), transparency_colour_union(0), enum_id(0) +: flags((BMPN_Flags)DEFAULT_BMPN_FLAGS), index(0), version_num (gbnc_version << BMPNAME_PARENT_VER_SHIFT), enum_id(0), priority (DEFAULT_BMPN_PRIORITY), transparency_colour_union(0) #if cencon , md5val(0) #endif @@ -33,7 +33,7 @@ BMP_Name::BMP_Name (const char * fname, int const gbnc_version) } BMP_Name::BMP_Name (const char * fname) -: flags((BMPN_Flags)DEFAULT_BMPN_FLAGS), index(0), version_num (0), priority (DEFAULT_BMPN_PRIORITY), transparency_colour_union(0), enum_id(0) +: flags((BMPN_Flags)DEFAULT_BMPN_FLAGS), index(0), version_num (0), enum_id(0), priority (DEFAULT_BMPN_PRIORITY), transparency_colour_union(0) #if cencon , md5val(0) #endif @@ -824,8 +824,6 @@ Matching_Images_Chunk::Matching_Images_Chunk(Chunk_With_Children * parent, char : Chunk(parent,"MATCHIMG") , flags ((MICFlags)(*(int *)(datablock+8) & MICF_MASK)) { - char const * datastart = datablock; - spares[0] = *(int *)datablock; spares[1] = *(int *)(datablock+4); @@ -888,7 +886,7 @@ ImageDescriptor const & Matching_Images_Chunk::GetLoadImage(ImageDescriptor cons RIF_IMPLEMENT_DYNCREATE("BMPMD5ID",Bitmap_MD5_Chunk) Bitmap_MD5_Chunk::Bitmap_MD5_Chunk(Chunk_With_Children * parent, int const * md5id, BMP_Name const & rcbmp, char const * rname, char const * sname) -: Chunk(parent,"BMPMD5ID"), spare(0), flags(BMD5F_0), version_num(rcbmp.version_num) +: Chunk(parent,"BMPMD5ID"), flags(BMD5F_0), version_num(rcbmp.version_num), spare(0) { memcpy(md5_val,md5id,16); @@ -907,7 +905,7 @@ Bitmap_MD5_Chunk::Bitmap_MD5_Chunk(Chunk_With_Children * parent, int const * md5 } Bitmap_MD5_Chunk::Bitmap_MD5_Chunk(Chunk_With_Children * parent, char const * datablock, size_t) -: Chunk(parent,"BMPMD5ID"), spare(*(int *)datablock), flags((BMPMD5_Flags)(*(int *)(datablock+4) & BMD5F_MASK)), version_num(*(int *)(datablock+8)) +: Chunk(parent,"BMPMD5ID"), flags((BMPMD5_Flags)(*(int *)(datablock+4) & BMD5F_MASK)), version_num(*(int *)(datablock+8)), spare(*(int *)datablock) { memcpy(md5_val,datablock+12,16); datablock += 28; diff --git a/src/win95/chnkload.cpp b/src/win95/chnkload.cpp index 757c68c..1a348df 100644 --- a/src/win95/chnkload.cpp +++ b/src/win95/chnkload.cpp @@ -378,32 +378,32 @@ ShapeInMSL const * ShapeInMSL::GetByName(char const * nam) } ShapeInMSL::ShapeInMSL() -: shptr(0) -, listpos(GLS_NOTINLIST) +: listpos(GLS_NOTINLIST) +, shptr(0) , in_hash_table(FALSE) { } ShapeInMSL::ShapeInMSL(int _p) -: shptr(0) -, listpos(_p) +: listpos(_p) +, shptr(0) , in_hash_table(FALSE) { } ShapeInMSL::ShapeInMSL(SHAPEHEADER * _s, char const * _n, int _p) -: shptr(_s) +: listpos(_p) +, shptr(_s) , name(_n) -, listpos(_p) , in_hash_table(FALSE) { AddToHashTables(); } ShapeInMSL::ShapeInMSL(ShapeInMSL const & sim) -: shptr(sim.shptr) +: listpos(sim.listpos) +, shptr(sim.shptr) , name(sim.name) -, listpos(sim.listpos) , in_hash_table(FALSE) { if (sim.in_hash_table) AddToHashTables(); @@ -479,11 +479,7 @@ RIFFHANDLE load_rif (const char * fname) CL_LogFile.lprintf("FAILED TO LOAD RIF: %s\n",fname); #endif ReleaseDirect3D(); -#if 0 - char message[200]; - sprintf(message,"Error loading %s",fname); - MessageBox(NULL,message,"AvP",MB_OK+MB_SYSTEMMODAL); -#endif + fprintf(stderr, "load_rif: Error loading %s\n", fname); exit(0x111); return INVALID_RIFFHANDLE; @@ -516,13 +512,9 @@ RIFFHANDLE load_rif_non_env (const char * fname) #endif ReleaseDirect3D(); -#if 0 - char message[200]; - sprintf(message,"Error loading %s",fname); - MessageBox(NULL,message,"AvP",MB_OK+MB_SYSTEMMODAL); -#endif fprintf(stderr, "load_rif_non_env: Error loading %s\n", fname); exit(0x111); + return INVALID_RIFFHANDLE; } #if OUTPUT_LOG @@ -1559,10 +1551,7 @@ void DeallocateRifLoadedShapeheader(SHAPEHEADER * shp) #if !StandardShapeLanguage #error Must have standard shape language #endif - - int max_num_texs = 0; - int i; - + if(shp->animation_header) { // so it gets deallocated properly @@ -1576,6 +1565,9 @@ void DeallocateRifLoadedShapeheader(SHAPEHEADER * shp) } #if !USE_LEVEL_MEMORY_POOL + int max_num_texs = 0; + int i; + if (shp->points) { if (*shp->points) DeallocateMem(*shp->points); diff --git a/src/win95/chnktexi.cpp b/src/win95/chnktexi.cpp index 8fe0345..6487737 100644 --- a/src/win95/chnktexi.cpp +++ b/src/win95/chnktexi.cpp @@ -109,12 +109,13 @@ static inline bool IsFileInFastFile(char const * pszFileName) static bool DoesFileExist(char const * pszFileName) { - DWORD dwFileAttributes = GetFileAttributes(pszFileName); - - if (0xffffffff == dwFileAttributes || dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + unsigned int attr = GetGameFileAttributes(pszFileName, FILETYPE_PERM); + + if ((attr & FILEATTR_DIRECTORY) != 0) return false; - else - return true; + if ((attr & FILEATTR_READABLE) == 0) + return false; + return true; } static char * GetPath(char * pszFileNameBuf, unsigned nBufSize, ImageDescriptor const & idsc, Chunk_With_Children * pEnvDataChunk, bool bGloballyPalettized) diff --git a/src/win95/db.c b/src/win95/db.c index 228bb1b..a9d63c7 100644 --- a/src/win95/db.c +++ b/src/win95/db.c @@ -85,7 +85,7 @@ int db_option = 0; /* Default is off. */ * logfile will go in the directory that is current when db_log_init() * is called. */ -#define ABSOLUTE_PATH 0 +#define ABSOLUTE_PATH 1 /* M A C R O S ******************************************************** */ @@ -152,12 +152,14 @@ static const char* db_assert_textA[ 3 ] = "Expression: %s", "File: %s Line: %d" }; -#if 0 + +#ifndef DB_NOWINDOWS static const char* db_prompt_std = "Quit program/force e(x)ception? [y/n/x]"; static const char* db_prompt_windows = "Quit program? [Yes/No]/force exception? [Cancel]"; #endif + static const char* db_assert_log_begin_text = "DB: FAILED ASSERTION BEGINS"; static const char* db_assert_log_end_text = @@ -394,7 +396,7 @@ void db_log_fired(const char *strP) if(!InitialisedLog) db_log_init(); { /* Open a file for appending, creating one if it doesn't yet exist. */ - FILE *fP = fopen(LogFileNameP, "a+"); + FILE *fP = OpenGameFile(LogFileNameP, FILEMODE_APPEND, FILETYPE_CONFIG); if(!fP) return; @@ -409,13 +411,12 @@ void db_log_init(void) sprintf( LogFileNameP, "%s", db_log_file_name ); #else /* Append the log file name to the current working directory. */ -/* TODO - path seperator */ sprintf( LogFileNameP, "%s/%s", getcwd( LogFileNameP, 240 ), db_log_file_name ); #endif /* Delete old log file. */ - remove(LogFileNameP); + DeleteGameFile(LogFileNameP); /* Flag that we have initialised the log file. */ InitialisedLog = 1; diff --git a/src/win95/iff_ilbm.cpp b/src/win95/iff_ilbm.cpp index b5ebcc5..c09d032 100644 --- a/src/win95/iff_ilbm.cpp +++ b/src/win95/iff_ilbm.cpp @@ -84,10 +84,6 @@ namespace IFF return true; } -// The uninitialised part of byte is shifted out. -#ifdef _MSC_VER -#pragma warning(disable: 4701) -#endif bool IlbmBodyChunk::EncodeNextRow(unsigned const * pRow) { if (!pEncodeDst) return false; @@ -96,7 +92,7 @@ namespace IFF { UBYTE * pBuf = pEncodeSrc; - unsigned byte; + unsigned byte=0; for (unsigned x=0; x //#endif // WIN32 || _WIN32 || WINDOWS || _WINDOWS @@ -497,7 +497,12 @@ class MediaStdFileMedium : public MediaMedium void Open(char const * pszFileName, char const * pszOpenMode) { - m_pFile = fopen(pszFileName,pszOpenMode); + if (pszOpenMode[0] != 'r' || pszOpenMode[1] != 'b') { + fprintf(stderr, "Open(%s, %s)\n", pszFileName, pszOpenMode); + m_fError |= MME_OPENFAIL; + return; + } + m_pFile = OpenGameFile(pszFileName, FILEMODE_READONLY, FILETYPE_PERM); if (!m_pFile) m_fError |= MME_OPENFAIL; } diff --git a/src/win95/mishchnk.cpp b/src/win95/mishchnk.cpp index f455f07..4c92dd7 100644 --- a/src/win95/mishchnk.cpp +++ b/src/win95/mishchnk.cpp @@ -116,8 +116,7 @@ BOOL Lockable_Chunk_With_Children::lock_chunk(File_Chunk & fchunk) CloseHandle (rif_file); return TRUE; - #endif - + #endif } BOOL Lockable_Chunk_With_Children::unlock_chunk (File_Chunk & fchunk, BOOL updateyn) @@ -362,10 +361,9 @@ File_Chunk::File_Chunk(const char * file_name) // Load in whole chunk and traverse char rifIsCompressed = FALSE; char *uncompressedData = NULL; - HANDLE rif_file; + FILE *rif_file; DWORD file_size; DWORD file_size_from_file; - unsigned long bytes_read; char * buffer; char * buffer_ptr; char id_buffer[9]; @@ -380,27 +378,28 @@ File_Chunk::File_Chunk(const char * file_name) strcpy (filename, file_name); - rif_file = CreateFileA (file_name, GENERIC_READ, 0, 0, OPEN_EXISTING, - FILE_FLAG_RANDOM_ACCESS, 0); + rif_file = OpenGameFile(file_name, FILEMODE_READONLY, FILETYPE_PERM); - if (rif_file == INVALID_HANDLE_VALUE) { + if (rif_file == NULL) { error_code = CHUNK_FAILED_ON_LOAD; return; } - file_size = GetFileSize (rif_file, 0); + fseek(rif_file, 0, SEEK_END); + file_size = ftell(rif_file); + rewind(rif_file); - - if (!ReadFile(rif_file, id_buffer, 8, &bytes_read, 0)) { + + if (fread(id_buffer, 1, 8, rif_file) != 8) { error_code = CHUNK_FAILED_ON_LOAD; - CloseHandle (rif_file); + fclose(rif_file); return; } #if UseOldChunkLoader if (strncmp (id_buffer, "REBINFLF", 8)) { error_code = CHUNK_FAILED_ON_LOAD_NOT_RECOGNISED; - CloseHandle (rif_file); + fclose(rif_file); return; } #else @@ -412,7 +411,7 @@ File_Chunk::File_Chunk(const char * file_name) else if (strncmp (id_buffer, "REBINFF2", 8)) { error_code = CHUNK_FAILED_ON_LOAD_NOT_RECOGNISED; - CloseHandle (rif_file); + fclose(rif_file); return; } #endif @@ -423,10 +422,9 @@ File_Chunk::File_Chunk(const char * file_name) pointer to the original data. */ if (rifIsCompressed) { - if (!ReadFile(rif_file, buffer+8, (file_size-8), &bytes_read, 0)) - { + if (fread(buffer+8, 1, (file_size-8), rif_file) != (file_size-8)) { error_code = CHUNK_FAILED_ON_LOAD; - CloseHandle (rif_file); + fclose(rif_file); return; } uncompressedData = HuffmanDecompress((HuffmanPackage*)buffer); @@ -438,27 +436,28 @@ File_Chunk::File_Chunk(const char * file_name) } else // the normal uncompressed approach: { - if (!ReadFile(rif_file, &file_size_from_file, 4, &bytes_read, 0)) { + if (fread(&file_size_from_file, 1, 4, rif_file) != 4) { error_code = CHUNK_FAILED_ON_LOAD; - CloseHandle (rif_file); + fclose(rif_file); return; } if (file_size != file_size_from_file) { error_code = CHUNK_FAILED_ON_LOAD_NOT_RECOGNISED; - CloseHandle (rif_file); + fclose(rif_file); return; } - if (!ReadFile(rif_file, buffer, (file_size-12), &bytes_read, 0)) - { + if (fread(buffer, 1, (file_size-12), rif_file) != (file_size-12)) { error_code = CHUNK_FAILED_ON_LOAD; - CloseHandle (rif_file); + fclose(rif_file); return; } buffer_ptr = buffer; } + fclose(rif_file); + // Process the RIF // The start of the first chunk @@ -471,7 +470,6 @@ File_Chunk::File_Chunk(const char * file_name) DynCreate(buffer_ptr); buffer_ptr += *(int *)(buffer_ptr + 8); - } /* KJL 17:59:42 19/09/98 - release the memory holding the rif */ @@ -484,10 +482,7 @@ File_Chunk::File_Chunk(const char * file_name) delete [] buffer; } - CloseHandle (rif_file); - post_input_processing(); - } File_Chunk::File_Chunk() @@ -1549,10 +1544,7 @@ Environment_Data_Chunk * File_Chunk::get_env_data() if (e_list.size()) return e_list.first_entry(); - else - { - return(0); - } + return 0; } void File_Chunk::build_object_array() @@ -1751,10 +1743,9 @@ RIF_File_Chunk::RIF_File_Chunk (Chunk_With_Children * parent, const char * file_ { char rifIsCompressed = FALSE; char *uncompressedData = NULL; - HANDLE rif_file; + FILE *rif_file; DWORD file_size; DWORD file_size_from_file; - unsigned long bytes_read; char * buffer; char * buffer_ptr; char id_buffer[9]; @@ -1766,21 +1757,21 @@ RIF_File_Chunk::RIF_File_Chunk (Chunk_With_Children * parent, const char * file_ error_code = 0; - rif_file = CreateFileA (file_name, GENERIC_READ, 0, 0, OPEN_EXISTING, - FILE_FLAG_RANDOM_ACCESS, 0); + rif_file = OpenGameFile(file_name, FILEMODE_READONLY, FILETYPE_PERM); - - if (rif_file == INVALID_HANDLE_VALUE) { + if (rif_file == NULL) { error_code = CHUNK_FAILED_ON_LOAD; Parent_File = ParentFileStore; return; } - file_size = GetFileSize (rif_file, 0); + fseek(rif_file, 0, SEEK_END); + file_size = ftell(rif_file); + rewind(rif_file); - if (!ReadFile(rif_file, id_buffer, 8, &bytes_read, 0)) { + if (fread(id_buffer, 1, 8, rif_file) != 8) { error_code = CHUNK_FAILED_ON_LOAD; - CloseHandle (rif_file); + fclose(rif_file); Parent_File = ParentFileStore; return; } @@ -1792,7 +1783,7 @@ RIF_File_Chunk::RIF_File_Chunk (Chunk_With_Children * parent, const char * file_ } else if (strncmp (id_buffer, "REBINFF2", 8)) { error_code = CHUNK_FAILED_ON_LOAD_NOT_RECOGNISED; - CloseHandle (rif_file); + fclose(rif_file); Parent_File = ParentFileStore; return; } @@ -1804,10 +1795,9 @@ RIF_File_Chunk::RIF_File_Chunk (Chunk_With_Children * parent, const char * file_ pointer to the original data. */ if (rifIsCompressed) { - if (!ReadFile(rif_file, buffer+8, (file_size-8), &bytes_read, 0)) - { + if (fread(buffer+8, 1, (file_size-8), rif_file) != (file_size-8)) { error_code = CHUNK_FAILED_ON_LOAD; - CloseHandle (rif_file); + fclose(rif_file); Parent_File = ParentFileStore; delete [] buffer; return; @@ -1822,9 +1812,9 @@ RIF_File_Chunk::RIF_File_Chunk (Chunk_With_Children * parent, const char * file_ else // the normal uncompressed approach: { //get the file size stored in the rif file - if (!ReadFile(rif_file, &file_size_from_file, 4, &bytes_read, 0)) { + if (fread(&file_size_from_file, 1, 4, rif_file) != 4) { error_code = CHUNK_FAILED_ON_LOAD; - CloseHandle (rif_file); + fclose(rif_file); Parent_File = ParentFileStore; delete [] buffer; return; @@ -1833,25 +1823,24 @@ RIF_File_Chunk::RIF_File_Chunk (Chunk_With_Children * parent, const char * file_ //and compare with the actual file size if (file_size != file_size_from_file) { error_code = CHUNK_FAILED_ON_LOAD_NOT_RECOGNISED; - CloseHandle (rif_file); + fclose(rif_file); Parent_File = ParentFileStore; delete [] buffer; return; } //read the rest of the file into the buffer - if (!ReadFile(rif_file, buffer, (file_size-12), &bytes_read, 0)) - { + if (fread(buffer, 1, (file_size-12), rif_file) != (file_size-12)) { error_code = CHUNK_FAILED_ON_LOAD; - CloseHandle (rif_file); + fclose(rif_file); Parent_File = ParentFileStore; delete [] buffer; return; } buffer_ptr = buffer; } - + fclose(rif_file); // Process the RIF @@ -1879,12 +1868,9 @@ RIF_File_Chunk::RIF_File_Chunk (Chunk_With_Children * parent, const char * file_ delete [] buffer; } - CloseHandle (rif_file); - post_input_processing(); Parent_File = ParentFileStore; - } void RIF_File_Chunk::post_input_processing() @@ -1991,8 +1977,5 @@ Environment_Data_Chunk * RIF_File_Chunk::get_env_data() if (e_list.size()) return e_list.first_entry(); - else - { - return(0); - } + return 0; } diff --git a/src/win95/sprchunk.cpp b/src/win95/sprchunk.cpp index 2b78f40..93f67e6 100644 --- a/src/win95/sprchunk.cpp +++ b/src/win95/sprchunk.cpp @@ -184,10 +184,9 @@ Sprite_Header_Chunk::Sprite_Header_Chunk(const char * file_name, Chunk_With_Chil : Chunk_With_Children(parent,"SPRIHEAD") { // Load in whole chunk and traverse - HANDLE rif_file; + FILE *rif_file; DWORD file_size; DWORD file_size_from_file; - unsigned long bytes_read; char * buffer; char * buffer_ptr; char id_buffer[9]; @@ -197,49 +196,51 @@ Sprite_Header_Chunk::Sprite_Header_Chunk(const char * file_name, Chunk_With_Chil error_code = 0; - rif_file = CreateFileA (file_name, GENERIC_READ, 0, 0, OPEN_EXISTING, - FILE_FLAG_RANDOM_ACCESS, 0); - - if (rif_file == INVALID_HANDLE_VALUE) { + rif_file = OpenGameFile(file_name, FILEMODE_READONLY, FILETYPE_PERM); + if (rif_file == NULL) { return; } - file_size = GetFileSize (rif_file, 0); - + fseek(rif_file, 0, SEEK_END); + file_size = ftell(rif_file); + rewind(rif_file); - if (!ReadFile(rif_file, id_buffer, 8, &bytes_read, 0)) { + if (fread(id_buffer, 1, 8, rif_file) != 8) { error_code = CHUNK_FAILED_ON_LOAD; - CloseHandle (rif_file); + fclose(rif_file); return; } - if (strncmp (id_buffer, "SPRIHEAD", 8)) { + if (strncmp(id_buffer, "SPRIHEAD", 8) != 0) { error_code = CHUNK_FAILED_ON_LOAD_NOT_RECOGNISED; - CloseHandle (rif_file); + fclose(rif_file); return; } - if (!ReadFile(rif_file, &file_size_from_file, 4, &bytes_read, 0)) { + if (fread(&file_size_from_file, 1, 4, rif_file) != 4) { error_code = CHUNK_FAILED_ON_LOAD; - CloseHandle (rif_file); + fclose(rif_file); return; } if (file_size != file_size_from_file) { error_code = CHUNK_FAILED_ON_LOAD_NOT_RECOGNISED; - CloseHandle (rif_file); + fclose(rif_file); return; } - buffer = new char [file_size]; - if (!ReadFile(rif_file, buffer, (file_size-12), &bytes_read, 0)) { + if (fread(buffer, 1, (file_size-12), rif_file) != (file_size-12)) { error_code = CHUNK_FAILED_ON_LOAD; - CloseHandle (rif_file); + delete [] buffer; + + fclose(rif_file); return; } + fclose(rif_file); + // Process the file buffer_ptr = buffer; @@ -248,7 +249,6 @@ Sprite_Header_Chunk::Sprite_Header_Chunk(const char * file_name, Chunk_With_Chil // The start of the first chunk while ((buffer_ptr-buffer)< ((signed) file_size-12) && !error_code) { - if ((*(int *)(buffer_ptr + 8)) + (buffer_ptr-buffer) > ((signed) file_size-12)) { error_code = CHUNK_FAILED_ON_LOAD_NOT_RECOGNISED; break; @@ -256,13 +256,9 @@ Sprite_Header_Chunk::Sprite_Header_Chunk(const char * file_name, Chunk_With_Chil DynCreate(buffer_ptr); buffer_ptr += *(int *)(buffer_ptr + 8); - } delete [] buffer; - - CloseHandle (rif_file); - } @@ -960,5 +956,4 @@ void Sprite_Extent_Chunk::fill_data_block(char* data_start) data_start+=4; *(int*)data_start=spare2; data_start+=4; - } -- cgit v1.3