git » fp-git.git » commit 3ab4a83

coded partial import

author ecalot
2005-06-09 01:07:09 UTC
committer ecalot
2005-06-09 01:07:09 UTC
parent bb7320bfeb9921ad36b73103dfeb1d557ebf4086

coded partial import

PR/src/lib/actions/export.c +2 -2
PR/src/lib/actions/import.c +37 -32

diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c
index 5e5a800..2d602b8 100644
--- a/PR/src/lib/actions/export.c
+++ b/PR/src/lib/actions/export.c
@@ -91,13 +91,13 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti
 
 		/* add to res more information from the resource list */
 		resourceListAddInfo(r,&res);
-		if ((!res.type)&&(!hasFlag(raw_flag))) res.type=verifyHeader(res.data,res.size); 
 		
 		if (isInThePartialList(res.path,res.id.value /*TODO: use res.id and code the index support to the partial list*/)) { /* If the resource was specified do the tasks */
+			if ((!res.type)&&(!hasFlag(raw_flag))) res.type=verifyHeader(res.data,res.size); 
 			if (!(hasFlag(unknown_flag))) { /* If unknown flag is set do nothing but generate the unknown.xml file */
 				if (hasFlag(raw_flag)) res.type=0; /* If "extract as raw" is set, type is 0 */
 
-				/* get save file name (if unknown document it in the xml) */
+				/* get save file name (if unknown document is in the xml) */
 				getFileName(vFileext,vDirExt,&res,vFiledat,vDatFileName,optionflag,backupExtension);
 
 				switch (res.type) {
diff --git a/PR/src/lib/actions/import.c b/PR/src/lib/actions/import.c
index 126a914..0bf18da 100644
--- a/PR/src/lib/actions/import.c
+++ b/PR/src/lib/actions/import.c
@@ -104,22 +104,22 @@ int fullCompile(const char* vFiledat, const char* vDirExt, tResourceList* r, int
 		newRes.id=res->id;
 		newRes.type=res->type;
 	
-			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)))) {
-				if (!mAddCompiledFileToDatFile(&newRes,vFileext)) {
-					if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_ERRORS,getFileNameFromPath(vFileext));
-					error++;
-				} else {
-					if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_SUCCESS,getFileNameFromPath(vFileext));
-					ok++;
-				}
-				free(newRes.data);
-			} else {
-				if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_NOT_OPEN,getFileNameFromPath(vFileext));
+		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)))) {
+			if (!mAddCompiledFileToDatFile(&newRes,vFileext)) {
+				if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_ERRORS,getFileNameFromPath(vFileext));
 				error++;
+			} else {
+				if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_SUCCESS,getFileNameFromPath(vFileext));
+				ok++;
 			}
+			free(newRes.data);
+		} else {
+			if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_NOT_OPEN,getFileNameFromPath(vFileext));
+			error++;
+		}
 
 		list_nextCursor(r);
 	}
@@ -147,52 +147,57 @@ int partialCompile(const char* vFiledat, const char* vDirExt, tResourceList* r,
 	/*char vFileext[MAX_FILENAME_SIZE];*/
 	int                error,ok=0;
 	int                indexNumber;
+	char vFileext[MAX_FILENAME_SIZE];
 	unsigned short int numberOfItems;
 	tResource          res;
+	tResource          newRes;
 
 	/* Initialize abstract variables to read this new DAT file */
 	if ((error=mRWBeginDatFile(vFiledat,&numberOfItems,optionflag))) return error;
 
 	/* main loop */
 	for (indexNumber=0;(indexNumber<numberOfItems);indexNumber++) {
-		if (!mReadFileInDatFile(&res,indexNumber)) {
-			mRWCloseDatFile(0);
+		if (!mReadFileInDatFile(&res,indexNumber)) 
 			RW_ERROR; /* Read error */
-		}
-/*		if (res->id.value==0xFFFF) continue; * Tammo Jan Bug fix TODO: move to the dat layer? */
 
-#if 0 /* TODO: recode this based on extract function */
-		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,"POP1");
+		if (res.id.value==0xFFFF) continue; /* Tammo Jan Bug fix * TODO: move to the dat layer? */
+
+		/* add to res more information from the resource list */
+		resourceListAddInfo(r,&res);
+
+		if (isInThePartialList(res.path,res.id.value /*TODO: use res.id and code the index support to the partial list*/)) { /* If the resource was specified */
+			if ((!res.type)&&(!hasFlag(raw_flag))) res.type=verifyHeader(res.data,res.size); 
+			if (hasFlag(raw_flag)) res.type=0; /* If "extract as raw" is set, type is 0 */
+
+			/* get save file name (if unknown document is in the xml) */
+			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 ((r[id]->size=((unsigned long)mLoadFileArray(vFileext,&data)))) {
-				if (!mAddCompiledFileToDatFile(data,r[id],vFileext)) {
+			/* the file is in the partial list, so i'll import */
+			if ((newRes.size=((unsigned short)mLoadFileArray(vFileext,&newRes.data)))) {
+				newRes.id=res.id;
+				newRes.type=res.type;
+				if (!mAddCompiledFileToDatFile(&newRes,vFileext)) {
 					if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_ERRORS,getFileNameFromPath(vFileext));
 					error++;
 				} else {
 					if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_SUCCESS,getFileNameFromPath(vFileext));
 					ok++;
 				}
-				free(data);
+				free(newRes.data);
 			} else {
 				if (hasFlag(verbose_flag)) fprintf(outputStream,PR_TEXT_IMPORT_NOT_OPEN,getFileNameFromPath(vFileext));
 				error++;
 			}
 		} else {
-			r[id]->size=size-1;
-			mWriteFileInDatFileIgnoreChecksum(data,size);
+			/* the file wasn't in the partial list, so I'll re-copy it from the open dat file */
+			res.size--; /* TODO: check if this works */
+			mWriteFileInDatFileIgnoreChecksum(&res);
 		}
-#endif
 	}
 
 	/* 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;
 }