diff --git a/YACReader/comic.cpp b/YACReader/comic.cpp index 7a3d21de..1a61282d 100644 --- a/YACReader/comic.cpp +++ b/YACReader/comic.cpp @@ -240,7 +240,12 @@ QList<QString> FileComic::filter(const QList<QString> & src) } void FileComic::fileExtracted(int index, const QByteArray & rawData) { + QFile f("c:/temp/out2.txt"); + f.open(QIODevice::Append); + QTextStream out(&f); int sortedIndex = _fileNames.indexOf(_order.at(index)); + out << sortedIndex << " , "; + f.close(); if(sortedIndex == -1) return; _pages[sortedIndex] = rawData; @@ -248,6 +253,104 @@ void FileComic::fileExtracted(int index, const QByteArray & rawData) emit imageLoaded(sortedIndex,_pages[sortedIndex]); } +QList<QVector<quint32> > FileComic::getSections(int & sectionIndex) +{ + QVector<quint32> sortedIndexes; + foreach(QString name, _fileNames) + { + sortedIndexes.append(_order.indexOf(name)); + } + QList<QVector <quint32> > sections; + quint32 previous = 0; + sectionIndex = -1; + int sectionCount = 0; + QVector <quint32> section; + int idx = 0; + int realIdx; + foreach(quint32 i, sortedIndexes) + { + + if(_firstPage == idx) + { + sectionIndex = sectionCount; + realIdx = i; + } + if(previous <= i) + { + //out << "idx : " << i << endl; + section.append(i); + previous = i; + } + else + { + if(sectionIndex == sectionCount) //found + { + if(section.indexOf(realIdx)!=0) + { + QVector <quint32> section1; + QVector <quint32> section2; + foreach(quint32 si,section) + { + if(si<realIdx) + section1.append(si); + else + section2.append(si); + } + sectionIndex++; + sections.append(section1); + sections.append(section2); + //out << "SPLIT" << endl; + + } + else + { + sections.append(section); + } + } + else + sections.append(section); + + section = QVector <quint32> (); + //out << "---------------" << endl; + section.append(i); + //out << "idx : " << i << endl; + previous = i; + sectionCount++; + } + + idx++; + } + if(sectionIndex == sectionCount) //found + { + if(section.indexOf(realIdx)!=0) + { + QVector <quint32> section1; + QVector <quint32> section2; + foreach(quint32 si,section) + { + if(si<realIdx) + section1.append(si); + else + section2.append(si); + } + sectionIndex++; + sections.append(section1); + sections.append(section2); + //out << "SPLIT" << endl; + + } + else + { + sections.append(section); + } + } + else + sections.append(section); + + //out << "se han encontrado : " << sections.count() << " sectionIndex : " << sectionIndex << endl; + return sections; +} + void FileComic::process() { QFile f("c:/temp/out.txt"); @@ -290,8 +393,17 @@ void FileComic::process() out << "tiempo en ordenar : " << myTimer.elapsed() << endl; - QList<QByteArray> allData = archive.getAllData(this); - + _firstPage = 0; + _index = 0; + + int sectionIndex; + QList<QVector <quint32> > sections = getSections(sectionIndex); + + for(int i = sectionIndex; i<sections.count() ; i++) + archive.getAllData(sections.at(i),this); + for(int i = 0; i<sectionIndex; i++) + archive.getAllData(sections.at(i),this); + //archive.getAllData(QVector<quint32>(),this); out << "tiempo en obtener datos : " << myTimer.elapsed() << endl; /* foreach(QString name,_fileNames) @@ -303,7 +415,7 @@ void FileComic::process() emit imageLoaded(sortedIndex,_pages[sortedIndex]); }*/ - out << "tiempo en copiar datos : " << myTimer.elapsed() << endl; + out << "--tiempo en copiar datos : " << myTimer.elapsed() << endl; f.close(); emit imagesLoaded(); } diff --git a/YACReader/comic.h b/YACReader/comic.h index 2ee53392..e2811efd 100644 --- a/YACReader/comic.h +++ b/YACReader/comic.h @@ -29,8 +29,8 @@ int _cfi; - - + //open the comic at this point + int _firstPage; bool _isPDF; public: @@ -86,6 +86,7 @@ Q_OBJECT private: QList<QString> filter(const QList<QString> & src); + QList<QVector<quint32> > getSections(int & sectionIndex); public: FileComic(); FileComic(const QString & path); diff --git a/compressed_archive/compressed_archive.cpp b/compressed_archive/compressed_archive.cpp index 623020fb..0c55c08d 100644 --- a/compressed_archive/compressed_archive.cpp +++ b/compressed_archive/compressed_archive.cpp @@ -166,14 +166,18 @@ int CompressedArchive::getNumFiles() szInterface->archive->GetNumberOfItems(&numItems); return numItems; } -QList<QByteArray> CompressedArchive::getAllData(ExtractDelegate * delegate) +QList<QByteArray> CompressedArchive::getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate) { CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback(true,delegate); CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec); extractCallbackSpec->Init(szInterface->archive, L""); // second parameter is output folder path extractCallbackSpec->PasswordIsDefined = false; - HRESULT result = szInterface->archive->Extract(NULL, -1, false, extractCallback); + HRESULT result; + if(indexes.isEmpty()) + result = szInterface->archive->Extract(NULL, -1, false, extractCallback); + else + result = szInterface->archive->Extract(indexes.data(), indexes.count(), false, extractCallback); if (result != S_OK) { qDebug() << "Extract Error" << endl; diff --git a/compressed_archive/compressed_archive.h b/compressed_archive/compressed_archive.h index 4d526029..23935753 100644 --- a/compressed_archive/compressed_archive.h +++ b/compressed_archive/compressed_archive.h @@ -36,7 +36,7 @@ signals: public slots: int getNumFiles(); - QList<QByteArray> getAllData(ExtractDelegate * delegate = 0); + QList<QByteArray> getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate = 0); QByteArray getRawDataAtIndex(int index); QList<QString> getFileNames(); private: