fileprocessor.cpp 1.82 KB
#include <QDebug>
#include "fileprocessor.h"

FileProcessor::FileProcessor()
{

}

bool FileProcessor::folderExist(const QString &path){
    QDir qdir(path);
    qDebug() << "check path" << path;
    return qdir.exists();
}

bool FileProcessor::fileExist(const QString &path_file){
    QFile qfile(path_file);
    return qfile.exists();
}

bool FileProcessor::detectUSB(QString &usbPath){
    QString checkUsbName[3] = {
        "sda",
        "sdb",
        "sdc"
    };

    for(int i =2;i >=0 ; i--){

        if(folderExist(QString("/sys/block/").append(checkUsbName[i]))){
            if(folderExist(QString("/mnt/%111").arg(checkUsbName[i]))){
                usbPath =  QString("/mnt/%111").arg(checkUsbName[i]);
                return true;
            }
            break;
        }
    }
    qDebug() << "usb detect fail";
    return false;
}


void FileProcessor::getAllDirList(QDir d, QStringList &list){
    QStringList qsl = d.entryList(QDir::NoDotAndDotDot | QDir::Dirs);
    foreach(QString strdir, qsl){
        strdir.prepend(d.absolutePath().append("/"));
        list.append(strdir);
        QDir dir(strdir);
        getAllDirList(dir,list);
    }
}

quint64 FileProcessor::getDirSize(const QString &str){
    qint64 sizex = 0;
    QFileInfo str_info(str);
    if(str_info.isDir()){
        QDir dir(str);
        QFileInfoList list = dir.entryInfoList(QDir::Files | QDir::Dirs  | QDir::NoSymLinks | QDir::NoDotAndDotDot);
        for (int i = 0; i < list.size(); ++i)
        {
            QFileInfo fileInfo = list.at(i);
            if(fileInfo.isDir())
            {
                    sizex += getDirSize(fileInfo.absoluteFilePath());
            }
            else{
                //qDebug() << fileInfo.absoluteFilePath() <<  fileInfo.size();
                sizex += fileInfo.size();
            }
        }
    }
   return sizex;
}