Permalink
Browse files

Wprowadzenie strategii dla obslugi programow archiwizujacych.

  • Loading branch information...
stolowski committed Aug 22, 2009
1 parent 0a83641 commit 4a2d2481415ce1652a6fa53ce4df40d110644fdf
View
2 header
@@ -1,7 +1,7 @@
/*
* This file is a part of QComicBook.
*
- * Copyright (C) 2005 Pawel Stolowski <yogin@linux.bydg.org>
+ * Copyright (C) 2005-2009 Pawel Stolowski <stolowski@gmail.com>
*
* QComicBook is free software; you can redestribute it and/or modify it
* under terms of GNU General Public License by Free Software Foundation.
@@ -0,0 +1,39 @@
+/*
+ * This file is a part of QComicBook.
+ *
+ * Copyright (C) 2005-2009 Pawel Stolowski <stolowski@gmail.com>
+ *
+ * QComicBook is free software; you can redestribute it and/or modify it
+ * under terms of GNU General Public License by Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY. See GPL for more details.
+ */
+
+#include "AceArchiverStrategy.h"
+#include "Utility.h"
+
+using namespace QComicBook;
+using Utility::which;
+
+AceArchiverStrategy::AceArchiverStrategy()
+ : ArchiverStrategy("ace", FileSignature(8, "\x2a\x41\x43\x45", 4))
+{
+}
+
+AceArchiverStrategy::~AceArchiverStrategy()
+{
+}
+
+void AceArchiverStrategy::configure()
+{
+ addExtension(".ace");
+ addExtension(".cba");
+
+ if (which("unace") != QString::null)
+ {
+ setExtractArguments("unace x -y -c- @F");
+ setListArguments("unace l -y -c- @F");
+ setSupported();
+ }
+}
View
@@ -0,0 +1,30 @@
+/*
+ * This file is a part of QComicBook.
+ *
+ * Copyright (C) 2005-2009 Pawel Stolowski <stolowski@gmail.com>
+ *
+ * QComicBook is free software; you can redestribute it and/or modify it
+ * under terms of GNU General Public License by Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY. See GPL for more details.
+ */
+
+#ifndef __ACE_ARCHIVER_STRATEGY_H
+#define __ACE_ARCHIVER_STRATEGY_H
+
+#include "ArchiverStrategy.h"
+
+namespace QComicBook
+{
+ class AceArchiverStrategy: public ArchiverStrategy
+ {
+ public:
+ AceArchiverStrategy();
+ virtual ~AceArchiverStrategy();
+
+ virtual void configure();
+ };
+}
+
+#endif
View
@@ -0,0 +1,101 @@
+/*
+ * This file is a part of QComicBook.
+ *
+ * Copyright (C) 2005-2009 Pawel Stolowski <stolowski@gmail.com>
+ *
+ * QComicBook is free software; you can redestribute it and/or modify it
+ * under terms of GNU General Public License by Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY. See GPL for more details.
+ */
+
+#include "ArchiverStrategy.h"
+#include <QFile>
+
+using namespace QComicBook;
+
+ArchiverStrategy::ArchiverStrategy(const QString &name, const FileSignature &sig)
+ : name(name)
+ , supported(false)
+ , signature(sig)
+{
+}
+
+ArchiverStrategy::~ArchiverStrategy()
+{
+}
+
+void ArchiverStrategy::setSupported(bool f)
+{
+ supported = f;
+}
+
+void ArchiverStrategy::addExtension(const QString &ext)
+{
+ if (extensions.indexOf(ext) < 0)
+ {
+ extensions.append(ext);
+ }
+}
+
+void ArchiverStrategy::setFileMagic(const FileSignature &sig)
+{
+ signature = sig;
+}
+
+QStringList ArchiverStrategy::getArguments(const QStringList & inargs, const QString &filename)
+{
+ QStringList args;
+ foreach (QString s, inargs)
+ {
+ if (s == "@F")
+ {
+ args << filename;
+ }
+ else
+ {
+ args << s;
+ }
+ }
+ return args;
+}
+
+void ArchiverStrategy::setExtractArguments(const QString &command)
+{
+ extractArgs = command.split(" ", QString::SkipEmptyParts);
+}
+
+void ArchiverStrategy::setListArguments(const QString &command)
+{
+ listArgs = command.split(" ", QString::SkipEmptyParts);
+}
+
+QStringList ArchiverStrategy::getExtractArguments(const QString &filename) const
+{
+ return getArguments(extractArgs, filename);
+}
+
+QStringList ArchiverStrategy::getListArguments(const QString &filename) const
+{
+ return getArguments(listArgs, filename);
+}
+
+QStringList ArchiverStrategy::getExtensions() const
+{
+ return extensions;
+}
+
+bool ArchiverStrategy::canOpen(QFile *f) const
+{
+ return signature.matches(f);
+}
+
+bool ArchiverStrategy::canOpen(const QString &filename) const
+{
+ QFile file(filename);
+ if (file.open(QIODevice::ReadOnly))
+ {
+ return canOpen(&file);
+ }
+}
View
@@ -0,0 +1,43 @@
+#ifndef __ARCHIVER_STRATEGY
+#define __ARCHIVER_STRATEGY
+
+#include <QString>
+#include <QStringList>
+#include "FileSignature.h"
+
+class QFile;
+
+namespace QComicBook
+{
+ class ArchiverStrategy
+ {
+ public:
+ ArchiverStrategy(const QString &name, const FileSignature &sig);
+ virtual ~ArchiverStrategy();
+
+ virtual bool canOpen(QFile *f) const;
+ virtual bool canOpen(const QString &filename) const;
+ QStringList getExtractArguments(const QString &filename) const;
+ QStringList getListArguments(const QString &filename) const;
+ QStringList getExtensions() const;
+ virtual void configure() = 0;
+
+ protected:
+ static QStringList getArguments(const QStringList & inargs, const QString &filename);
+ void setFileMagic(const FileSignature &sig);
+ void setExtractArguments(const QString &command);
+ void setListArguments(const QString &command);
+ void setSupported(bool f=true);
+ void addExtension(const QString &ext);
+
+ private:
+ FileSignature signature;
+ QString name;
+ bool supported;
+ QStringList extensions;
+ QStringList extractArgs;
+ QStringList listArgs;
+ };
+}
+
+#endif
View
@@ -1,5 +1,14 @@
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR})
-SET(qcomicbook_src AboutDialog.cpp Bookmark.cpp BookmarkManager.cpp
+SET(qcomicbook_src
+ ArchiverStrategy.cpp
+ AceArchiverStrategy.cpp
+ P7zipArchiverStrategy.cpp
+ RarArchiverStrategy.cpp
+ TargzArchiverStrategy.cpp
+ Tarbz2ArchiverStrategy.cpp
+ ZipArchiverStrategy.cpp
+ FileSignature.cpp
+ AboutDialog.cpp Bookmark.cpp BookmarkManager.cpp
Bookmarks.cpp ComicBookCfgDialog.cpp ComicBookInfo.cpp ComicBookSettings.cpp ComicMainWindow.cpp DirReader.cpp
History.cpp IconViewThumbnail.cpp ImgArchiver.cpp ImgArchiveSink.cpp
ImgCache.cpp
View
@@ -0,0 +1,63 @@
+/*
+ * This file is a part of QComicBook.
+ *
+ * Copyright (C) 2005-2009 Pawel Stolowski <stolowski@gmail.com>
+ *
+ * QComicBook is free software; you can redestribute it and/or modify it
+ * under terms of GNU General Public License by Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY. See GPL for more details.
+ */
+
+#include "FileSignature.h"
+
+using namespace QComicBook;
+
+FileSignature::FileSignature(unsigned int offset, const char *pattern, unsigned int len)
+ : offset(offset)
+{
+ this->pattern = QByteArray(pattern, len);
+}
+
+FileSignature::FileSignature()
+ : offset(0)
+{
+}
+
+FileSignature::FileSignature(const FileSignature &sig)
+{
+ pattern = sig.pattern;
+ offset = sig.offset;
+}
+
+FileSignature::~FileSignature()
+{
+}
+
+bool FileSignature::matches(QFile *file) const
+{
+ if (pattern.size() > 0 && file->seek(offset))
+ {
+ for (int i=0; i<pattern.size(); i++)
+ {
+ char c;
+ if (!file->getChar(&c))
+ return false;
+ if (c != pattern.at(i))
+ return false;
+ }
+ return true;
+ }
+ return false;
+}
+
+FileSignature& FileSignature::operator =(const FileSignature &sig)
+{
+ if (this != &sig)
+ {
+ pattern = sig.pattern;
+ offset = sig.offset;
+ }
+ return *this;
+}
View
@@ -0,0 +1,38 @@
+/*
+ * This file is a part of QComicBook.
+ *
+ * Copyright (C) 2005-2009 Pawel Stolowski <stolowski@gmail.com>
+ *
+ * QComicBook is free software; you can redestribute it and/or modify it
+ * under terms of GNU General Public License by Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY. See GPL for more details.
+ */
+
+#ifndef __FILE_SIGNATURE_H
+#define __FILE_SIGNATURE_H
+
+#include <QFile>
+#include <QByteArray>
+
+namespace QComicBook
+{
+ class FileSignature
+ {
+ public:
+ FileSignature(unsigned int offset, const char *pattern, unsigned int len);
+ FileSignature();
+ FileSignature(const FileSignature &sig);
+ ~FileSignature();
+
+ bool matches(QFile *file) const;
+ FileSignature& operator =(const FileSignature &sig);
+
+ private:
+ unsigned int offset;
+ QByteArray pattern;
+ };
+}
+
+#endif
@@ -0,0 +1,38 @@
+/*
+ * This file is a part of QComicBook.
+ *
+ * Copyright (C) 2005-2009 Pawel Stolowski <stolowski@gmail.com>
+ *
+ * QComicBook is free software; you can redestribute it and/or modify it
+ * under terms of GNU General Public License by Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY. See GPL for more details.
+ */
+
+#include "P7zipArchiverStrategy.h"
+#include "Utility.h"
+
+using namespace QComicBook;
+using Utility::which;
+
+P7zipArchiverStrategy::P7zipArchiverStrategy()
+ : ArchiverStrategy("p7zip", FileSignature())
+{
+}
+
+P7zipArchiverStrategy::~P7zipArchiverStrategy()
+{
+}
+
+void P7zipArchiverStrategy::configure()
+{
+ addExtension(".7z");
+
+ if (which("7z") != QString::null)
+ {
+ setExtractArguments("7z x @F");
+ setListArguments("7z l @F");
+ setSupported();
+ }
+}
Oops, something went wrong.

0 comments on commit 4a2d248

Please sign in to comment.