2012-02-20 21:47:14 +00:00
|
|
|
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
2009-10-25 22:49:24 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#ifndef __INDEXEDZIP_HH_INCLUDED__
|
|
|
|
#define __INDEXEDZIP_HH_INCLUDED__
|
|
|
|
|
|
|
|
#include "btreeidx.hh"
|
|
|
|
#include <QFile>
|
2017-04-24 14:42:01 +00:00
|
|
|
#include "zipfile.hh"
|
2009-10-25 22:49:24 +00:00
|
|
|
|
|
|
|
/// Allows using a btree index to read zip files. Basically built on top of
|
|
|
|
/// the base dictionary infrastructure adapted for zips.
|
|
|
|
class IndexedZip: public BtreeIndexing::BtreeIndex
|
|
|
|
{
|
2017-04-24 14:42:01 +00:00
|
|
|
ZipFile::SplitZipFile zip;
|
2009-10-25 22:49:24 +00:00
|
|
|
bool zipIsOpen;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
IndexedZip():
|
|
|
|
zipIsOpen( false )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Opens the index. The values are those previously returned by buildIndex().
|
|
|
|
using BtreeIndexing::BtreeIndex::openIndex;
|
|
|
|
|
|
|
|
/// Opens the zip file itself. Returns true if succeeded, false otherwise.
|
|
|
|
bool openZipFile( QString const & );
|
|
|
|
|
|
|
|
/// Returns true if the zip is open, false otherwise.
|
|
|
|
bool isOpen() const
|
|
|
|
{
|
|
|
|
return zipIsOpen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Checks whether the given file exists in the zip file or not.
|
|
|
|
/// Note that this function is thread-safe, since it does not access zip file.
|
|
|
|
bool hasFile( gd::wstring const & name );
|
|
|
|
|
|
|
|
/// Attempts loading the given file into the given vector. Returns true on
|
|
|
|
/// success, false otherwise.
|
|
|
|
bool loadFile( gd::wstring const & name, std::vector< char > & );
|
2012-09-28 12:39:52 +00:00
|
|
|
bool loadFile( uint32_t offset, std::vector< char > & );
|
2012-01-30 13:13:58 +00:00
|
|
|
|
|
|
|
/// Index compressed files in zip file
|
2014-10-10 12:52:22 +00:00
|
|
|
bool indexFile( BtreeIndexing::IndexedWords & zipFileNames, quint32 * filesCount = 0 );
|
2009-10-25 22:49:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|