From 3067884e745c79639ec82ae7520caf19c6963b66 Mon Sep 17 00:00:00 2001 From: Alexander Golubev Date: Mon, 28 Jul 2025 22:18:21 +0300 Subject: [PATCH] Fix discovery of sox binary Closes: https://mirror.git.trinitydesktop.org/gitea/TDE/k3b/issues/58 Signed-off-by: Alexander Golubev --- plugins/encoder/sox/k3bsoxencoder.cpp | 43 ++++++++++----------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/plugins/encoder/sox/k3bsoxencoder.cpp b/plugins/encoder/sox/k3bsoxencoder.cpp index 631a9b9..1cc7c3a 100644 --- a/plugins/encoder/sox/k3bsoxencoder.cpp +++ b/plugins/encoder/sox/k3bsoxencoder.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -65,47 +66,33 @@ class K3bSoxProgram : public K3bExternalProgram if( !TQFile::exists( path ) ) return false; - K3bExternalBin* bin = 0; - // probe version TDEProcess vp; K3bProcessOutputCollector out( &vp ); vp << path << "-h"; if( vp.start( TDEProcess::Block, TDEProcess::AllOutput ) ) { - int pos = out.output().find( "sox: SoX Version" ); - if ( pos < 0 ) - pos = out.output().find( "sox: SoX v" ); // newer sox versions - int endPos = out.output().find( "\n", pos ); - if( pos > 0 && endPos > 0 ) { - pos += 17; - bin = new K3bExternalBin( this ); + TQRegExp versionRe ("sox: +(SoX )?(Version |v)([^\\n]+)"); + // Should match: + // * sox: Version 12.2.3 + // * sox: SoX Version 12.18.1 + // * sox: SoX v14.0.0 + // * sox: SoX v14.4.0 + int pos = versionRe.search( out.output() ); + if( pos > 0 ) { + TQString version = versionRe.cap(3); + + K3bExternalBin* bin = new K3bExternalBin( this ); + bin->path = path; - bin->version = out.output().mid( pos, endPos-pos ); + bin->version = version; addBin( bin ); return true; } - else { - pos = out.output().find( "sox: Version" ); - endPos = out.output().find( "\n", pos ); - if( pos > 0 && endPos > 0 ) { - pos += 13; - bin = new K3bExternalBin( this ); - bin->path = path; - bin->version = out.output().mid( pos, endPos-pos ); - - addBin( bin ); - - return true; - } - else - return false; - } } - else - return false; + return false; } };