Commit 93b9fdd3 authored by Halla Rempt's avatar Halla Rempt
Browse files

BUG:350498 Work around encoding issues in kzip

This adds an option to KoStore to retrieve all top-level directories.
If we cannot open the directory specified in the maindoc.xml file,
open the first one...
parent 28f04a75
......@@ -94,8 +94,16 @@ KisKraLoadVisitor::KisKraLoadVisitor(KisImageWSP image,
m_name.remove(0, 1);
}
if (!m_store->enterDirectory(m_name)) {
dbgFile << "Could not enter directory" << m_name << ", probably an old-style file with 'part' added.";
m_name = expandEncodedDirectory(m_name);
QStringList directories = m_store->directoryList();
qDebug() << directories;
if (directories.size() > 0) {
dbgFile << "Could not locate the directory, maybe some encoding issue? Grab the first directory, that'll be the image one." << m_name << directories;
m_name = directories.first();
}
else {
dbgFile << "Could not enter directory" << m_name << ", probably an old-style file with 'part' added.";
m_name = expandEncodedDirectory(m_name);
}
}
else {
m_store->popDirectory();
......
......@@ -481,6 +481,19 @@ bool KoEncryptedStore::isEncrypted()
return true;
}
QStringList KoEncryptedStore::directoryList() const
{
QStringList retval;
const KArchiveDirectory *directory = m_pZip->directory();
foreach(const QString &name, directory->entries()) {
const KArchiveEntry* fileArchiveEntry = m_pZip->directory()->entry(name);
if (fileArchiveEntry->isDirectory()) {
retval << name;
}
}
return retval;
}
bool KoEncryptedStore::isToBeEncrypted(const QString& name)
{
return !(name == META_FILE || name == MANIFEST_FILE || name == THUMBNAIL_FILE);
......
......@@ -65,6 +65,8 @@ public:
*/
virtual bool isEncrypted();
virtual QStringList directoryList() const;
protected:
void init(const QByteArray &appIdentification);
......
......@@ -603,3 +603,8 @@ KoStore::Mode KoStore::mode() const
Q_D(const KoStore);
return d->mode;
}
QStringList KoStore::directoryList() const
{
return QStringList();
}
......@@ -182,6 +182,14 @@ public:
*/
Mode mode() const;
/**
* If an store is opened for reading, then the directories
* of the store can be accessed via this function.
*
* @return a stringlist with all directories found
*/
virtual QStringList directoryList() const;
/**
* Enters one or multiple directories. In Read mode this actually
* checks whether the specified directories exist and returns false
......
......@@ -97,6 +97,19 @@ KoTarStore::~KoTarStore()
}
}
QStringList KoTarStore::directoryList() const
{
QStringList retval;
const KArchiveDirectory *directory = m_pTar->directory();
foreach(const QString &name, directory->entries()) {
const KArchiveEntry* fileArchiveEntry = m_pTar->directory()->entry(name);
if (fileArchiveEntry->isDirectory()) {
retval << name;
}
}
return retval;
}
QByteArray KoTarStore::completeMagic(const QByteArray& appMimetype)
{
kDebug(30002) << "QCString KoTarStore::completeMagic( const QCString& appMimetype )********************";
......
......@@ -42,6 +42,9 @@ public:
KoTarStore(QWidget* window, const KUrl& url, const QString & _filename, Mode _mode,
const QByteArray & appIdentification, bool writeMimetype = true);
~KoTarStore();
virtual QStringList directoryList() const;
protected:
void init(const QByteArray &appIdentification);
virtual bool doFinalize();
......
......@@ -187,6 +187,19 @@ qint64 KoZipStore::write(const char* _data, qint64 _len)
return 0;
}
QStringList KoZipStore::directoryList() const
{
QStringList retval;
const KArchiveDirectory *directory = m_pZip->directory();
foreach(const QString &name, directory->entries()) {
const KArchiveEntry* fileArchiveEntry = m_pZip->directory()->entry(name);
if (fileArchiveEntry->isDirectory()) {
retval << name;
}
}
return retval;
}
bool KoZipStore::closeWrite()
{
Q_D(KoStore);
......
......@@ -43,6 +43,9 @@ public:
virtual void setCompressionEnabled(bool e);
virtual qint64 write(const char* _data, qint64 _len);
virtual QStringList directoryList() const;
protected:
void init(const QByteArray& appIdentification);
virtual bool doFinalize();
......
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