| 550 | DVDISOCopyThread::DVDISOCopyThread(MTD *owner, |
| 551 | QMutex *drive_mutex, |
| 552 | const QString &dvd_device, |
| 553 | int track, |
| 554 | const QString &dest_file, |
| 555 | const QString &name, |
| 556 | const QString &start_string, |
| 557 | int nice_priority) |
| 558 | :DVDThread(owner, |
| 559 | drive_mutex, |
| 560 | dvd_device, |
| 561 | track, |
| 562 | dest_file, |
| 563 | name, |
| 564 | start_string, |
| 565 | nice_priority) |
| 566 | |
| 567 | { |
| 568 | } |
| 569 | |
| 570 | void DVDISOCopyThread::run() |
| 571 | { |
| 572 | // |
| 573 | // Be nice |
| 574 | // |
| 575 | |
| 576 | nice(nice_level); |
| 577 | job_name = QString(QObject::tr("ISO Image Copy of %1")).arg(rip_name); |
| 578 | if(keepGoing()) |
| 579 | { |
| 580 | copyFullDisc(); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | bool DVDISOCopyThread::copyFullDisc(void) |
| 585 | { |
| 586 | bool loop = true; |
| 587 | |
| 588 | setSubName(QObject::tr("Waiting for Access to DVD"), 1); |
| 589 | |
| 590 | while(loop) |
| 591 | { |
| 592 | if(dvd_device_access->tryLock()) |
| 593 | { |
| 594 | loop = false; |
| 595 | } |
| 596 | else |
| 597 | { |
| 598 | if(keepGoing()) |
| 599 | { |
| 600 | sleep(5); |
| 601 | } |
| 602 | else |
| 603 | { |
| 604 | problem("abandoned job because master control said we need to shut down"); |
| 605 | return false; |
| 606 | } |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | if(!keepGoing()) |
| 611 | { |
| 612 | problem("abandoned job because master control said we need to shut down"); |
| 613 | dvd_device_access->unlock(); |
| 614 | return false; |
| 615 | } |
| 616 | |
| 617 | ripfile = new RipFile(destination_file_string, ".iso"); |
| 618 | if(!ripfile->open(IO_WriteOnly | IO_Raw | IO_Truncate, false)) |
| 619 | { |
| 620 | problem(QString("DVDISOCopyThread could not open output file: %1").arg(ripfile->name())); |
| 621 | dvd_device_access->unlock(); |
| 622 | return false; |
| 623 | } |
| 624 | |
| 625 | sendLoggingEvent(QString("ISO DVD image copy to: %1").arg(ripfile->name())); |
| 626 | |
| 627 | int file = open( dvd_device_location, O_RDONLY ); |
| 628 | if(file == -1) |
| 629 | { |
| 630 | problem(QString("DVDISOCopyThread could not open dvd device: %1").arg(dvd_device_location)); |
| 631 | ripfile->remove(); |
| 632 | delete ripfile; |
| 633 | ripfile = NULL; |
| 634 | dvd_device_access->unlock(); |
| 635 | return false; |
| 636 | } |
| 637 | |
| 638 | off_t dvd_size = lseek(file, 0, SEEK_END); |
| 639 | lseek(file, 0, SEEK_SET); |
| 640 | |
| 641 | int buf_size = 4098; |
| 642 | unsigned char *buffer = new unsigned char[buf_size]; |
| 643 | long long total_bytes(0); |
| 644 | |
| 645 | QTime job_time; |
| 646 | job_time.start(); |
| 647 | |
| 648 | while( 1 ) |
| 649 | { |
| 650 | int bytes_read = read(file, buffer, buf_size); |
| 651 | if(bytes_read == -1) |
| 652 | { |
| 653 | perror("read"); |
| 654 | problem(QString("DVDISOCopyThread dvd device read error")); |
| 655 | ripfile->remove(); |
| 656 | delete ripfile; |
| 657 | ripfile = NULL; |
| 658 | delete buffer; |
| 659 | dvd_device_access->unlock(); |
| 660 | return false; |
| 661 | } |
| 662 | if(bytes_read == 0) |
| 663 | { |
| 664 | break; |
| 665 | } |
| 666 | |
| 667 | if(!ripfile->writeBlocks(buffer, bytes_read)) |
| 668 | { |
| 669 | problem(QString("DVDISOCopyThread rip file write error")); |
| 670 | ripfile->remove(); |
| 671 | delete ripfile; |
| 672 | ripfile = NULL; |
| 673 | delete buffer; |
| 674 | dvd_device_access->unlock(); |
| 675 | return false; |
| 676 | } |
| 677 | |
| 678 | total_bytes += bytes_read; |
| 679 | |
| 680 | setSubProgress((double) (total_bytes) / (double) (dvd_size), 1); |
| 681 | overall_progress = subjob_progress * sub_to_overall_multiple; |
| 682 | updateSubjobString(job_time.elapsed() / 1000, |
| 683 | QObject::tr("Ripping to file ~")); |
| 684 | |
| 685 | // |
| 686 | // Escape out and clean up if mtd main thread |
| 687 | // tells us to |
| 688 | // |
| 689 | |
| 690 | if(!keepGoing()) |
| 691 | { |
| 692 | problem("abandoned job because master control said we need to shut down"); |
| 693 | ripfile->remove(); |
| 694 | delete ripfile; |
| 695 | ripfile = NULL; |
| 696 | delete buffer; |
| 697 | dvd_device_access->unlock(); |
| 698 | return false; |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | delete buffer; |
| 703 | ripfile->close(); |
| 704 | delete ripfile; |
| 705 | dvd_device_access->unlock(); |
| 706 | sendLoggingEvent("job thread finished copying ISO image"); |
| 707 | return true; |
| 708 | } |
| 709 | |
| 710 | DVDISOCopyThread::~DVDISOCopyThread() |
| 711 | { |
| 712 | } |
| 713 | |
| 714 | /* |
| 715 | --------------------------------------------------------------------- |
| 716 | */ |
| 717 | |