diff --git a/src/dvdcopy.cc b/src/dvdcopy.cc index 76376b4..8a5159a 100644 --- a/src/dvdcopy.cc +++ b/src/dvdcopy.cc @@ -111,18 +111,29 @@ int DVDCopy::copyFile(const DVDFileData * dat, int firstBlock, } DVDOutFile outfile(targetDirectory.c_str(), dat->title, dat->domain); - auto success = [&outfile](int offset, int nb, - unsigned char * buffer, - const DVDFileData * dat) { - outfile.writeSectors(reinterpret_cast(buffer), nb); - }; int skipped = 0; - auto failure = [&outfile, &skipped, this](int blk, int nb, - const DVDFileData * dat) { - outfile.skipSectors(nb); - registerBadSectors(dat, blk, nb); - skipped += nb; + struct encaps { + int & sk; + DVDOutFile & of; + DVDCopy * dd; + } base = { skipped, outfile, this}; + + auto success = [](int offset, int nb, + unsigned char * buffer, + const DVDFileData * dat, + void * en) { + encaps * b = (encaps*) en; + b->of.writeSectors(reinterpret_cast(buffer), nb); + }; + + auto failure = [](int blk, int nb, + const DVDFileData * dat, + void * en) { + encaps * b = (encaps*) en; + b->of.skipSectors(nb); + b->dd->registerBadSectors(dat, blk, nb); + b->sk += nb; }; int size = file->fileSize(); @@ -137,7 +148,8 @@ int DVDCopy::copyFile(const DVDFileData * dat, int firstBlock, if(blockNumber < 0) blockNumber = size - current_size; - file->walkFile(current_size, blockNumber, readNumber, success, failure); + file->walkFile(current_size, blockNumber, readNumber, + success, failure, &base); outfile.closeFile(); if(skipped) { diff --git a/src/dvdfile.cc b/src/dvdfile.cc index 8fad229..4a7ef3d 100644 --- a/src/dvdfile.cc +++ b/src/dvdfile.cc @@ -125,9 +125,12 @@ DVDFile * DVDFile::openFile(dvd_reader_t * reader, const DVDFileData * dat) void DVDFile::walkFile(int start, int blocks, int steps, void (*successfulRead)(int offset, int nb, unsigned char * buffer, - const DVDFileData * dat), + const DVDFileData * dat, + void * d), void (*failedRead)(int offset, int nb, - const DVDFileData * dat)) + const DVDFileData * dat, + void * d), + void * d) { /* Data structures necessary for progress report */ struct timeval init; @@ -168,11 +171,11 @@ void DVDFile::walkFile(int start, int blocks, int steps, /* There was an error reading the file. */ printf("\nError while reading block %d of file %s, skipping\n", blk, fileName.c_str()); - failedRead(blk, nb, dat); + failedRead(blk, nb, dat, d); read = nb; } else - successfulRead(blk, read, readBuffer.get(), dat); + successfulRead(blk, read, readBuffer.get(), dat, d); remaining -= read; blk += read; diff --git a/src/dvdfile.hh b/src/dvdfile.hh index 75c4e40..5ad53bb 100644 --- a/src/dvdfile.hh +++ b/src/dvdfile.hh @@ -62,9 +62,12 @@ public: void walkFile(int start, int blocks, int steps, void (*successfulRead)(int offset, int nb, unsigned char * buffer, - const DVDFileData * dat), + const DVDFileData * dat, + void * ptr), void (*failedRead)(int offset, int nb, - const DVDFileData * dat)); + const DVDFileData * dat, + void * ptr), + void * ptr); };