author | ecalot
<ecalot> 2005-06-11 15:53:52 UTC |
committer | ecalot
<ecalot> 2005-06-11 15:53:52 UTC |
parent | e11943174f77e46bcd4920cba9fc4eb584f85639 |
PR/src/include/dat.h | +1 | -1 |
PR/src/include/disk.h | +1 | -1 |
PR/src/lib/actions/import.c | +2 | -2 |
PR/src/lib/formats/plv.c | +1 | -1 |
PR/src/lib/layers/dat.c | +20 | -12 |
PR/src/lib/layers/reslist.c | +1 | -1 |
diff --git a/PR/src/include/dat.h b/PR/src/include/dat.h index 3e6423c..7009dcf 100644 --- a/PR/src/include/dat.h +++ b/PR/src/include/dat.h @@ -43,7 +43,7 @@ typedef struct { typedef struct { tResourceId id; tResourceId palette; - unsigned short int size; + long int size; unsigned long int offset; /* Used internally in dat.c to remember the offset */ unsigned char number; /* Used for level number */ char type; diff --git a/PR/src/include/disk.h b/PR/src/include/disk.h index 2ab4599..2a78ae9 100644 --- a/PR/src/include/disk.h +++ b/PR/src/include/disk.h @@ -67,7 +67,7 @@ typedef struct tOpenFiles { FILE* file; char* name; unsigned char* content; - unsigned long int size; + long int size; }tOpenFiles; char mDiskVealidateFileHeader(unsigned char* text, int size, FILE* fp); diff --git a/PR/src/lib/actions/import.c b/PR/src/lib/actions/import.c index e493da0..4a11b42 100644 --- a/PR/src/lib/actions/import.c +++ b/PR/src/lib/actions/import.c @@ -107,7 +107,7 @@ int fullCompile(const char* vFiledat, const char* vDirExt, tResourceList* r, int if (hasFlag(raw_flag)) newRes.type=0; /* compile from raw */ getFileName(vFileext,vDirExt,res,vFiledat,vDatFileName,optionflag,backupExtension); /* the file is in the archive, so i'll add it to the main dat body */ - if ((newRes.size=((unsigned short)mLoadFileArray(vFileext,&newRes.data))<=0)) { + if ((newRes.size=(mLoadFileArray(vFileext,&newRes.data)))>0) { if (!mAddCompiledFileToDatFile(&newRes,vFileext)) { if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_ERRORS,getFileNameFromPath(vFileext)); error++; @@ -171,7 +171,7 @@ int partialCompile(const char* vFiledat, const char* vDirExt, tResourceList* r, getFileName(vFileext,vDirExt,&res,vFiledat,vDatFileName,optionflag,backupExtension); /* the file is in the partial list, so i'll import */ - if ((newRes.size=((unsigned short)mLoadFileArray(vFileext,&newRes.data)))) { + if ((newRes.size=mLoadFileArray(vFileext,&newRes.data))>0) { newRes.id=res.id; newRes.type=res.type; if (!mAddCompiledFileToDatFile(&newRes,vFileext)) { diff --git a/PR/src/lib/formats/plv.c b/PR/src/lib/formats/plv.c index 5580231..385ec75 100644 --- a/PR/src/lib/formats/plv.c +++ b/PR/src/lib/formats/plv.c @@ -193,7 +193,7 @@ int mFormatImportPlv(tResource *res) { /* save data */ posAux=res->data; res->data=pos; - mWriteFileInDatFileIgnoreChecksum(res); /* TODO: check res->size-- */ + mWriteFileInDatFileIgnoreChecksum(res); res->data=posAux; return 1; diff --git a/PR/src/lib/layers/dat.c b/PR/src/lib/layers/dat.c index 9e87da2..0bbe968 100644 --- a/PR/src/lib/layers/dat.c +++ b/PR/src/lib/layers/dat.c @@ -392,23 +392,36 @@ int mWriteBeginDatFile(const char* vFile, int optionflag) { } } -void dat_write(const tResource* res,unsigned long off) { +void dat_write(const tResource* res,unsigned char checksum) { tResource insert; - /* do the magic */ - fwrite(res->data,res->size,1,writeDatFile); - /* remember only indexed values */ insert.id=res->id; insert.size=res->size; - insert.offset=off; + insert.offset=((unsigned long)ftell(writeDatFile)); + + /* writes the checksum */ + fwritechar(&checksum,writeDatFile); + + /* do the magic */ + fwrite(res->data,res->size,1,writeDatFile); /* TODO: use an abstract use of the list (at least macros in reslist.h) */ list_insert(&resIndex,&insert); } void mWriteFileInDatFileIgnoreChecksum(const tResource* res) { - dat_write(res,(unsigned long)ftell(writeDatFile)); + tResource aux; + + /* set up virtual resource aux */ + aux=*res; + + /* drop the checksum */ + aux.data++; + aux.size--; + + /* write it */ + dat_write(&aux,res->data[0]); } void mWriteFileInDatFile(const tResource* res) { @@ -421,18 +434,13 @@ void mWriteFileInDatFile(const tResource* res) { int k = res->size; unsigned char checksum = 0; const unsigned char* dataAux = res->data; - unsigned long off; /* calculates the checksum */ while (k--) checksum+=*(dataAux++); checksum=~checksum; - /* writes the checksum and the data content */ - off=(unsigned long)ftell(writeDatFile); - fwritechar(&checksum,writeDatFile); - /* write the resource contents */ - dat_write(res,off); + dat_write(res,checksum); } diff --git a/PR/src/lib/layers/reslist.c b/PR/src/lib/layers/reslist.c index 42aec1b..6999597 100644 --- a/PR/src/lib/layers/reslist.c +++ b/PR/src/lib/layers/reslist.c @@ -78,7 +78,7 @@ void resourceListAdd(tResourceList* r,const tResource* res) { void printr(const tResource* record) { printf("id=(%d,%s)\n",record->id.value,record->id.index); printf("palette=(%d,%s)\n",record->palette.value,record->palette.index); - printf("size=%d offset=%lu\n",record->size,record->offset); + printf("size=%ld offset=%lu\n",record->size,record->offset); printf("number=%d type=%d\n",record->number,record->type); printf("path='%s' name='%s' desc='%s'\n\n",record->path,record->name,record->desc); }