#include "cachewebpage.h" #include "httpdownload.h" #include "sncdatabase.h" CacheWebPage::CacheWebPage(QString pageUrl, QString cachePath, QObject *parent): QThread(parent) { this->pageUrl = pageUrl; this->cachePath = cachePath; this->stop = false; createPageCachePath(); } CacheWebPage::~CacheWebPage() { qDebug()<pageUrl.toAscii(), QCryptographicHash::Md5 ); md5.append(ba.toHex()); QDir dir(this->cachePath); if(!dir.exists(md5)) { dir.mkdir(md5); } if(this->cachePath.endsWith('/')) this->cachePath += md5 + "/"; else this->cachePath += "/" + md5 + "/"; } void CacheWebPage::abort() { this-> stop = true; } void CacheWebPage::downloadPage() { HttpDownload download; QString storePath = createLocalDirByUrl(this->pageUrl); int retCode = download.downloadFile(this->pageUrl,storePath); if(retCode<0) return ; if(stop) return ; QUrl url(this->pageUrl); QFileInfo fileInfo(url.path()); QFile file(storePath + fileInfo.fileName()); if(!file.open(QIODevice::ReadOnly)) return ; QTextStream in(&file); QString souceText = in.readAll(); file.close(); QStringList elements = getMatchElementFromPage(souceText); QFileInfo fileInfo2(this->pageUrl); for(int i=0;ipageUrl.replace(fileInfo2.fileName(),"") + elements.at(i); QString path = createLocalDirByUrl(link); HttpDownload down; down.downloadFile(link,path); } } QString CacheWebPage::createLocalDirByUrl(QString pageUrl) { QUrl url(pageUrl); QString path = this->cachePath; QStringList subDirs = url.path().split("/"); QDir dir(path); if(subDirs.size()>2) { for(int i=1;i