home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2004 April
/
CMCD0404.ISO
/
Software
/
Freeware
/
Multimedia
/
xcd
/
xcd2file
/
xcd2file.cpp
next >
Wrap
C/C++ Source or Header
|
2002-07-21
|
2KB
|
76 lines
#include <stdio.h>
#include <string.h>
#include "../core/xcd_media_reader.h"
#define MAX_BUFFER 65536
#define MAX_FILE_NAME 512
#define DEFAULE_OUT_EXTENSION ".out"
int main(int argc, char *argv[])
{
XCD_Media_Reader* pXmr;
char outFileName[MAX_FILE_NAME];
FILE *outFile;
char buffer[MAX_BUFFER];
int bytesRead, bytesWritten, totalWritten=0, errorOccured=0;
if (argc<2 || argc>3){
printf ("Usage: xcd2file <XCD file> [<output file name>]\n");
printf ("Convertrs an XCD (or any mode 2 form 2) file to a normal file\n");
printf ("by stripping the raw data and [if possible] using backup file\nto correct the original file\n");
printf ("if <output file name> is not defined, the output file is '<XCD file>.out'\n");
return 1;
}
pXmr = new XCD_Media_Reader (argv[1]);
if (!pXmr->isOpenedOK()){
printf ("File '%s' could not be properly opened for some reason,\n", argv[1]);
printf ("Operation aborted.\n");
return 1;
}
if (argc<3){
strcpy(outFileName, argv[1]);
strcat(outFileName, DEFAULE_OUT_EXTENSION);
} else
strcpy(outFileName, argv[2]);
printf ("outFileName='%s'\n",outFileName);
if (!(outFile=fopen(outFileName,"wb"))){
printf ("Cannot create output file '%s',\n",outFileName);
printf ("Operation aborted.\n");
return 1;
}
while ((bytesRead=(pXmr->readNext(buffer, MAX_BUFFER))) > 0){
totalWritten+=(bytesWritten=fwrite (buffer, 1, bytesRead, outFile));
//dprintf ("bytesRead=%d, bytesWritten=%d, totalWritten=%d\n",bytesRead, bytesWritten, totalWritten);
printf("#");
if (totalWritten/(10*1024*1024) != (totalWritten-bytesWritten)/(10*1024*1024))
printf ("\n%dM\n",totalWritten/(1024*1024));
if (bytesWritten!=bytesRead){
printf ("Error occured while writing to file,\nOperation Aborted.\n");
errorOccured=1;
break;
}
}printf("\n");
if (fclose(outFile)){
printf ("File '%s' could not be closed properly,\nOperation aborted.\n", outFileName);
}
printf ("%d bytes were written to '%s'.\n",totalWritten, outFileName);
if (!errorOccured)
printf ("Success\n");
else
printf ("Failed\n");
return errorOccured;
}