• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

ark

  • sources
  • kde-4.14
  • kdeutils
  • ark
  • plugins
  • cli7zplugin
cli7zplugin/cliplugin.cpp
Go to the documentation of this file.
1 /*
2  * ark -- archiver for the KDE project
3  *
4  * Copyright (C) 2009 Harald Hvaal <haraldhv@stud.ntnu.no>
5  * Copyright (C) 2009-2011 Raphael Kubo da Costa <rakuco@FreeBSD.org>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "cliplugin.h"
24 #include "kerfuffle/cliinterface.h"
25 #include "kerfuffle/kerfuffle_export.h"
26 
27 #include <QDateTime>
28 #include <QDir>
29 #include <QLatin1String>
30 #include <QString>
31 
32 #include <KDebug>
33 
34 using namespace Kerfuffle;
35 
36 CliPlugin::CliPlugin(QObject *parent, const QVariantList & args)
37  : CliInterface(parent, args)
38  , m_archiveType(ArchiveType7z)
39  , m_state(ReadStateHeader)
40 {
41 }
42 
43 CliPlugin::~CliPlugin()
44 {
45 }
46 
47 ParameterList CliPlugin::parameterList() const
48 {
49  static ParameterList p;
50 
51  if (p.isEmpty()) {
52  //p[CaptureProgress] = true;
53  p[ListProgram] = p[ExtractProgram] = p[DeleteProgram] = p[AddProgram] = QStringList() << QLatin1String( "7z" ) << QLatin1String( "7za" ) << QLatin1String( "7zr" );
54 
55  p[ListArgs] = QStringList() << QLatin1String( "l" ) << QLatin1String( "-slt" ) << QLatin1String( "$Archive" );
56  p[ExtractArgs] = QStringList() << QLatin1String( "$PreservePathSwitch" ) << QLatin1String( "$PasswordSwitch" ) << QLatin1String( "$Archive" ) << QLatin1String( "$Files" );
57  p[PreservePathSwitch] = QStringList() << QLatin1String( "x" ) << QLatin1String( "e" );
58  p[PasswordSwitch] = QStringList() << QLatin1String( "-p$Password" );
59  p[FileExistsExpression] = QLatin1String( "already exists. Overwrite with" );
60  p[WrongPasswordPatterns] = QStringList() << QLatin1String( "Wrong password" );
61  p[AddArgs] = QStringList() << QLatin1String( "a" ) << QLatin1String( "$Archive" ) << QLatin1String( "$Files" );
62  p[DeleteArgs] = QStringList() << QLatin1String( "d" ) << QLatin1String( "$Archive" ) << QLatin1String( "$Files" );
63 
64  p[FileExistsInput] = QStringList()
65  << QLatin1String( "Y" ) //overwrite
66  << QLatin1String( "N" )//skip
67  << QLatin1String( "A" ) //overwrite all
68  << QLatin1String( "S" ) //autoskip
69  << QLatin1String( "Q" ) //cancel
70  ;
71 
72  p[PasswordPromptPattern] = QLatin1String("Enter password \\(will not be echoed\\) :");
73  }
74 
75  return p;
76 }
77 
78 bool CliPlugin::readListLine(const QString& line)
79 {
80  static const QLatin1String archiveInfoDelimiter1("--"); // 7z 9.13+
81  static const QLatin1String archiveInfoDelimiter2("----"); // 7z 9.04
82  static const QLatin1String entryInfoDelimiter("----------");
83 
84  switch (m_state) {
85  case ReadStateHeader:
86  if (line.startsWith(QLatin1String("Listing archive:"))) {
87  kDebug() << "Archive name: "
88  << line.right(line.size() - 16).trimmed();
89  } else if ((line == archiveInfoDelimiter1) ||
90  (line == archiveInfoDelimiter2)) {
91  m_state = ReadStateArchiveInformation;
92  } else if (line.contains(QLatin1String( "Error:" ))) {
93  kDebug() << line.mid(6);
94  }
95  break;
96 
97  case ReadStateArchiveInformation:
98  if (line == entryInfoDelimiter) {
99  m_state = ReadStateEntryInformation;
100  } else if (line.startsWith(QLatin1String("Type ="))) {
101  const QString type = line.mid(7).trimmed();
102  kDebug() << "Archive type: " << type;
103 
104  if (type == QLatin1String("7z")) {
105  m_archiveType = ArchiveType7z;
106  } else if (type == QLatin1String("BZip2")) {
107  m_archiveType = ArchiveTypeBZip2;
108  } else if (type == QLatin1String("GZip")) {
109  m_archiveType = ArchiveTypeGZip;
110  } else if (type == QLatin1String("Tar")) {
111  m_archiveType = ArchiveTypeTar;
112  } else if (type == QLatin1String("Zip")) {
113  m_archiveType = ArchiveTypeZip;
114  } else {
115  // Should not happen
116  kWarning() << "Unsupported archive type";
117  return false;
118  }
119  }
120 
121  break;
122 
123  case ReadStateEntryInformation:
124  if (line.startsWith(QLatin1String("Path ="))) {
125  const QString entryFilename =
126  QDir::fromNativeSeparators(line.mid(6).trimmed());
127  m_currentArchiveEntry.clear();
128  m_currentArchiveEntry[FileName] = entryFilename;
129  m_currentArchiveEntry[InternalID] = entryFilename;
130  } else if (line.startsWith(QLatin1String("Size = "))) {
131  m_currentArchiveEntry[ Size ] = line.mid(7).trimmed();
132  } else if (line.startsWith(QLatin1String("Packed Size = "))) {
133  // #236696: 7z files only show a single Packed Size value
134  // corresponding to the whole archive.
135  if (m_archiveType != ArchiveType7z) {
136  m_currentArchiveEntry[CompressedSize] = line.mid(14).trimmed();
137  }
138  } else if (line.startsWith(QLatin1String("Modified = "))) {
139  m_currentArchiveEntry[ Timestamp ] =
140  QDateTime::fromString(line.mid(11).trimmed(),
141  QLatin1String( "yyyy-MM-dd hh:mm:ss" ));
142  } else if (line.startsWith(QLatin1String("Attributes = "))) {
143  const QString attributes = line.mid(13).trimmed();
144 
145  const bool isDirectory = attributes.startsWith(QLatin1Char( 'D' ));
146  m_currentArchiveEntry[ IsDirectory ] = isDirectory;
147  if (isDirectory) {
148  const QString directoryName =
149  m_currentArchiveEntry[FileName].toString();
150  if (!directoryName.endsWith(QLatin1Char( '/' ))) {
151  const bool isPasswordProtected = (line.at(12) == QLatin1Char( '+' ));
152  m_currentArchiveEntry[FileName] =
153  m_currentArchiveEntry[InternalID] = QString(directoryName + QLatin1Char( '/' ));
154  m_currentArchiveEntry[ IsPasswordProtected ] =
155  isPasswordProtected;
156  }
157  }
158 
159  m_currentArchiveEntry[ Permissions ] = attributes.mid(1);
160  } else if (line.startsWith(QLatin1String("CRC = "))) {
161  m_currentArchiveEntry[ CRC ] = line.mid(6).trimmed();
162  } else if (line.startsWith(QLatin1String("Method = "))) {
163  m_currentArchiveEntry[ Method ] = line.mid(9).trimmed();
164  } else if (line.startsWith(QLatin1String("Encrypted = ")) &&
165  line.size() >= 13) {
166  m_currentArchiveEntry[ IsPasswordProtected ] = (line.at(12) == QLatin1Char( '+' ));
167  } else if (line.startsWith(QLatin1String("Block = "))) {
168  if (m_currentArchiveEntry.contains(FileName)) {
169  emit entry(m_currentArchiveEntry);
170  }
171  }
172  break;
173  }
174 
175  return true;
176 }
177 
178 KERFUFFLE_EXPORT_PLUGIN(CliPlugin)
179 
180 #include "cliplugin.moc"
cliinterface.h
Kerfuffle::ExtractProgram
QStringList The names to the program that will handle extracting of this archive (eg "rar")...
Definition: cliinterface.h:84
Kerfuffle::IsPasswordProtected
The entry is password-protected.
Definition: archive.h:74
QDir::fromNativeSeparators
QString fromNativeSeparators(const QString &pathName)
Kerfuffle::IsDirectory
The entry is a directory.
Definition: archive.h:72
Kerfuffle::AddProgram
QStringList The names to the program that will handle adding in this archive format (eg "rar")...
Definition: cliinterface.h:210
kerfuffle_export.h
Kerfuffle::CliInterface
Definition: cliinterface.h:224
CliPlugin
Definition: cli7zplugin/cliplugin.h:29
Kerfuffle::ListArgs
QStringList The arguments that are passed to the program above for listing the archive.
Definition: cliinterface.h:75
QString::size
int size() const
Kerfuffle::PasswordPromptPattern
QString Default: empty A regexp pattern that matches the program's password prompt.
Definition: cliinterface.h:58
Kerfuffle::CompressedSize
The compressed size for the entry.
Definition: archive.h:65
Kerfuffle::ReadOnlyArchiveInterface::entry
void entry(const ArchiveEntry &archiveEntry)
cliplugin.h
CliPlugin::parameterList
virtual Kerfuffle::ParameterList parameterList() const
Definition: cli7zplugin/cliplugin.cpp:47
Kerfuffle::PreservePathSwitch
QStringList This should be a qstringlist with either two elements.
Definition: cliinterface.h:122
QHash
QObject
Kerfuffle::WrongPasswordPatterns
QStringList Default: empty A list of regexp patterns that will alert the user that the password was w...
Definition: cliinterface.h:201
QString::trimmed
QString trimmed() const
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
Kerfuffle::ExtractArgs
QStringList The arguments that are passed to the program above for extracting the archive...
Definition: cliinterface.h:100
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
Kerfuffle::FileExistsExpression
QString This is a regexp, defining how to recognize a "File already exists" prompt when extracting...
Definition: cliinterface.h:148
CliPlugin::CliPlugin
CliPlugin(QObject *parent, const QVariantList &args)
Definition: cli7zplugin/cliplugin.cpp:36
QString
Kerfuffle::Timestamp
The timestamp for the current entry.
Definition: archive.h:71
CliPlugin::~CliPlugin
virtual ~CliPlugin()
Definition: cli7zplugin/cliplugin.cpp:43
QStringList
QString::right
QString right(int n) const
Kerfuffle::FileName
The entry's file name.
Definition: archive.h:59
QHash::clear
void clear()
Kerfuffle::CRC
The entry's CRC.
Definition: archive.h:68
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
QLatin1Char
QDateTime::fromString
QDateTime fromString(const QString &string, Qt::DateFormat format)
Kerfuffle::Permissions
The entry's permissions.
Definition: archive.h:61
Kerfuffle::DeleteArgs
QStringList The arguments that are passed to the program above for deleting from the archive...
Definition: cliinterface.h:187
Kerfuffle::PasswordSwitch
QStringList (default empty) The format of the root node switch.
Definition: cliinterface.h:141
QString::mid
QString mid(int position, int n) const
Kerfuffle::DeleteProgram
QStringList The names to the program that will handle deleting of elements in this archive format (eg...
Definition: cliinterface.h:178
QLatin1String
QHash::isEmpty
bool isEmpty() const
Kerfuffle::FileExistsInput
QStringList The various responses that can be supplied as a response to the "file exists" prompt...
Definition: cliinterface.h:169
Kerfuffle::Method
The compression method used on the entry.
Definition: archive.h:69
Kerfuffle::Size
The entry's original size.
Definition: archive.h:64
Kerfuffle::AddArgs
QStringList The arguments that are passed to the program above for adding to the archive.
Definition: cliinterface.h:219
QString::at
const QChar at(int position) const
CliPlugin::readListLine
virtual bool readListLine(const QString &line)
Definition: cli7zplugin/cliplugin.cpp:78
KERFUFFLE_EXPORT_PLUGIN
#define KERFUFFLE_EXPORT_PLUGIN(p)
Definition: kerfuffle_export.h:49
QHash::contains
bool contains(const Key &key) const
Kerfuffle::InternalID
The entry's ID for Ark's internal manipulation.
Definition: archive.h:60
Kerfuffle::ListProgram
QStringList The names to the program that will handle listing of this archive (eg "rar")...
Definition: cliinterface.h:67
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:37 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ark

Skip menu "ark"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal