[MeasureFreeDiskSpace]

Fixed: When the designation of Drive is wrong, a strange volume label is indicated.
Changed: Incorrect drive letter (e.g. not "C:\" but "C:") is now allowed.
This commit is contained in:
spx 2009-10-08 16:49:41 +00:00
parent 1f93585b00
commit febd3d1407

View File

@ -55,11 +55,13 @@ bool CMeasureDiskSpace::Update()
{
if (!CMeasure::PreUpdate()) return false;
ULARGE_INTEGER i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;
if (!m_Drive.empty())
{
UINT type = GetDriveType(m_Drive.c_str());
if (type != DRIVE_CDROM && (!m_IgnoreRemovable || type != DRIVE_REMOVABLE)) // Ignore CD-ROMS and removable drives
{
ULARGE_INTEGER i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;
if(GetDiskFreeSpaceEx(m_Drive.c_str(), &i64FreeBytesToCaller, &i64TotalBytes, &i64FreeBytes))
{
LARGE_INTEGER tmpInt;
@ -81,10 +83,11 @@ bool CMeasureDiskSpace::Update()
if (m_Label)
{
WCHAR volumeName[MAX_PATH];
WCHAR volumeName[MAX_PATH] = {0};
GetVolumeInformation(m_Drive.c_str(), volumeName, MAX_PATH, NULL, NULL, NULL, NULL, 0);
m_LabelName = volumeName;
}
}
return PostUpdate();
}
@ -116,16 +119,29 @@ void CMeasureDiskSpace::ReadConfig(CConfigParser& parser, const WCHAR* section)
CMeasure::ReadConfig(parser, section);
m_Drive = parser.ReadString(section, L"Drive", L"C:\\");
if (m_Drive.empty())
{
DebugLog(L"Drive letter is not given.");
m_Value = 0;
m_LabelName = L"";
}
else if (m_Drive[m_Drive.length() - 1] != L'\\') // E.g. "C:"
{
m_Drive += L"\\"; // A trailing backslash is required.
}
m_Total = (1 == parser.ReadInt(section, L"Total", 0));
m_Label = (1 == parser.ReadInt(section, L"Label", 0));
m_IgnoreRemovable = (1 == parser.ReadInt(section, L"IgnoreRemovable", 1));
// Set the m_MaxValue
ULARGE_INTEGER i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;
if (!m_Drive.empty())
{
UINT type = GetDriveType(m_Drive.c_str());
if (type != DRIVE_CDROM && (!m_IgnoreRemovable || type != DRIVE_REMOVABLE)) // Ignore CD-ROMS and removable drives
{
ULARGE_INTEGER i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;
if(GetDiskFreeSpaceEx(m_Drive.c_str(), &i64FreeBytesToCaller, &i64TotalBytes, &i64FreeBytes))
{
LARGE_INTEGER tmpInt;
@ -134,4 +150,5 @@ void CMeasureDiskSpace::ReadConfig(CConfigParser& parser, const WCHAR* section)
}
}
}
}