PROPERTIES =
{

}

function Initialize()

	msType = SKIN:GetMeasure('MeasureTypeDrive')
	msErrMsg = SKIN:GetMeasure('MeasureErrorMessage')
	msLabel = SKIN:GetMeasure('MeasureLabelDrive')
	msTotal = SKIN:GetMeasure('MeasureTotalDrive')
	msFree = SKIN:GetMeasure('MeasureFreeDrive')
	msUsed = SKIN:GetMeasure('MeasureUsedDrive')
	
	
	sDrive = SKIN:GetVariable('Drive')

end -- function Initialize

function Update()

	sType = msType:GetStringValue()
	sErrMsg = msErrMsg:GetStringValue()
	sLabel = msLabel:GetStringValue()
	iTotal = msTotal:GetValue() / 1073741824
	iFree = msFree:GetValue() / 1073741824
	iUsed = msUsed:GetValue() / 1073741824

	if sType == 'Removed' then
		if sErrMsg == '0' or sErrMsg == '1' or sErrMsg == '2' or sErrMsg == '3' or sErrMsg == '5' then
			
			SKIN:Bang('!SetOption DriveBarTotal ToolTipText ""')
			SKIN:Bang('!HideMeter MeterDriveBarBack')
			SKIN:Bang('!HideMeter MeterDriveBar')
			SKIN:Bang('!HideMeter MeterPercent')
			SKIN:Bang('!HideMeter DriveLetter')
			SKIN:Bang('!HideMeter DriveBarTotal')
			SKIN:Bang('!HideMeter MeterButtonEject')
			SKIN:Bang('!HideMeter MeterButtonOK')
			SKIN:Bang('!HideMeter MeterDriveLabelLetter')
			SKIN:Bang('!HideMeter MeterShowDriveFree')
			if sErrMsg == '2' or sErrMsg == '5' then
				SKIN:Bang('!SetVariable ERR 1')
			end
			if sErrMsg == '3' then
				SKIN:Bang('!SetOption MeterRemoved Text "#Drive# unavailable"')
			else
				SKIN:Bang('!SetOption MeterRemoved Text "#Drive# removed"')
			end
			SKIN:Bang('!ShowMeter MeterRemoved')
		end
	else
			if sErrMsg == '2' or sErrMsg == '5' then
				SKIN:Bang('!SetOption MeterRemoved Text "Error removing #Drive#"')
				SKIN:Bang('!SetOption DriveBarTotal ToolTipText ""')
				SKIN:Bang('!HideMeter MeterDriveBarBack')
				SKIN:Bang('!HideMeter MeterDriveBar')
				SKIN:Bang('!HideMeter MeterPercent')
				SKIN:Bang('!HideMeter DriveLetter')
				SKIN:Bang('!HideMeter DriveBarTotal')
				SKIN:Bang('!HideMeter MeterButtonEject')
				SKIN:Bang('!HideMeter MeterDriveLabelLetter')
				SKIN:Bang('!HideMeter MeterShowDriveFree')
				SKIN:Bang('!ShowMeter MeterButtonOK')
				SKIN:Bang('!ShowMeter MeterRemoved')
			else
				SKIN:Bang('!SetOption MeterRemoved Text "#Drive# removed"')
				SKIN:Bang('!ShowMeter MeterDriveLabelLetter')
				SKIN:Bang('!ShowMeter MeterButtonEject')
				SKIN:Bang('!ShowMeter DriveBarTotal')
				SKIN:Bang('!HideMeter MeterButtonOK')
				SKIN:Bang('!ShowMeter DriveLetter')
				SKIN:Bang('!SetOption DriveBarTotal ToolTipText \"Total Space:  '..round(iTotal,2)..' GB#CRLF#Free Space:  '..round(iFree,2)..' GB#CRLF#Used Space:  '..round(iUsed,2)..' GB"')
				SKIN:Bang('!ShowMeter MeterDriveBarBack')
				SKIN:Bang('!ShowMeter MeterDriveBar')
				SKIN:Bang('!ShowMeter MeterPercent')
				SKIN:Bang('!HideMeter MeterRemoved')	
				SKIN:Bang('!ShowMeter MeterShowDriveFree')
			end
	end

   return sDrive..' is '..sType
   
end -- function Update

function round(num, idp)
  return tonumber(string.format("%." .. (idp or 0) .. "f", num))
end

