• 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
  • clizipplugin
clizipplugin/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 #include "cliplugin.h"
23 #include "kerfuffle/cliinterface.h"
24 #include "kerfuffle/kerfuffle_export.h"
25 
26 #include <KDebug>
27 
28 #include <QDateTime>
29 #include <QDir>
30 #include <QLatin1String>
31 #include <QRegExp>
32 #include <QString>
33 #include <QStringList>
34 
35 using namespace Kerfuffle;
36 
37 CliPlugin::CliPlugin(QObject *parent, const QVariantList & args)
38  : CliInterface(parent, args)
39  , m_status(Header)
40 {
41 }
42 
43 CliPlugin::~CliPlugin()
44 {
45 }
46 
47 // #208091: infozip applies special meanings to some characters, so we
48 // need to escape them with backslashes.see match.c in
49 // infozip's source code
50 QString CliPlugin::escapeFileName(const QString &fileName) const
51 {
52  const QString escapedCharacters(QLatin1String("[]*?^-\\!"));
53 
54  QString quoted;
55  const int len = fileName.length();
56  const QLatin1Char backslash('\\');
57  quoted.reserve(len * 2);
58 
59  for (int i = 0; i < len; ++i) {
60  if (escapedCharacters.contains(fileName.at(i))) {
61  quoted.append(backslash);
62  }
63 
64  quoted.append(fileName.at(i));
65  }
66 
67  return quoted;
68 }
69 
70 ParameterList CliPlugin::parameterList() const
71 {
72  static ParameterList p;
73 
74  if (p.isEmpty()) {
75  p[CaptureProgress] = false;
76  p[ListProgram] = QStringList() << QLatin1String( "zipinfo" );
77  p[ExtractProgram] = QStringList() << QLatin1String( "unzip" );
78  p[DeleteProgram] = p[AddProgram] = QStringList() << QLatin1String( "zip" );
79 
80  p[ListArgs] = QStringList() << QLatin1String( "-l" ) << QLatin1String( "-T" ) << QLatin1String( "$Archive" );
81  p[ExtractArgs] = QStringList() << QLatin1String( "$PreservePathSwitch" ) << QLatin1String( "$PasswordSwitch" ) << QLatin1String( "$Archive" ) << QLatin1String( "$Files" );
82  p[PreservePathSwitch] = QStringList() << QLatin1String( "" ) << QLatin1String( "-j" );
83  p[PasswordSwitch] = QStringList() << QLatin1String( "-P$Password" );
84 
85  p[DeleteArgs] = QStringList() << QLatin1String( "-d" ) << QLatin1String( "$Archive" ) << QLatin1String( "$Files" );
86 
87  p[FileExistsExpression] = QLatin1String( "^replace (.+)\\?" );
88  p[FileExistsInput] = QStringList()
89  << QLatin1String( "y" ) //overwrite
90  << QLatin1String( "n" ) //skip
91  << QLatin1String( "A" ) //overwrite all
92  << QLatin1String( "N" ) //autoskip
93  ;
94 
95  p[AddArgs] = QStringList() << QLatin1String( "-r" ) << QLatin1String( "$Archive" ) << QLatin1String( "$Files" );
96 
97  p[PasswordPromptPattern] = QLatin1String(" password: ");
98  p[WrongPasswordPatterns] = QStringList() << QLatin1String( "incorrect password" );
99  //p[ExtractionFailedPatterns] = QStringList() << "CRC failed";
100  }
101  return p;
102 }
103 
104 bool CliPlugin::readListLine(const QString &line)
105 {
106  static const QRegExp entryPattern(QLatin1String(
107  "^(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\d{8}).(\\d{6})\\s+(.+)$") );
108 
109  switch (m_status) {
110  case Header:
111  m_status = Entry;
112  break;
113  case Entry:
114  if (entryPattern.indexIn(line) != -1) {
115  ArchiveEntry e;
116  e[Permissions] = entryPattern.cap(1);
117 
118  // #280354: infozip may not show the right attributes for a given directory, so an entry
119  // ending with '/' is actually more reliable than 'd' bein in the attributes.
120  e[IsDirectory] = entryPattern.cap(10).endsWith(QLatin1Char('/'));
121 
122  e[Size] = entryPattern.cap(4).toInt();
123  QString status = entryPattern.cap(5);
124  if (status[0].isUpper()) {
125  e[IsPasswordProtected] = true;
126  }
127  e[CompressedSize] = entryPattern.cap(6).toInt();
128 
129  const QDateTime ts(QDate::fromString(entryPattern.cap(8), QLatin1String( "yyyyMMdd" )),
130  QTime::fromString(entryPattern.cap(9), QLatin1String( "hhmmss" )));
131  e[Timestamp] = ts;
132 
133  e[FileName] = e[InternalID] = entryPattern.cap(10);
134  emit entry(e);
135  }
136  break;
137  }
138 
139  return true;
140 }
141 
142 KERFUFFLE_EXPORT_PLUGIN(CliPlugin)
143 
cliinterface.h
QString::append
QString & append(QChar ch)
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
Kerfuffle::IsDirectory
The entry is a directory.
Definition: archive.h:72
CliPlugin::escapeFileName
virtual QString escapeFileName(const QString &fileName) const
Performs any additional escaping and processing on fileName before passing it to the underlying proce...
Definition: clirarplugin/cliplugin.cpp:54
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
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
QTime::fromString
QTime fromString(const QString &string, Qt::DateFormat format)
Kerfuffle::ReadOnlyArchiveInterface::entry
void entry(const ArchiveEntry &archiveEntry)
QRegExp
QDate::fromString
QDate fromString(const QString &string, Qt::DateFormat format)
Kerfuffle::ArchiveEntry
QHash< int, QVariant > ArchiveEntry
Definition: archive.h:78
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
QString::toInt
int toInt(bool *ok, int base) const
Kerfuffle::WrongPasswordPatterns
QStringList Default: empty A list of regexp patterns that will alert the user that the password was w...
Definition: cliinterface.h:201
Kerfuffle::ExtractArgs
QStringList The arguments that are passed to the program above for extracting the archive...
Definition: cliinterface.h:100
Kerfuffle::CliInterface::escapedCharacters
QString escapedCharacters()
Returns the list of characters which are preceded by a backslash when a file name in an archive is pa...
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
Kerfuffle::FileName
The entry's file name.
Definition: archive.h:59
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
QLatin1Char
Kerfuffle::CaptureProgress
Bool (default false) Will look for the %-sign in the stdout while working, in the form of (2%...
Definition: cliinterface.h:51
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
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::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
QString::length
int length() const
QString::reserve
void reserve(int size)
KERFUFFLE_EXPORT_PLUGIN
#define KERFUFFLE_EXPORT_PLUGIN(p)
Definition: kerfuffle_export.h:49
Kerfuffle::InternalID
The entry's ID for Ark's internal manipulation.
Definition: archive.h:60
QDateTime
Kerfuffle::ListProgram
QStringList The names to the program that will handle listing of this archive (eg "rar")...
Definition: cliinterface.h:67
cliplugin.h
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