Ark: added support for rar/unrar 5.x utilities. Both 4.x and 5.x are supported.

Special thanks to Fabio Rossi <rossi.f@inwind.it> for raising the issue and providing an initial patch.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit 4e99fc39eb)
pull/30/head
Michele Calgaro 8 years ago
parent 5699abf077
commit 0123b079a9

@ -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 );
}

@ -65,6 +65,7 @@ class RarArch : public Arch
* Therefore, the variables below are needed.
*/
bool m_isFirstLine;
short m_version;
TQString m_entryFilename;
};

Loading…
Cancel
Save