1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
   | #if defined(__WIN32) || defined(__WINNT)
#include <windows.h> //http://msdn.microsoft.com/en-us/library/windows/desktop/aa364939(v=vs.85).aspx
#endif
typedef wchar_t TCHAR;
#define _tcslen wcslen
#ifdef __LINUX
#include <blkid/blkid.h>
#endif
 
bool DeviceManager::isRemovable(QString path) {
#if defined(__WIN32) || defined(__WINNT)
    QFileInfoList fil=QDir::drives();
    for(int i=0; i<fil.size(); i++)
        if(path.contains(fil.at(i).absoluteFilePath())) {
            UINT uDriveType = GetDriveType(fil.at(i).absoluteFilePath().replace("/","\\").toStdWString().c_str());
            if(uDriveType!=DRIVE_FIXED && uDriveType!=DRIVE_RAMDISK) return true;
        }
#endif
    return false;
}
 
QString DeviceManager::getUuid(QString path) {
    QFileInfoList fil=QDir::drives();
    QString tmp="";
#if defined(__WIN32) || defined(__WINNT)
    for(int i=0; i<fil.size(); i++)
        if(path.contains(fil.at(i).absoluteFilePath())) {
            wchar_t buf[50];
            GetVolumeNameForVolumeMountPoint(fil.at(i).absoluteFilePath().replace("/","\\").toStdWString().c_str(), buf, 50);
            tmp=QString::fromWCharArray(buf);
        }
#endif
#ifdef __LINUX
    QFile f("/proc/mounts");
    QRegExp rx("([\\S]+)[\s]+([\\S]+)[\s]+([\\S]+)[\s]+([\\S]+)[\s]+([\\S]+)[\s]+([\\S]+)");
    f.open(QIODevice::ReadOnly | QIODevice::Text);
    QTextStream ts(&f);
    while(!ts.atEnd()) {
        QString line=ts.readLine().trimmed();
        if(line.at(0)=="#") continue; //ignore comments
        if(rx.exactMatch(line)) {
            if(path.startsWith(rx.cap(2))) return blkid_evaluate_spec(rx.cap(2).toLocal8Bit().constData(), NULL);
        }
    }
    f.close();
#endif
    return tmp;
} | 
Partager