From 0123b079a9817ccd7bf4791db673b77414dad414 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Fri, 22 Apr 2016 22:20:18 +1000 Subject: Ark: added support for rar/unrar 5.x utilities. Both 4.x and 5.x are supported. Special thanks to Fabio Rossi for raising the issue and providing an initial patch. Signed-off-by: Michele Calgaro (cherry picked from commit 4e99fc39eb61da7ad6fedaa05df76101c6db571e) --- ark/rar.cpp | 114 ++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 81 insertions(+), 33 deletions(-) (limited to 'ark/rar.cpp') diff --git a/ark/rar.cpp b/ark/rar.cpp index 4d6a7ce..e47c78a 100644 --- a/ark/rar.cpp +++ b/ark/rar.cpp @@ -52,8 +52,10 @@ #include "arkutils.h" #include "filelistview.h" +#define VERSION_5 5 + RarArch::RarArch( ArkWidget *_gui, const TQString & _fileName ) - : Arch( _gui, _fileName ) + : Arch( _gui, _fileName ), m_isFirstLine(false), m_version(0) { // Check if rar is available bool have_rar = !TDEGlobal::dirs()->findExe( "rar" ).isNull(); @@ -82,11 +84,7 @@ RarArch::RarArch( ArkWidget *_gui, const TQString & _fileName ) setReadOnly( true ); } - - - m_headerString = "-------------------------------------------------------------------------------"; - - m_isFirstLine = true; + m_headerString = ""; } bool RarArch::processLine( const TQCString &line ) @@ -96,7 +94,33 @@ bool RarArch::processLine( const TQCString &line ) TQTextCodec *codec = TQTextCodec::codecForLocale(); unicode_line = codec->toUnicode( line ); - if ( m_isFirstLine ) + // Look for rar/unrar version first + if (!m_version) + { + if (line.left(3) == "RAR") + { + bool ok_flag = false; + short version = line.mid(4, 1).toShort(&ok_flag); + if (ok_flag) + { + m_version = version; + if (m_version < VERSION_5) + { + m_headerString = "-------------------------------------------------------------------------------"; + m_isFirstLine = true; + } + else + { + m_headerString = "----------- --------- -------- ----- ---------- ----- -------- ----"; + } + setHeaders(); + return true; + } + } + return false; + } + + if (m_version < VERSION_5 && m_isFirstLine) { m_entryFilename = TQString::fromLocal8Bit( line ); m_entryFilename.remove( 0, 1 ); @@ -105,37 +129,59 @@ bool RarArch::processLine( const TQCString &line ) } TQStringList list; - TQStringList l2 = TQStringList::split( ' ', line ); - if( l2[5].startsWith("d") ) + if (m_version < VERSION_5) { - m_isFirstLine = true; - return true; - } - - list << m_entryFilename; // filename - list << l2[ 0 ]; // size - list << l2[ 1 ]; // packed - list << l2[ 2 ]; // ratio - - TQStringList date = TQStringList::split( '-', l2[ 3 ] ); - list << ArkUtils::fixYear( date[ 2 ].latin1() ) + '-' + date[ 1 ] + '-' + date [ 0 ] + ' ' + l2[4]; // date - list << l2[ 5 ]; // attributes - list << l2[ 6 ]; // crc - list << l2[ 7 ]; // method - list << l2[ 8 ]; // Version - - m_gui->fileList()->addItem( list ); // send to GUI - - m_isFirstLine = true; + if( l2[5].startsWith("d") ) + { + // Folder item + m_isFirstLine = true; + return true; + } + + list << m_entryFilename; // filename + list << l2[ 0 ]; // size + list << l2[ 1 ]; // packed + list << l2[ 2 ]; // ratio + + TQStringList date = TQStringList::split( '-', l2[ 3 ] ); + list << ArkUtils::fixYear( date[ 2 ].latin1() ) + '-' + date[ 1 ] + '-' + date [ 0 ] + ' ' + l2[4]; // date + list << l2[ 5 ]; // attributes + list << l2[ 6 ]; // crc + list << l2[ 7 ]; // method + list << l2[ 8 ]; // Version + + m_gui->fileList()->addItem( list ); // send to GUI + + m_isFirstLine = true; + } + else + { + if( l2[0].startsWith("d") ) + { + // Folder item + return true; + } + + m_entryFilename = line.mid(line.find(l2[7])); + list << m_entryFilename; // filename + list << l2[ 1 ]; // size + list << l2[ 2 ]; // packed + list << l2[ 3 ]; // ratio + + TQStringList date = TQStringList::split('-', l2[4]); + list << l2[ 4 ] + " " + l2[ 5 ]; // date and time + list << l2[ 0 ]; // attributes + list << l2[ 6 ]; // crc + + m_gui->fileList()->addItem( list ); // send to GUI + } return true; } void RarArch::open() { - setHeaders(); - m_buffer = ""; m_header_removed = false; m_finished = false; @@ -174,9 +220,11 @@ void RarArch::setHeaders() list.append( TIMESTAMP_COLUMN ); list.append( PERMISSION_COLUMN ); list.append( CRC_COLUMN ); - list.append( METHOD_COLUMN ); - list.append( VERSION_COLUMN ); - + if (m_version < VERSION_5) + { + list.append( METHOD_COLUMN ); + list.append( VERSION_COLUMN ); + } emit headers( list ); } -- cgit v1.2.1