author | ecalot
<ecalot> 2006-02-17 01:53:22 UTC |
committer | ecalot
<ecalot> 2006-02-17 01:53:22 UTC |
parent | c5545da8b8b673c1a5583d4c6b6494936bbdba76 |
PR/src/include/common.h | +2 | -0 |
PR/src/lib/actions/classify.c | +4 | -1 |
PR/src/lib/actions/export.c | +4 | -3 |
PR/src/lib/actions/import.c | +4 | -1 |
PR/src/lib/layers/dat.c | +8 | -9 |
diff --git a/PR/src/include/common.h b/PR/src/include/common.h index 0da982f..9f47c40 100644 --- a/PR/src/include/common.h +++ b/PR/src/include/common.h @@ -216,6 +216,8 @@ PARSING_OPTRAW\ #define PR_RESULT_FD_IMPORT_FROM_MORE_THAN_ONE_DIR -20 #define PR_RESULT_FD_IMPORT_RECURSIVE -21 #define PR_RESULT_FD_NO_FILES_SELECTED -22 +#define PR_RESULT_INDEX_NOT_FOUND -23 +#define PR_RESULT_CHECKSUM_ERROR -24 #define PR_RESULT_ERR_WRONG_PRIMITIVE_CALL -19 #define PR_RESULT_HELP_SHOWN -1 #define PR_RESULT_SUCCESS 0 diff --git a/PR/src/lib/actions/classify.c b/PR/src/lib/actions/classify.c index e32c666..79cc3c3 100644 --- a/PR/src/lib/actions/classify.c +++ b/PR/src/lib/actions/classify.c @@ -60,7 +60,10 @@ int prClassifyDat(const char* vFiledat) { /* main loop */ for (indexNumber=0;(indexNumber<numberOfItems)&&(type==eResTypeBinary);indexNumber++) { - if (!mReadFileInDatFile(&res,indexNumber)) READ_ERROR; /* Read error */ + int ok; + ok=mReadFileInDatFile(&res,indexNumber); + if (ok==PR_RESULT_INDEX_NOT_FOUND) READ_ERROR; /* Read error */ + /*if (ok==PR_RESULT_CHECKSUM_ERROR) fprintf(outputStream,"Warning: Checksum error\n"); Warning TODO: add an output for the checksum warning */ if (res.id.value==0xFFFF) continue; /* Tammo Jan Bug fix */ type=verifyHeader(res.data,res.size); } diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c index 2b37f11..286b19d 100644 --- a/PR/src/lib/actions/export.c +++ b/PR/src/lib/actions/export.c @@ -91,8 +91,9 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti /* main loop */ for (indexNumber=0;ok&&(indexNumber<numberOfItems);indexNumber++) { - - if (!mReadFileInDatFile(&res,indexNumber)) return PR_RESULT_ERR_INVALID_DAT; /* Read error */ + ok=mReadFileInDatFile(&res,indexNumber); + if (ok==PR_RESULT_INDEX_NOT_FOUND) return PR_RESULT_ERR_INVALID_DAT; /* Read error */ + if (ok==PR_RESULT_CHECKSUM_ERROR) fprintf(outputStream,"Warning: Checksum error\n"); /* Warning */ if (res.id.value==0xFFFF) continue; /* Tammo Jan Bug fix */ /* add to res more information from the resource list */ resourceListAddInfo(r,&res); @@ -139,7 +140,7 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti tResource otherPalette; otherPalette.id=res.palette; /* Read the palette and load it into memory */ - if (mReadFileInDatFileId(&otherPalette)) { + if (mReadFileInDatFileId(&otherPalette)==PR_RESULT_SUCCESS) { /* All right, it's not so bad, I can handle it! I'll buffer the new palette */ tPaletteListItem e; e.bits=readPalette(&e.pal,otherPalette.data,otherPalette.size); diff --git a/PR/src/lib/actions/import.c b/PR/src/lib/actions/import.c index 4b4230c..56f1231 100644 --- a/PR/src/lib/actions/import.c +++ b/PR/src/lib/actions/import.c @@ -156,7 +156,10 @@ int import_partial(const char* vFiledat, const char* vDirExt, tResourceList* r, /* main loop */ for (indexNumber=0;(indexNumber<numberOfItems);indexNumber++) { - if (!mReadFileInDatFile(&res,indexNumber)) return PR_RESULT_ERR_INVALID_DAT; /* Read error */ + int readResult; + readResult=mReadFileInDatFile(&res,indexNumber); + if (readResult==PR_RESULT_INDEX_NOT_FOUND) return PR_RESULT_ERR_INVALID_DAT; /* Read error */ + if (readResult==PR_RESULT_CHECKSUM_ERROR) fprintf(outputStream,"Warning: Ignoring checksum error\n"); /* Warning */ if (res.id.value==0xFFFF) continue; /* Tammo Jan Bug fix */ diff --git a/PR/src/lib/layers/dat.c b/PR/src/lib/layers/dat.c index 361ef88..fc18f68 100644 --- a/PR/src/lib/layers/dat.c +++ b/PR/src/lib/layers/dat.c @@ -394,7 +394,7 @@ tIndexCursor dat_createCursor(unsigned char* highData,int highDataSize,unsigned /* the cursor read function */ -void dat_readRes(tResource* res, tIndexCursor indexCursor) { +int dat_readRes(tResource* res, tIndexCursor indexCursor) { /* for each archived file the index is read */ res->id.value= dat_readCursorGetId (indexCursor); strncpy(res->id.index,dat_readCursorGetIndexName (indexCursor),5); @@ -403,9 +403,10 @@ void dat_readRes(tResource* res, tIndexCursor indexCursor) { res->size= dat_readCursorGetSize (indexCursor); res->flags= dat_readCursorGetFlags (indexCursor); - res->size++; /* add the checksum */ + /*res->size++; * add the checksum */ - res->data=readDatFile+res->offset; + res->data=readDatFile+res->offset+1; /* ignore the checksum */ + return checkSum(readDatFile+res->offset,res->size+1); /*printf("reading resource: %d:%4s at %d order=%d\n",res->id.value,res->id.index,res->offset,res->id.order);*/ } @@ -483,15 +484,13 @@ int mReadBeginDatFile(unsigned short int *numberOfItems,const char* vFiledat){ } int mReadFileInDatFileId(tResource* res) { - if (!dat_cursorMoveId(&readIndexCursor,res->id)) return 0; /* false means index not found */ - dat_readRes(res,readIndexCursor); - return 1; /* true */ + if (!dat_cursorMoveId(&readIndexCursor,res->id)) return PR_RESULT_INDEX_NOT_FOUND; /* false means index not found */ + return dat_readRes(res,readIndexCursor)?PR_RESULT_SUCCESS:PR_RESULT_CHECKSUM_ERROR; /* depending on the checksum */ } int mReadFileInDatFile(tResource* res, int k) { - if (!dat_cursorMove(&readIndexCursor,k)) return 0; /* false means out of range */ - dat_readRes(res,readIndexCursor); - return 1; /* true */ + if (!dat_cursorMove(&readIndexCursor,k)) return PR_RESULT_INDEX_NOT_FOUND; /* false means out of range */ + return dat_readRes(res,readIndexCursor)?PR_RESULT_SUCCESS:PR_RESULT_CHECKSUM_ERROR; /* depending on the checksum */ } #endif