Commit 744f4c1c authored by captainwong's avatar captainwong

fix logical drives

parent 1e58ae74
...@@ -36,8 +36,39 @@ std::vector<LogicalDrive> logical_drives() ...@@ -36,8 +36,39 @@ std::vector<LogicalDrive> logical_drives()
{ {
std::vector<LogicalDrive> drives; std::vector<LogicalDrive> drives;
wmi::Result result; wmi::Result devices;
if (wmi::WmiBase::simpleSelect({ L"DeviceID", L"DriveType", L"FreeSpace", L"Size", L"VolumeName" }, L"Win32_LogicalDisk", L"where DriveType != 5", result)) { if (wmi::WmiBase::simpleSelect({ L"DeviceID" }, L"Win32_LogicalDisk", L"where DriveType != 5", devices)) {
for (auto&& item : devices) {
std::wstring DeviceID = item[L"DeviceID"];
std::wstring Where = L"where DeviceID=\"" + DeviceID + L"\"";
LogicalDrive drive;
drive.device_id = utf16_to_mbcs(DeviceID);
wmi::Result DriveType, FreeSpace, Size, VolumeName;
if (!wmi::WmiBase::simpleSelect({ L"DriveType" }, L"Win32_LogicalDisk", Where, DriveType)) {
continue;
}
drive.drive_type = parseDriveType(DriveType[0][L"DriveType"]);
if (!wmi::WmiBase::simpleSelect({ L"FreeSpace" }, L"Win32_LogicalDisk", Where, FreeSpace)) {
continue;
}
drive.free_space = FreeSpace.empty() ? 0 : std::stoull(FreeSpace[0][L"FreeSpace"]);
if (!wmi::WmiBase::simpleSelect({ L"Size" }, L"Win32_LogicalDisk", Where, Size)) {
continue;
}
drive.size = Size.empty() ? 0 : std::stoull(Size[0][L"Size"]);
if (!wmi::WmiBase::simpleSelect({ L"VolumeName" }, L"Win32_LogicalDisk", Where, VolumeName)) {
continue;
}
drive.volume_name = VolumeName.empty() ? "" : utf16_to_mbcs(VolumeName[0][L"VolumeName"]);
drives.push_back(drive);
}
}
/*if (wmi::WmiBase::simpleSelect({ L"DeviceID", L"DriveType", L"FreeSpace", L"Size", L"VolumeName" }, L"Win32_LogicalDisk", L"where DriveType != 5", result)) {
for (auto&& item : result) { for (auto&& item : result) {
LogicalDrive drive; LogicalDrive drive;
drive.device_id = utf16_to_mbcs(item[L"DeviceID"]); drive.device_id = utf16_to_mbcs(item[L"DeviceID"]);
...@@ -51,7 +82,7 @@ std::vector<LogicalDrive> logical_drives() ...@@ -51,7 +82,7 @@ std::vector<LogicalDrive> logical_drives()
drive.volume_name = utf16_to_mbcs(item[L"VolumeName"]); drive.volume_name = utf16_to_mbcs(item[L"VolumeName"]);
drives.push_back(drive); drives.push_back(drive);
} }
} }*/
return drives; return drives;
} }
......
...@@ -372,6 +372,9 @@ EndProject ...@@ -372,6 +372,9 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jinfo", "jinfo\jinfo.vcxproj", "{7B505B49-5584-4CF7-A2BB-65CC84303B33}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jinfo", "jinfo\jinfo.vcxproj", "{7B505B49-5584-4CF7-A2BB-65CC84303B33}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_jinfo", "test_jinfo\test_jinfo.vcxproj", "{0E83FBE2-4696-41AD-9A5F-55B1401AB77C}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_jinfo", "test_jinfo\test_jinfo.vcxproj", "{0E83FBE2-4696-41AD-9A5F-55B1401AB77C}"
ProjectSection(ProjectDependencies) = postProject
{7B505B49-5584-4CF7-A2BB-65CC84303B33} = {7B505B49-5584-4CF7-A2BB-65CC84303B33}
EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libjinfo", "libjinfo\libjinfo.vcxproj", "{441E6793-7CDA-4D51-81BD-7A38520F1C1D}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libjinfo", "libjinfo\libjinfo.vcxproj", "{441E6793-7CDA-4D51-81BD-7A38520F1C1D}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment