Reimplement using a context-passing void ptr, but it does not feel that neat anymore...
But it works ! But it really feels like a functor would have been much much nicer, although that surely would have been much more code...
This commit is contained in:
parent
93d948361e
commit
a81f2de7ad
3 changed files with 35 additions and 17 deletions
|
|
@ -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<char*>(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<char*>(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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue