Example #1
0
/*!
    Returns a list of volume info objects based on the given \a volumeGUID. The function also solves mounted
    volume folder paths. It does not return any network drive shares.
*/
QList<VolumeInfo> localVolumeInfosFromMountPoints(PTCHAR volumeGUID)
{
#ifndef UNICODE
#define fromWCharArray fromLatin1
#endif
    QList<VolumeInfo> volumes;
    DWORD bufferSize;
    TCHAR volumeNames[MAX_PATH + 1] = { 0 };
    if (GetVolumePathNamesForVolumeName(volumeGUID, volumeNames, MAX_PATH, &bufferSize)) {
        QStringList mountedPaths = QString::fromWCharArray(volumeNames, bufferSize).split(QLatin1Char(char(0)),
            QString::SkipEmptyParts);
        foreach (const QString &mountedPath, mountedPaths) {
            VolumeInfo info;
            info.setMountPath(mountedPath);
            info.setVolumeDescriptor(QString::fromWCharArray(volumeGUID));
            volumes.append(info);
        }
Example #2
0
UINT fileManage::getVolume(WCHAR* volumePathName, UINT num) const {
	HANDLE findHandle = NULL;
	DWORD charCount = MAX_PATH+1;
	WCHAR volumeName[MAX_PATH+1];
	WCHAR deviceName[MAX_PATH+1];
	DWORD index = 0;
	UINT result = 0;
	UINT count = 0;

	findHandle = FindFirstVolume(volumeName, ARRAYSIZE(volumeName));
	if(INVALID_HANDLE_VALUE==findHandle) return 0;
	while(TRUE) {
		index = wcslen(volumeName)-1;
		volumeName[index] = L'\0';
		result = QueryDosDevice(&volumeName[4], deviceName, ARRAYSIZE(deviceName));
		volumeName[index] = L'\\';

		if(ERROR_INSUFFICIENT_BUFFER==result || 0==result) {
			result = 0;
			break;
		}
		result = retrieveDevName(deviceName);
		if(!result) {
			size_t temp = wcslen(volumePathName);
			if(volumePathName[temp]==L'\0') result=1;
			break;
		}
		result = GetVolumePathNamesForVolumeName(volumeName, volumePathName, charCount, &charCount);
		if(result) {
			if(count++==num) {
				size_t temp = wcslen(volumePathName);
				if(volumePathName[temp]==L'\0') result=1;
				break;
			}
			result = FindNextVolume(findHandle, volumeName, ARRAYSIZE(volumeName));
		}
	}

	FindVolumeClose(findHandle);
	findHandle = INVALID_HANDLE_VALUE;
	return result;
}