Skip to content

Instantly share code, notes, and snippets.

@a-andreyev
Created June 19, 2013 16:03
Show Gist options
  • Save a-andreyev/5815525 to your computer and use it in GitHub Desktop.
Save a-andreyev/5815525 to your computer and use it in GitHub Desktop.
My qt5-qtsystems QStorageInfoPrivate::uriForDrive for Windows OSes realization to get uri-for-drive value similar with unix OSes
// My qt5-qtsystems QStorageInfoPrivate::uriForDrive for Windows OSes realization to get uri-for-drive value similar with unix OSes
// yetanotherandreyev at gmail
QString QStorageInfoPrivate::uriForDrive(const QString &drive)
{
WCHAR VolumeNameBuffer[100], FileSystemNameBuffer[100]; // not sure about buffer size yet
long unsigned int sn;
if (GetVolumeInformation((WCHAR *)drive.utf16(), VolumeNameBuffer, 100, &sn, NULL, NULL, FileSystemNameBuffer, 100)) {
QString uri = QString::number(sn,16).toUpper();
int x = uri.size();
if (x<8) {
for (int i=0;i<(8-x);i++) {
uri.insert(0,QString("0"));
}
}
if (uri.size()==8) uri.insert(4,QString("-"));
return uri;
}
return QString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment