Commit 6d8bd57b authored by Christoph Feck's avatar Christoph Feck
Browse files

Fix unrar 5 support

BUG: 319303
FIXED-IN: 4.11.2
REVIEW: 111625
parent 66263e47
......@@ -53,7 +53,8 @@ namespace Kerfuffle
{
CliInterface::CliInterface(QObject *parent, const QVariantList & args)
: ReadWriteArchiveInterface(parent, args),
m_process(0)
m_process(0),
m_listEmptyLines(false)
{
//because this interface uses the event loop
setWaitForFinishedSignal(true);
......@@ -78,6 +79,11 @@ CliInterface::~CliInterface()
Q_ASSERT(!m_process);
}
void CliInterface::setListEmptyLines(bool emptyLines)
{
m_listEmptyLines = emptyLines;
}
bool CliInterface::list()
{
cacheParameterList();
......@@ -476,7 +482,7 @@ void CliInterface::readStdout(bool handleAll)
}
foreach(const QByteArray& line, lines) {
if (!line.isEmpty()) {
if (!line.isEmpty() || (m_listEmptyLines && m_operationMode == List)) {
handleLine(QString::fromLocal8Bit(line));
}
}
......
......@@ -263,6 +263,13 @@ public:
*/
void setEscapedCharacters(const QString& characters);
/**
* Sets if the listing should include empty lines.
*
* The default value is false.
*/
void setListEmptyLines(bool emptyLines);
private:
void substituteListVariables(QStringList& params);
......@@ -330,6 +337,7 @@ private:
ParameterList m_param;
QVariantList m_removedFiles;
bool m_listEmptyLines;
private slots:
void readStdout(bool handleAll = false);
......
......@@ -39,6 +39,7 @@ CliPlugin::CliPlugin(QObject *parent, const QVariantList& args)
, m_isPasswordProtected(false)
, m_remainingIgnoredSubHeaderLines(0)
, m_isUnrarFree(false)
, m_isUnrarVersion5(false)
{
}
......@@ -107,9 +108,86 @@ bool CliPlugin::readListLine(const QString &line)
static const QLatin1String columnDescription1String(" Size Packed Ratio Date Time Attr CRC Meth Ver");
static const QLatin1String columnDescription2String(" Host OS Solid Old"); // Only present in unrar-nonfree
if (m_isUnrarVersion5) {
int colonPos = line.indexOf(QLatin1Char(':'));
if (colonPos == -1) {
if (m_entryFileName.isEmpty()) {
return true;
}
ArchiveEntry e;
QString compressionRatio = m_entryDetails.value(QLatin1String("ratio"));
compressionRatio.chop(1); // Remove the '%'
QString time = m_entryDetails.value(QLatin1String("mtime"));
// FIXME unrar 5 beta 8 seems to lack the seconds, or the trailing ,000 is not the milliseconds
QDateTime ts = QDateTime::fromString(time, QLatin1String("yyyy-MM-dd HH:mm,zzz"));
bool isDirectory = m_entryDetails.value(QLatin1String("type")) == QLatin1String("Directory");
if (isDirectory && !m_entryFileName.endsWith(QLatin1Char( '/' ))) {
m_entryFileName += QLatin1Char( '/' );
}
QString compression = m_entryDetails.value(QLatin1String("compression"));
int optionPos = compression.indexOf(QLatin1Char('-'));
if (optionPos != -1) {
e[Method] = compression.mid(optionPos);
e[Version] = compression.left(optionPos).trimmed();
} else {
// no method specified
e[Method].clear();
e[Version] = compression;
}
m_isPasswordProtected = m_entryDetails.value(QLatin1String("flags")).contains(QLatin1String("encrypted"));
e[FileName] = m_entryFileName;
e[InternalID] = m_entryFileName;
e[Size] = m_entryDetails.value(QLatin1String("size"));
e[CompressedSize] = m_entryDetails.value(QLatin1String("packed size"));
e[Ratio] = compressionRatio;
e[Timestamp] = ts;
e[IsDirectory] = isDirectory;
e[Permissions] = m_entryDetails.value(QLatin1String("attributes"));
e[CRC] = m_entryDetails.value(QLatin1String("crc32"));
e[IsPasswordProtected] = m_isPasswordProtected;
kDebug() << "Added entry: " << e;
emit entry(e);
m_entryFileName.clear();
return true;
}
QString key = line.left(colonPos).trimmed().toLower();
QString value = line.mid(colonPos + 2);
if (key == QLatin1String("name")) {
m_entryFileName = value;
m_entryDetails.clear();
return true;
}
// in multivolume archives, the split CRC32 is denoted specially
if (key == QLatin1String("pack-crc32")) {
key = key.mid(5);
}
m_entryDetails.insert(key, value);
return true;
}
switch (m_parseState)
{
case ParseStateColumnDescription1:
if (line.startsWith(QLatin1String("Details:"))) {
m_isUnrarVersion5 = true;
setListEmptyLines(true);
// no previously detected entry
m_entryFileName.clear();
}
if (line.startsWith(columnDescription1String)) {
m_parseState = ParseStateColumnDescription2;
}
......
......@@ -51,12 +51,14 @@ private:
} m_parseState;
QString m_entryFileName;
QHash<QString, QString> m_entryDetails;
bool m_isPasswordProtected;
int m_remainingIgnoredSubHeaderLines;
bool m_isUnrarFree;
bool m_isUnrarVersion5;
};
#endif // CLIPLUGIN_H
Markdown is supported
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