Exemplo n.º 1
0
void Dialog::setupStorage()
{
    QSystemStorageInfo mi;
    storageTreeWidget->clear();
    storageTreeWidget->header()->setResizeMode(QHeaderView::ResizeToContents);

    QStringList vols = mi.logicalDrives();
    foreach(QString volName, vols) {
        QString type;
        QSystemStorageInfo::DriveType volType;
        volType = mi.typeForDrive(volName);
        if(volType == QSystemStorageInfo::InternalDrive) {
            type =  "Internal";
        }

        if(volType == QSystemStorageInfo::RemovableDrive) {
            type = "Removable";
        }
        if(volType == QSystemStorageInfo::CdromDrive) {
            type =  "Cdrom";
        }
        if(volType == QSystemStorageInfo::RemoteDrive) {
            type =  "Network";
        }
        QStringList items;
        items << volName;
        items << type;
        items << QString::number(mi.totalDiskSpace(volName));
        items << QString::number(mi.availableDiskSpace(volName));
        QTreeWidgetItem *item = new QTreeWidgetItem(items);
        storageTreeWidget->addTopLevelItem(item);
    }
Exemplo n.º 2
0
static void test_systemstorageinfo(void)
{
  QSystemStorageInfo storageinfo;

  QStringList lst = storageinfo.logicalDrives();

  qDebug() << "storageinfo.logicalDrives ->" << lst;

  for(int i = 0; i < lst.size(); ++i) {
    const QString &drv = lst.at(i);

    qDebug() << "Logical drive:" << drv;

    qlonglong avail = storageinfo.availableDiskSpace(drv);
    qDebug() << "  storageinfo.availableDiskSpace() ->" << human_size(avail);

    qlonglong total = storageinfo.totalDiskSpace(drv);
    qDebug() << "  storageinfo.totalDiskSpace() ->" << human_size(total);

    QSystemStorageInfo::DriveType dtype = storageinfo.typeForDrive(drv);
    qDebug() << "  storageinfo.typeForDrive() ->" << dtype;

    QString duri = storageinfo.uriForDrive(drv);
    qDebug() << "  storageinfo.uriForDrive() ->" << duri;

    QSystemStorageInfo::StorageState dstate = storageinfo.getStorageState(drv);
    qDebug() << "  storageinfo.getStorageState() ->" << dstate;
  }
}
Exemplo n.º 3
0
u64 DirectoryFileSystem::FreeSpace(const std::string &path) {
#ifdef _WIN32
	const std::wstring w32path = ConvertUTF8ToWString(GetLocalPath(path));
	ULARGE_INTEGER free;
	if (GetDiskFreeSpaceExW(w32path.c_str(), &free, nullptr, nullptr))
		return free.QuadPart;
#elif defined(__SYMBIAN32__)
	QSystemStorageInfo storageInfo;
	return (u64)storageInfo.availableDiskSpace("E");
#else
	std::string localPath = GetLocalPath(path);
	struct statvfs diskstat;
	int res = statvfs(localPath.c_str(), &diskstat);

#if HOST_IS_CASE_SENSITIVE
	std::string fixedCase = path;
	if (res != 0 && FixPathCase(basePath, fixedCase, FPC_FILE_MUST_EXIST)) {
		// May have failed due to case sensitivity, try again.
		localPath = GetLocalPath(fixedCase);
		res = statvfs(localPath.c_str(), &diskstat);
	}
#endif

	if (res == 0) {
#ifndef ANDROID
		if (diskstat.f_flag & ST_RDONLY) {
			return 0;
		}
#endif
		return (u64)diskstat.f_bavail * (u64)diskstat.f_frsize;
	}
#endif

	// Just assume they're swimming in free disk space if we don't know otherwise.
	return std::numeric_limits<u64>::max();
}