Commit 0ede7206 authored by Ömer Fadıl Usta's avatar Ömer Fadıl Usta 😊 Committed by Albert Astals Cid
Browse files

Add extra checks for externalbins

Fix some possible calls over null objects
Shorten the repeated parts

BUG: 452814
parent 74b3bd88
Pipeline #187806 passed with stage
in 4 minutes and 25 seconds
......@@ -254,8 +254,8 @@ void K3b::CdCopyJob::slotDiskInfoReady( K3b::Device::DeviceHandler* dh )
//
// To copy mode2 data tracks we need cdrecord >= 2.01a12 which introduced the -xa1 and -xamix options
//
if( k3bcore->externalBinManager()->binObject("cdrecord") &&
!k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "xamix" ) ) {
const K3b::ExternalBin* cdrecordBin = k3bcore->externalBinManager()->binObject("cdrecord");
if( cdrecordBin && !cdrecordBin->hasFeature( "xamix" ) ) {
for( K3b::Device::Toc::const_iterator it = d->toc.constBegin(); it != d->toc.constEnd(); ++it ) {
if( (*it).type() == K3b::Device::Track::TYPE_DATA &&
( (*it).mode() == K3b::Device::Track::XA_FORM1 ||
......
......@@ -83,7 +83,7 @@ void K3b::CloneJob::start()
m_running = false;
return;
}
else if( !cdrecordBin->hasFeature( "clone" ) ) {
else if( cdrecordBin && !cdrecordBin->hasFeature( "clone" ) ) {
emit infoMessage( i18n("Cdrecord version %1 does not have cloning support.",cdrecordBin->version()), MessageError );
jobFinished(false);
m_running = false;
......
......@@ -112,12 +112,12 @@ void K3b::DvdCopyJob::start()
d->readerRunning = d->writerRunning = false;
emit newTask( i18n("Checking Source Medium") );
const K3b::ExternalBin* growisofsBin = k3bcore->externalBinManager()->binObject("growisofs");
if( m_onTheFly &&
k3bcore->externalBinManager()->binObject( "growisofs" )->version() < K3b::Version( 5, 12 ) ) {
growisofsBin && growisofsBin->version() < K3b::Version( 5, 12 ) ) {
m_onTheFly = false;
emit infoMessage( i18n("K3b does not support writing on-the-fly with growisofs %1.",
k3bcore->externalBinManager()->binObject( "growisofs" )->version()), MessageError );
growisofsBin->version()), MessageError );
emit infoMessage( i18n("Disabling on-the-fly writing."), MessageInfo );
}
......@@ -160,16 +160,18 @@ void K3b::DvdCopyJob::slotDiskInfoReady( K3b::Device::DeviceHandler* dh )
else {
// first let's determine which application to use
d->usedWritingApp = writingApp();
const K3b::ExternalBin* cdrecordBin = k3bcore->externalBinManager()->binObject("cdrecord");
const K3b::ExternalBin* growisofsBin = k3bcore->externalBinManager()->binObject("growisofs");
if ( d->usedWritingApp == K3b::WritingAppAuto ) {
// prefer growisofs to wodim, which doesn't work all that great for DVDs
// (and doesn't support BluRay at all)
if ( k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "wodim" ) )
if ( cdrecordBin && cdrecordBin->hasFeature( "wodim" ) )
d->usedWritingApp = K3b::WritingAppGrowisofs;
// otherwise, let's default to cdrecord for the time being
// FIXME: use growisofs for non-dao and non-auto mode
else {
if ( K3b::Device::isBdMedia( d->sourceDiskInfo.mediaType() ) ) {
if ( k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "blu-ray" ) )
if ( cdrecordBin && cdrecordBin->hasFeature( "blu-ray" ) )
d->usedWritingApp = K3b::WritingAppCdrecord;
else
d->usedWritingApp = K3b::WritingAppGrowisofs;
......@@ -236,8 +238,7 @@ void K3b::DvdCopyJob::slotDiskInfoReady( K3b::Device::DeviceHandler* dh )
jobFinished(false);
return;
}
else if( k3bcore->externalBinManager()->binObject( "growisofs" ) &&
!k3bcore->externalBinManager()->binObject( "growisofs" )->hasFeature( "dual-layer" ) ) {
else if( growisofsBin && !growisofsBin->hasFeature( "dual-layer" ) ) {
emit infoMessage( i18n("This growisofs version does not support writing Double Layer DVDs."), MessageError );
d->running = false;
jobFinished(false);
......@@ -266,8 +267,7 @@ void K3b::DvdCopyJob::slotDiskInfoReady( K3b::Device::DeviceHandler* dh )
// writable space in DAO mode
// with version >= 5.15 growisofs supports specifying the size of the track
if( m_writingMode != K3b::WritingModeSao || !m_onTheFly || m_onlyCreateImage ||
( k3bcore->externalBinManager()->binObject( "growisofs" ) &&
k3bcore->externalBinManager()->binObject( "growisofs" )->hasFeature( "daosize" ) ) ||
( growisofsBin && growisofsBin->hasFeature( "daosize" ) ) ||
d->usedWritingApp == K3b::WritingAppCdrecord ) {
d->lastSector = dh->toc().lastSector();
break;
......
......@@ -260,11 +260,12 @@ bool K3b::MetaWriter::determineUsedAppAndMode()
bool cdrecordBluRay = false;
bool cdrecordWodim = false;
bool growisofsBluRay = false;
if( k3bcore->externalBinManager()->binObject("cdrecord") ) {
cdrecordOnTheFly = k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "audio-stdin" );
cdrecordCdText = k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "cdtext" );
cdrecordBluRay = k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "blu-ray" );
cdrecordWodim = k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "wodim" );
const K3b::ExternalBin* cdrecordBin = k3bcore->externalBinManager()->binObject("cdrecord");
if( cdrecordBin ) {
cdrecordOnTheFly = cdrecordBin->hasFeature( "audio-stdin" );
cdrecordCdText = cdrecordBin->hasFeature( "cdtext" );
cdrecordBluRay = cdrecordBin->hasFeature( "blu-ray" );
cdrecordWodim = cdrecordBin->hasFeature( "wodim" );
}
if( k3bcore->externalBinManager()->binObject("growisofs") ) {
growisofsBluRay = k3bcore->externalBinManager()->binObject("growisofs")->hasFeature( "blu-ray" );
......@@ -418,7 +419,7 @@ bool K3b::MetaWriter::determineUsedAppAndMode()
//
if( !burnDevice()->dao() && d->usedWritingApp == K3b::WritingAppCdrecord ) {
if( !burnDevice()->supportsRawWriting() &&
( !less4Sec || k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "short-track-raw" ) ) )
( !less4Sec || (cdrecordBin && cdrecordBin->hasFeature( "short-track-raw" ) ) ) )
d->usedWritingMode = K3b::WritingModeRaw;
else
d->usedWritingMode = K3b::WritingModeTao;
......@@ -574,8 +575,8 @@ bool K3b::MetaWriter::setupCdrecordJob()
writer->addArgument( "-data" );
}
else {
if( k3bcore->externalBinManager()->binObject("cdrecord") &&
k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "xamix" ) )
const K3b::ExternalBin* cdrecordBin = k3bcore->externalBinManager()->binObject("cdrecord");
if( cdrecordBin && cdrecordBin->hasFeature( "xamix" ) )
writer->addArgument( "-xa" );
else
writer->addArgument( "-xa1" );
......
......@@ -144,7 +144,7 @@ void K3b::AudioJob::start()
d->copies = 1;
emit newTask( i18n("Preparing data") );
const K3b::ExternalBin* cdrecordBin = k3bcore->externalBinManager()->binObject("cdrecord");
//
// Check if all files exist
//
......@@ -231,7 +231,7 @@ void K3b::AudioJob::start()
//
if( !writer()->dao() && writingApp() == K3b::WritingAppCdrecord ) {
if(!writer()->supportsRawWriting() &&
( !d->less4Sec || k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "short-track-raw" ) ) )
( !d->less4Sec || ( cdrecordBin && cdrecordBin->hasFeature( "short-track-raw" ) ) ) )
m_usedWritingMode = K3b::WritingModeRaw;
else
m_usedWritingMode = K3b::WritingModeTao;
......@@ -251,9 +251,9 @@ void K3b::AudioJob::start()
bool cdrecordOnTheFly = false;
bool cdrecordCdText = false;
if( k3bcore->externalBinManager()->binObject("cdrecord") ) {
cdrecordOnTheFly = k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "audio-stdin" );
cdrecordCdText = k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "cdtext" );
if( cdrecordBin ) {
cdrecordOnTheFly = cdrecordBin->hasFeature( "audio-stdin" );
cdrecordCdText = cdrecordBin->hasFeature( "cdtext" );
}
// determine writing app
......@@ -286,7 +286,7 @@ void K3b::AudioJob::start()
d->useCdText ) {
if( !cdrecordCdText ) {
emit infoMessage( i18n("Cdrecord %1 does not support CD-Text writing.",
k3bcore->externalBinManager()->binObject("cdrecord")->version()), MessageError );
cdrecordBin->version()), MessageError );
d->useCdText = false;
}
else if( m_usedWritingMode == K3b::WritingModeTao ) {
......@@ -507,11 +507,11 @@ bool K3b::AudioJob::prepareWriter()
// add all the audio tracks
writer->addArgument( "-audio" );
const K3b::ExternalBin* cdrecordBin = k3bcore->externalBinManager()->binObject("cdrecord");
// we only need to pad in one case. cdrecord < 2.01.01a03 cannot handle shorttrack + raw
if( d->less4Sec ) {
if( m_usedWritingMode == K3b::WritingModeRaw &&
!k3bcore->externalBinManager()->binObject( "cdrecord" )->hasFeature( "short-track-raw" ) ) {
if( m_usedWritingMode == K3b::WritingModeRaw && ( cdrecordBin &&
!cdrecordBin->hasFeature( "short-track-raw" ) ) ) {
writer->addArgument( "-pad" );
}
else {
......
......@@ -689,13 +689,12 @@ bool K3b::DataJob::waitForBurnMedium()
{
// start with all media types supported by the writer
Device::MediaTypes m = d->doc->supportedMediaTypes() & d->doc->burner()->writeCapabilities();
// if everything goes wrong we are left with no possible media to request
if ( !m ) {
emit infoMessage( i18n( "Internal Error: No medium type fits. This project cannot be burned." ), MessageError );
return false;
}
const K3b::ExternalBin* cdrecordBin = k3bcore->externalBinManager()->binObject("cdrecord");
emit newSubTask( i18n("Waiting for a medium") );
Device::MediaType foundMedium = waitForMedium( d->doc->burner(),
usedMultiSessionMode() == K3b::DataDoc::CONTINUE ||
......@@ -802,7 +801,7 @@ bool K3b::DataJob::waitForBurnMedium()
// let's default to cdrecord for the time being (except for special cases below)
// but prefer growisofs for DVDs
if ( d->usedWritingApp == K3b::WritingAppAuto ) {
if (k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "wodim" ))
if (cdrecordBin && cdrecordBin->hasFeature( "wodim" ))
d->usedWritingApp = K3b::WritingAppGrowisofs;
else
d->usedWritingApp = K3b::WritingAppCdrecord;
......@@ -921,15 +920,14 @@ bool K3b::DataJob::waitForBurnMedium()
else if ( foundMedium & K3b::Device::MEDIA_BD_ALL ) {
d->usedWritingApp = writingApp();
if( d->usedWritingApp == K3b::WritingAppAuto ) {
if (k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "wodim" ))
if ( cdrecordBin && cdrecordBin->hasFeature( "wodim" ))
d->usedWritingApp = K3b::WritingAppGrowisofs;
else
d->usedWritingApp = K3b::WritingAppCdrecord;
}
if (d->usedWritingApp == K3b::WritingAppCdrecord &&
k3bcore->externalBinManager()->binObject("cdrecord") &&
!k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature("blu-ray")) {
cdrecordBin && !cdrecordBin->hasFeature("blu-ray")) {
d->usedWritingApp = K3b::WritingAppGrowisofs;
}
......@@ -1065,8 +1063,8 @@ bool K3b::DataJob::setupCdrecordJob()
if( d->usedDataMode == K3b::DataMode1 )
writer->addArgument( "-data" );
else {
if( k3bcore->externalBinManager()->binObject("cdrecord") &&
k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "xamix" ) )
const K3b::ExternalBin* cdrecordBin = k3bcore->externalBinManager()->binObject("cdrecord");
if( cdrecordBin && cdrecordBin->hasFeature( "xamix" ) )
writer->addArgument( "-xa" );
else
writer->addArgument( "-xa1" );
......
......@@ -148,8 +148,8 @@ void K3b::IsoImager::slotProcessExited( int exitCode, QProcess::ExitStatus exitS
// that contain one or more backslashes
// mkisofs 1.14 has the bug, 1.15a40 not
// TODO: find out the version that fixed the bug
if( m_containsFilesWithMultibleBackslashes &&
!k3bcore->externalBinManager()->binObject( "mkisofs" )->hasFeature( "backslashed_filenames" ) ) {
if( m_containsFilesWithMultibleBackslashes && d->mkisofsBin &&
!d->mkisofsBin->hasFeature( "backslashed_filenames" ) ) {
emit infoMessage( i18n("Due to a bug in mkisofs <= 1.15a40, K3b is unable to handle "
"filenames that contain more than one backslash:"), MessageError );
......@@ -605,7 +605,7 @@ bool K3b::IsoImager::addMkisofsParameters( bool printSize )
}
if ( filesGreaterThan4Gb ) {
if ( !d->mkisofsBin->hasFeature( "no-4gb-limit" ) ) {
if ( d->mkisofsBin && !d->mkisofsBin->hasFeature( "no-4gb-limit" ) ) {
emit infoMessage( i18n( "Found files bigger than 4 GB. K3b needs at least %1 to continue." ,
QString( "mkisofs >= 2.01.01a33 / genisoimage >= 1.1.4" ) ),
MessageError );
......@@ -614,7 +614,7 @@ bool K3b::IsoImager::addMkisofsParameters( bool printSize )
}
// in genisoimage 1.1.3 "they" silently introduced this awful parameter
if (filesGreaterThan2Gb && d->mkisofsBin->hasFeature("genisoimage") && d->mkisofsBin->version() >= K3b::Version(1, 1, 3)) {
if (filesGreaterThan2Gb && d->mkisofsBin && d->mkisofsBin->hasFeature("genisoimage") && d->mkisofsBin->version() >= K3b::Version(1, 1, 3)) {
*m_process << "-allow-limited-size";
emit infoMessage(i18n("Found files bigger than 2 GB. These files will be fully accessible."),
MessageInfo);
......@@ -710,9 +710,12 @@ bool K3b::IsoImager::addMkisofsParameters( bool printSize )
// additional parameters from config
const QStringList& params = k3bcore->externalBinManager()->binObject( "mkisofs" )->userParameters();
for( QStringList::const_iterator it = params.begin(); it != params.end(); ++it )
*m_process << *it;
if ( d->mkisofsBin) {
const QStringList& params = d->mkisofsBin->userParameters();
for( QStringList::const_iterator it = params.begin(); it != params.end(); ++it )
*m_process << *it;
}
return true;
}
......
......@@ -833,8 +833,8 @@ void K3b::MixedJob::addDataTrack( K3b::CdrecordWriter* writer )
{
// add data track
if( m_usedDataMode == K3b::DataMode2 ) {
if( k3bcore->externalBinManager()->binObject("cdrecord") &&
k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "xamix" ) )
const K3b::ExternalBin* cdrecordBin = k3bcore->externalBinManager()->binObject("cdrecord");
if( cdrecordBin && cdrecordBin->hasFeature( "xamix" ) )
writer->addArgument( "-xa" );
else
writer->addArgument( "-xa1" );
......@@ -1145,17 +1145,15 @@ void K3b::MixedJob::determineWritingMode()
else
m_usedDataMode = m_doc->dataDoc()->dataMode();
const K3b::ExternalBin* cdrecordBin = k3bcore->externalBinManager()->binObject("cdrecord");
// we try to use cdrecord if possible
bool cdrecordOnTheFly = false;
bool cdrecordCdText = false;
bool cdrecordUsable = false;
if( k3bcore->externalBinManager()->binObject("cdrecord") ) {
cdrecordOnTheFly =
k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "audio-stdin" );
cdrecordCdText =
k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "cdtext" );
if( cdrecordBin ) {
cdrecordOnTheFly = cdrecordBin->hasFeature( "audio-stdin" );
cdrecordCdText = cdrecordBin->hasFeature( "cdtext" );
cdrecordUsable =
!( !cdrecordOnTheFly && m_doc->onTheFly() ) &&
!( m_doc->audioDoc()->cdText() && !cdrecordCdText );
......@@ -1227,7 +1225,11 @@ void K3b::MixedJob::determineWritingMode()
if( m_doc->audioDoc()->cdText() ) {
if( !cdrecordCdText ) {
m_doc->audioDoc()->writeCdText( false );
emit infoMessage( i18n("Cdrecord %1 does not support CD-Text writing.",k3bcore->externalBinManager()->binObject("cdrecord")->version()), MessageError );
if (cdrecordBin) {
emit infoMessage( i18n("Cdrecord %1 does not support CD-Text writing.",cdrecordBin->version()), MessageError );
} else {
emit infoMessage( i18n("Cdrecord couldn't found on your system." ), MessageError );
}
}
else if( m_usedAudioWritingMode == K3b::WritingModeTao ) {
emit infoMessage( i18n("It is not possible to write CD-Text in TAO mode. Try DAO or RAW."), MessageWarning );
......
......@@ -172,6 +172,8 @@ void K3b::SystemProblemDialog::checkSystem(QWidget* parent, NotificationLevel le
if (!forceCheck && !readCheckSystemConfig())
return;
const K3b::ExternalBin* cdrecordBin = k3bcore->externalBinManager()->binObject("cdrecord");
if( k3bcore->deviceManager()->allDevices().isEmpty() ) {
problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
i18n("No optical drive found."),
......@@ -209,9 +211,9 @@ void K3b::SystemProblemDialog::checkSystem(QWidget* parent, NotificationLevel le
"cdrecord.") ) );
}
else {
if( k3bcore->externalBinManager()->binObject( "cdrecord" )->hasFeature( "outdated" ) ) {
if( cdrecordBin && cdrecordBin->hasFeature( "outdated" ) ) {
problems.append( K3b::SystemProblem( K3b::SystemProblem::NON_CRITICAL,
i18n("Used %1 version %2 is outdated",QString("cdrecord"),QString(k3bcore->externalBinManager()->binObject( "cdrecord" )->version())),
i18n("Used %1 version %2 is outdated",QString("cdrecord"),QString(cdrecordBin->version())),
i18n("Although K3b supports all cdrtools versions since "
"1.10 it is highly recommended to at least use "
"version 2.0."),
......@@ -226,9 +228,9 @@ void K3b::SystemProblemDialog::checkSystem(QWidget* parent, NotificationLevel le
//
// Kernel 2.6.16.something seems to introduce another problem which was apparently worked around in cdrecord 2.01.01a05
//
if( K3b::simpleKernelVersion() >= K3b::Version( 2, 6, 8 ) &&
k3bcore->externalBinManager()->binObject( "cdrecord" )->version() < K3b::Version( 2, 1, 1, "a05" ) && !k3bcore->externalBinManager()->binObject( "cdrecord" )->hasFeature( "wodim" ) ) {
if( k3bcore->externalBinManager()->binObject( "cdrecord" )->hasFeature( "suidroot" ) ) {
if( K3b::simpleKernelVersion() >= K3b::Version( 2, 6, 8 ) && cdrecordBin &&
cdrecordBin->version() < K3b::Version( 2, 1, 1, "a05" ) && !cdrecordBin->hasFeature( "wodim" ) ) {
if( cdrecordBin->hasFeature( "suidroot" ) ) {
showBinSettingsButton = true;
problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
i18n("%1 will be run with root privileges on kernel >= 2.6.8",QString("cdrecord <= 2.01.01a05")),
......@@ -423,12 +425,12 @@ void K3b::SystemProblemDialog::checkSystem(QWidget* parent, NotificationLevel le
if( k3bcore->externalBinManager()->foundBin( "cdrecord" ) ) {
if( !( k3bcore->externalBinManager()->binObject( "cdrecord" )->hasFeature( "hacked-atapi" ) &&
if( !( cdrecordBin->hasFeature( "hacked-atapi" ) &&
K3b::hackedAtapiSupport() ) &&
!( k3bcore->externalBinManager()->binObject( "cdrecord" )->hasFeature( "plain-atapi" ) &&
!( cdrecordBin->hasFeature( "plain-atapi" ) &&
K3b::plainAtapiSupport() ) ) {
problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
i18n("%1 %2 does not support ATAPI",QString("cdrecord"),k3bcore->externalBinManager()->binObject("cdrecord")->version()),
i18n("%1 %2 does not support ATAPI",QString("cdrecord"),cdrecordBin->version()),
i18n("The configured version of %1 does not "
"support writing to ATAPI devices without "
"SCSI emulation and there is at least one writer "
......
......@@ -210,9 +210,10 @@ void K3b::AudioBurnDialog::toggleAll()
bool cdrecordOnTheFly = false;
bool cdrecordCdText = false;
if ( k3bcore->externalBinManager()->binObject("cdrecord") ) {
cdrecordOnTheFly = k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "audio-stdin" );
cdrecordCdText = k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "cdtext" );
const K3b::ExternalBin* cdrecordBin = k3bcore->externalBinManager()->binObject("cdrecord");
if ( cdrecordBin ) {
cdrecordOnTheFly = cdrecordBin->hasFeature( "audio-stdin" );
cdrecordCdText = cdrecordBin->hasFeature( "cdtext" );
}
// cdrdao always knows onthefly and cdtext
......
......@@ -241,9 +241,10 @@ void K3b::MixedBurnDialog::toggleAll()
bool cdrecordOnTheFly = false;
bool cdrecordCdText = false;
if ( k3bcore->externalBinManager()->binObject("cdrecord") ) {
cdrecordOnTheFly = k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "audio-stdin" );
cdrecordCdText = k3bcore->externalBinManager()->binObject("cdrecord")->hasFeature( "cdtext" );
const K3b::ExternalBin* cdrecordBin = k3bcore->externalBinManager()->binObject("cdrecord");
if ( cdrecordBin ) {
cdrecordOnTheFly = cdrecordBin->hasFeature( "audio-stdin" );
cdrecordCdText = cdrecordBin->hasFeature( "cdtext" );
}
// cdrdao always knows onthefly and cdtext
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment