QStringList StorageGroup::GetFileInfoList(QString Path) { QStringList files; QString relPath; bool badPath = true; if (Path.isEmpty() || Path == "/") { for (QStringList::Iterator it = m_dirlist.begin(); it != m_dirlist.end(); ++it) files << QString("sgdir::%1").arg(*it); return files; } for (QStringList::Iterator it = m_dirlist.begin(); it != m_dirlist.end(); ++it) { if (Path.startsWith(*it)) { relPath = Path; relPath.replace(*it,""); if (relPath.startsWith("/")) relPath.replace(0,1,""); badPath = false; } } LOG(VB_FILE, LOG_INFO, LOC + QString("GetFileInfoList: Reading '%1'").arg(Path)); if (badPath) return files; QDir d(Path); if (!d.exists()) return files; QFileInfoList list = d.entryInfoList(); if (!list.size()) return files; for (QFileInfoList::iterator p = list.begin(); p != list.end(); ++p) { if (p->fileName() == "." || p->fileName() == ".." || p->fileName() == "Thumbs.db") { continue; } QString tmp; if (p->isDir()) tmp = QString("dir::%1::0").arg(p->fileName()); else tmp = QString("file::%1::%2::%3%4").arg(p->fileName()).arg(p->size()) .arg(relPath).arg(p->fileName()); LOG(VB_FILE, LOG_DEBUG, LOC + QString("GetFileInfoList: (%1)").arg(tmp)); files.append(tmp); } return files; }
qint64 Dialog::countSize(QString filePath) { qint64 fileSize = 0; QList<QString> fileList; QFileInfo fileInfo(filePath); QString strTopDir; if(fileInfo.isDir()) {//文件夹加入堆栈 m_bFolder = true; if (filePath.contains('/')) { QStringList strList = filePath.split("/"); int iSize = strList.size(); strTopDir = strList.at(iSize-1); } else if(filePath.contains('\\')) { QStringList strList = filePath.split("\\"); int iSize = strList.size(); strTopDir = strList.at(iSize-1); } fileList.push_back(filePath); } else {//如果是文件的话就取文件的特特征码,文件特征码用文件的创建,最后的修改时间字符串和文件的路径取MD5 m_bFolder = false; m_fileList.push_front(filePath); fileSize = fileInfo.size(); QString createTime = fileInfo.created().toString(); QString modifiedTime = fileInfo.lastModified().toString(); QString checkString = createTime + modifiedTime; checkString += filePath; //m_fileCheck = MD5String(checkString.toLocal8Bit().data()); } while(!fileList.isEmpty()){//判断堆栈中是否有文件夹 QString filePath = fileList.value(0);//取堆栈的顶部位置 QDir dir(filePath);//文件夹信息 dir.setFilter(QDir::Dirs|QDir::Files|QDir::Hidden|QDir::System); dir.setSorting(QDir::DirsFirst); QFileInfoList list = dir.entryInfoList();//去得文件夹的文件信息 QFileInfoList::iterator iter; if (2 == list.size()) { qDebug() << "empty dir : " << filePath; m_emptyFolderList.push_back(filePath); } for(iter=list.begin(); iter!=list.end(); iter++) {//遍历文件夹内部 //m_stopMutex.lock(); // if(m_bStop) { // m_stopMutex.unlock(); // return -1; // } // m_stopMutex.unlock(); //qDebug() << "filename : " << iter->fileName(); if(iter->fileName() == "." || iter->fileName() == "..") { continue; } if(iter->isDir()) {//如果为文件夹的话加入到堆栈 fileList.push_back(iter->filePath()); } else {//如果是文件的话,取到文件的大小,并且把文件加入到发送list中 fileSize += iter->size(); //QString str m_fileList.push_front(iter->filePath()); } } fileList.pop_front();//堆栈顶部的元素已经处理完毕,出堆栈 } // if(m_fileCheck.size() == 0) {//文件夹的特征码是文件的所有路径取MD5 // QString checkString; // QList<QString>::iterator iter; // for(iter=m_fileList.begin(); iter!=m_fileList.end(); iter++) { // checkString += (*iter); // } // m_fileCheck = MD5String(checkString.toLocal8Bit().data()); // } qDebug() << "file or director size : " << fileSize; return fileSize; }