author | ecalot
<ecalot> 2004-03-21 23:30:04 UTC |
committer | ecalot
<ecalot> 2004-03-21 23:30:04 UTC |
parent | 70c8f7eb8f0639b8ea8405545d9cb146d5b7ead8 |
PR/src/console/main.c | +6 | -5 |
PR/src/lib/actions/classify.c | +7 | -5 |
PR/src/lib/actions/export.c | +2 | -3 |
PR/src/lib/actions/import.c | +32 | -13 |
PR/src/lib/layers/autodetect.c | +4 | -0 |
PR/src/lib/layers/dat.c | +38 | -13 |
PR/src/lib/layers/idlist.c | +4 | -0 |
PR/src/lib/pr.c | +6 | -5 |
PR/src/lib/xml/tree.c | +4 | -0 |
PR/src/lib/xml/unknown.c | +4 | -0 |
diff --git a/PR/src/console/main.c b/PR/src/console/main.c index bb408f4..2390b8a 100644 --- a/PR/src/console/main.c +++ b/PR/src/console/main.c @@ -204,10 +204,11 @@ int prImportDatOpt(const char* vDatFile, const char* vDirName, const char* vResF Return values: -1 DAT File couldn't be open for writing - -2 XML Parse error - -3 No memory - -4 XML Attribute not recognized - -5 XML File not found + -2 DAT file not found or invalid in partial importation + -3 XML Parse error + -4 No memory + -5 XML Attribute not recognized + -6 XML File not found 00 File successfully imported positive number: number of missing files */ @@ -229,7 +230,7 @@ int prImportDatOpt(const char* vDatFile, const char* vDirName, const char* vResF a=parseFile(vResFile,currentDatFileName,r); if (a<0) { /* parsing errors */ - a-=1; + a-=2; } else { /* importing errors/no errors */ a=compile (vDatFile, vDirName,r,opt,currentDatFileName,backupExtension); diff --git a/PR/src/lib/actions/classify.c b/PR/src/lib/actions/classify.c index 4029314..31a9d50 100644 --- a/PR/src/lib/actions/classify.c +++ b/PR/src/lib/actions/classify.c @@ -32,7 +32,7 @@ tasks.c: Princed Resources : Classify a DAT file */ #include <stdio.h> -#include "tasks.h" +#include "tasks.h" #include "memory.h" #include "resources.h" #include "dat.h" @@ -48,8 +48,9 @@ tasks.c: Princed Resources : Classify a DAT file extern int pop1; +#define READ_ERROR {mReadCloseDatFile();return 0;} + int prVerifyDatType(const char* vFiledat) { - int error; int indexNumber; long int id; unsigned char* data; @@ -58,16 +59,17 @@ int prVerifyDatType(const char* vFiledat) { unsigned short int numberOfItems; /* Initialize abstract variables to read this new DAT file */ - if (error=mReadBeginDatFile(&numberOfItems,vFiledat)) return error; + if (!mReadBeginDatFile(&numberOfItems,vFiledat)) return -1; /* main loop */ for (indexNumber=0;(indexNumber<numberOfItems)&&(type==RES_TYPE_BINARY);indexNumber++) { id=mReadGetFileInDatFile(indexNumber,&data,&size); - if (id<0) return 0; /* Read error */ + if (id<0) READ_ERROR; /* Read error */ if (id==0xFFFF) continue; /* Tammo Jan Bug fix */ - if (id>=MAX_RES_COUNT) return 0; /* A file with an ID out of range will be treated as invalid */ + if (id>=MAX_RES_COUNT) READ_ERROR; /* A file with an ID out of range will be treated as invalid */ type=verifyHeader(data,size); } + mReadCloseDatFile(); return pop1?type:(type+10); } diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c index c187d66..cf75a5f 100644 --- a/PR/src/lib/actions/export.c +++ b/PR/src/lib/actions/export.c @@ -74,7 +74,7 @@ for (id=0;id<MAX_RES_COUNT;id++) {\ int extract(const char* vFiledat,const char* vDirExt, tResource* r[], int optionflag, const char* vDatFileName, const char* vDatAuthor,const char* backupExtension) { char vFileext[MAX_FILENAME_SIZE]; int indexNumber; - int ok; + int ok=1; long int id; tImage image; /* this is used to make a persistent palette */ unsigned char* data; @@ -83,13 +83,12 @@ int extract(const char* vFiledat,const char* vDirExt, tResource* r[], int option unsigned short int paletteId=0; /* Initialize abstract variables to read this new DAT file */ - if (ok=mReadBeginDatFile(&numberOfItems,vFiledat)) return ok; + if (!mReadBeginDatFile(&numberOfItems,vFiledat)) return -1; /* Initializes the palette list */ initializePaletteList; /* main loop */ - ok=1; for (indexNumber=0;ok&&(indexNumber<numberOfItems);indexNumber++) { id=mReadGetFileInDatFile(indexNumber,&data,&size); diff --git a/PR/src/lib/actions/import.c b/PR/src/lib/actions/import.c index 07cbd30..084b9cf 100644 --- a/PR/src/lib/actions/import.c +++ b/PR/src/lib/actions/import.c @@ -93,7 +93,7 @@ for (id=0;id<MAX_RES_COUNT;id++) {\ | M A I N F U N C T I O N | \***************************************************************/ -int compile(const char* vFiledat, const char* vDirExt, tResource* r[], int optionflag, const char* vDatFileName,const char* backupExtension) { +int fullCompile(const char* vFiledat, const char* vDirExt, tResource* r[], int optionflag, const char* vDatFileName,const char* backupExtension) { /* Return values: -1 File couldn't be open for writing @@ -117,15 +117,15 @@ int compile(const char* vFiledat, const char* vDirExt, tResource* r[], int optio if ((r[id]->size=((unsigned short)mLoadFileArray(vFileext,&data)))) { mWriteInitResource(r+id); if (!mAddCompiledFileToDatFile(data,r[id],vFileext)) { - if (hasFlag(verbose_flag)) printf(PR_TEXT_IMPORT_ERRORS,getFileNameFromPath(vFileext)); + if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_ERRORS,getFileNameFromPath(vFileext)); error++; } else { - if (hasFlag(verbose_flag)) printf(PR_TEXT_IMPORT_SUCCESS,getFileNameFromPath(vFileext)); + if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_SUCCESS,getFileNameFromPath(vFileext)); ok++; } free(data); } else { - if (hasFlag(verbose_flag)) printf(PR_TEXT_IMPORT_NOT_OPEN,getFileNameFromPath(vFileext)); + if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_NOT_OPEN,getFileNameFromPath(vFileext)); error++; } } @@ -140,7 +140,16 @@ int compile(const char* vFiledat, const char* vDirExt, tResource* r[], int optio return error; } +#define RW_ERROR {mRWCloseDatFile(1);return 0;} int partialCompile(const char* vFiledat, const char* vDirExt, tResource* r[], int optionflag, const char* vDatFileName,const char* backupExtension) { + /* + Return values: + -2 Previous DAT file was invalid + -1 File couldn't be open for writing + 00 File successfully compiled + positive number: number of missing files + */ + char vFileext[MAX_FILENAME_SIZE]; int error,ok=0; int indexNumber; @@ -150,43 +159,53 @@ int partialCompile(const char* vFiledat, const char* vDirExt, tResource* r[], in unsigned short int numberOfItems; /* Initialize abstract variables to read this new DAT file */ - if (error=mRWBeginDatFile(vFiledat,&numberOfItems)) return error; + if ((error=mRWBeginDatFile(vFiledat,&numberOfItems,optionflag))) return error; /* main loop */ for (indexNumber=0;(indexNumber<numberOfItems);indexNumber++) { id=mReadGetFileInDatFile(indexNumber,&data,&size); - if (id<0) return 0; /* Read error */ + if (id<0) RW_ERROR; /* Read error */ /* TODO BUG: return doesn't close file */ if (id==0xFFFF) continue; /* Tammo Jan Bug fix */ - if (id>=MAX_RES_COUNT) return 0; /* A file with an ID out of range will be treated as invalid */ + if (id>=MAX_RES_COUNT) RW_ERROR; /* A file with an ID out of range will be treated as invalid */ mWriteInitResource(r+id); if (r[id]&&isInThePartialList(r[id]->path,id)) { /* If the resource was specified */ if (hasFlag(raw_flag)) r[id]->type=0; /* compile from raw */ getFileName(vFileext,vDirExt,r[id],(unsigned short)id,vFiledat,vDatFileName,optionflag,backupExtension); /* the file is in the archive, so i'll add it to the main dat body */ - if ((r[id]->size=((unsigned short)mLoadFileArray(vFileext,&data)))) { + if ((r[id]->size=((unsigned long)mLoadFileArray(vFileext,&data)))) { if (!mAddCompiledFileToDatFile(data,r[id],vFileext)) { - if (hasFlag(verbose_flag)) printf(PR_TEXT_IMPORT_ERRORS,getFileNameFromPath(vFileext)); + if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_ERRORS,getFileNameFromPath(vFileext)); error++; } else { - if (hasFlag(verbose_flag)) printf(PR_TEXT_IMPORT_SUCCESS,getFileNameFromPath(vFileext)); + if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_SUCCESS,getFileNameFromPath(vFileext)); ok++; } free(data); } else { - if (hasFlag(verbose_flag)) printf(PR_TEXT_IMPORT_NOT_OPEN,getFileNameFromPath(vFileext)); + if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_NOT_OPEN,getFileNameFromPath(vFileext)); error++; } } else { + r[id]->size=size-1; mWriteSetFileInDatFileIgnoreChecksum(data,size); } } - /* Free allocated resources and dynamic strings */ - freeResources; /* Close dat file */ mRWCloseDatFile(0); + /* Free allocated resources and dynamic strings */ + freeResources; + if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_DONE,ok,error); return error; } + +int compile(const char* vFiledat, const char* vDirExt, tResource* r[], int optionflag, const char* vDatFileName,const char* backupExtension) { + if (partialListActive()) { + return partialCompile(vFiledat,vDirExt,r,optionflag,vDatFileName,backupExtension); + } else { + return fullCompile(vFiledat,vDirExt,r,optionflag,vDatFileName,backupExtension); + } +} diff --git a/PR/src/lib/layers/autodetect.c b/PR/src/lib/layers/autodetect.c index a49cd34..d116498 100644 --- a/PR/src/lib/layers/autodetect.c +++ b/PR/src/lib/layers/autodetect.c @@ -112,6 +112,10 @@ const char* getExtDesc(int type) { static tResIdList partialList; +int partialListActive() { + return partialList.count; +} + void parseGivenPath(char* path) { /* PRE: partialList.list was not allocated diff --git a/PR/src/lib/layers/dat.c b/PR/src/lib/layers/dat.c index 605121a..28b59cf 100644 --- a/PR/src/lib/layers/dat.c +++ b/PR/src/lib/layers/dat.c @@ -58,13 +58,10 @@ void mReadCloseDatFile() { } int mReadBeginDatFile(unsigned short int *numberOfItems,const char* vFiledat){ - /* + /* Return Values: - -1 Wrong format - * - * - * - * + 0 Wrong Format or file not found + 1 Ok */ int ok; @@ -72,8 +69,8 @@ int mReadBeginDatFile(unsigned short int *numberOfItems,const char* vFiledat){ /* Open file */ readDatFileSize=mLoadFileArray(vFiledat,&readDatFile); - if (!readDatFileSize) return -1; - if (readDatFileSize<=6) return -1; + if (!readDatFileSize) return 0; + if (readDatFileSize<=6) {free(readDatFile);return 0;} readDatFilePoint=readDatFile; @@ -84,7 +81,7 @@ int mReadBeginDatFile(unsigned short int *numberOfItems,const char* vFiledat){ if ((indexOffset>readDatFileSize)&&((indexOffset+indexSize)!=readDatFileSize)) { free(readDatFile); - return -1; /* this is not a valid prince dat file */ + return 0; /* this is not a valid prince dat file */ } indexPointer=readDatFile+indexOffset; @@ -100,18 +97,19 @@ int mReadBeginDatFile(unsigned short int *numberOfItems,const char* vFiledat){ } recordSize=pop1?8:11; - return 0; + return 1; } int mReadGetFileInDatFile(int k,unsigned char* *data,unsigned long int *size) { - int ok=1; + int ok=1; /* TODO: rename mReadGet* for mRead* and mWriteSet for mWrite */ unsigned short int id; /* for each archived file the index is read */ id= (indexPointer[ofk+k*recordSize])+(indexPointer[ofk+k*recordSize+1]<<8); offset=(indexPointer[ofk+k*recordSize+2])+(indexPointer[ofk+k*recordSize+3]<<8)+(indexPointer[ofk+k*recordSize+4]<<16)+(indexPointer[ofk+k*recordSize+5]<<24); *size= (indexPointer[ofk+k*recordSize+6])+(indexPointer[ofk+k*recordSize+7]<<8)+1; - if (!pop1) ok=(indexPointer[ofk+k*recordSize+8]==0x40)&&(!indexPointer[ofk+k*recordSize+9])&&(!indexPointer[ofk+k*recordSize+10]); + if ((!pop1)&&(!(indexPointer[ofk+k*recordSize+8]==0x40)&&(!indexPointer[ofk+k*recordSize+9])&&(!indexPointer[ofk+k*recordSize+10]))) return -1; + if (offset+indexSize>readDatFileSize) return -1; *data=readDatFile+offset; return ok?id:-1; } @@ -127,7 +125,7 @@ int mReadInitResource(tResource** res,const unsigned char* data,long size) { (*res)->palette=0; (*res)->number=0; (*res)->size=(unsigned short int)size; - (*res)->offset=(unsigned short)offset; + (*res)->offset=(unsigned short)offset; /* TODO delete this line */ (*res)->type=verifyHeader(data,(unsigned short int)size); } else { /* If resource type is invalid or 0, the type will be decided by PR */ if (!((*res)->type)) (*res)->type=verifyHeader(data,(unsigned short int)size); @@ -145,6 +143,11 @@ int mWriteBeginDatFile(const char* vFile, int optionflag) { /* Opens safely a dat file for writing mode and reserves space for the headers + + Return Values: + 1 Ok + 0 File couldn't be open + */ if (writeOpen(vFile,&writeDatFile,optionflag|backup_flag)) { @@ -156,6 +159,9 @@ int mWriteBeginDatFile(const char* vFile, int optionflag) { } void mWriteInitResource(tResource** res) { + if ((*res)==NULL) { + (*res)=(tResource*)malloc(sizeof(tResource)); + } (*res)->offset=(unsigned long)ftell(writeDatFile); } @@ -216,3 +222,22 @@ void mWriteCloseDatFile(tResource* r[],int dontSave,int optionflag, const char* writeClose(writeDatFile,dontSave,optionflag,backupExtension); } +/***************************************************************\ +| DAT R/W primitives | +\***************************************************************/ + +int mRWBeginDatFile(const char* vFile, unsigned short int *numberOfItems, int optionflag) { + if (!mReadBeginDatFile(numberOfItems,vFile)) return -2; + if (!mWriteBeginDatFile(vFile,optionflag)) { + mReadCloseDatFile(); + return -1; + } + return 0; +} + + + + + + + diff --git a/PR/src/lib/layers/idlist.c b/PR/src/lib/layers/idlist.c index a49cd34..d116498 100644 --- a/PR/src/lib/layers/idlist.c +++ b/PR/src/lib/layers/idlist.c @@ -112,6 +112,10 @@ const char* getExtDesc(int type) { static tResIdList partialList; +int partialListActive() { + return partialList.count; +} + void parseGivenPath(char* path) { /* PRE: partialList.list was not allocated diff --git a/PR/src/lib/pr.c b/PR/src/lib/pr.c index bb408f4..2390b8a 100644 --- a/PR/src/lib/pr.c +++ b/PR/src/lib/pr.c @@ -204,10 +204,11 @@ int prImportDatOpt(const char* vDatFile, const char* vDirName, const char* vResF Return values: -1 DAT File couldn't be open for writing - -2 XML Parse error - -3 No memory - -4 XML Attribute not recognized - -5 XML File not found + -2 DAT file not found or invalid in partial importation + -3 XML Parse error + -4 No memory + -5 XML Attribute not recognized + -6 XML File not found 00 File successfully imported positive number: number of missing files */ @@ -229,7 +230,7 @@ int prImportDatOpt(const char* vDatFile, const char* vDirName, const char* vResF a=parseFile(vResFile,currentDatFileName,r); if (a<0) { /* parsing errors */ - a-=1; + a-=2; } else { /* importing errors/no errors */ a=compile (vDatFile, vDirName,r,opt,currentDatFileName,backupExtension); diff --git a/PR/src/lib/xml/tree.c b/PR/src/lib/xml/tree.c index a49cd34..d116498 100644 --- a/PR/src/lib/xml/tree.c +++ b/PR/src/lib/xml/tree.c @@ -112,6 +112,10 @@ const char* getExtDesc(int type) { static tResIdList partialList; +int partialListActive() { + return partialList.count; +} + void parseGivenPath(char* path) { /* PRE: partialList.list was not allocated diff --git a/PR/src/lib/xml/unknown.c b/PR/src/lib/xml/unknown.c index a49cd34..d116498 100644 --- a/PR/src/lib/xml/unknown.c +++ b/PR/src/lib/xml/unknown.c @@ -112,6 +112,10 @@ const char* getExtDesc(int type) { static tResIdList partialList; +int partialListActive() { + return partialList.count; +} + void parseGivenPath(char* path) { /* PRE: partialList.list was not allocated