/* ** Returns the uptime as string. ** */ const WCHAR* MeasureUptime::GetStringValue() { static WCHAR buffer[MAX_LINE_LENGTH]; size_t value = (size_t)m_Value; size_t time[4]; time[0] = value % 60; time[1] = (value / 60) % 60; time[2] = (value / (60 * 60)); time[3] = (value / (60 * 60 * 24)); if (!m_AddDaysToHours) { time[2] %= 24; } __try { FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, m_Format.c_str(), 0, 0, buffer, MAX_LINE_LENGTH, (char**)time); } __except (EXCEPTION_EXECUTE_HANDLER) { LogErrorF(this, L"Uptime: \"Format=%s\" invalid", m_Format.c_str()); buffer[0] = 0; } return CheckSubstitute(buffer); }
/* ** This method returns the value as text string. The actual value is ** get with GetValue() so we don't have to worry about m_Invert. ** ** autoScale If true, scale the value automatically to some sensible range. ** scale The scale to use if autoScale is false. ** decimals Number of decimals used in the value. If -1, get rid of ".00000" for dynamic variables. ** percentual Return the value as % from the maximum value. */ const WCHAR* Measure::GetFormattedValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual) { static WCHAR buffer[128]; WCHAR format[32]; if (percentual) { double val = 100.0 * GetRelativeValue(); _snwprintf_s(format, _TRUNCATE, L"%%.%if", decimals); _snwprintf_s(buffer, _TRUNCATE, format, val); } else if (autoScale != AUTOSCALE_OFF) { GetScaledValue(autoScale, decimals, GetValue(), buffer, _countof(buffer)); } else { double val = GetValue() / scale; if (decimals == -1) { int len = _snwprintf_s(buffer, _TRUNCATE, L"%.5f", val); RemoveTrailingZero(buffer, len); } else { _snwprintf_s(format, _TRUNCATE, L"%%.%if", decimals); _snwprintf_s(buffer, _TRUNCATE, format, val); } } return CheckSubstitute(buffer); }
/* ** Returns the time as string. ** */ const WCHAR* CMeasureScript::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual) { if (m_ValueType == LUA_TSTRING) { return CheckSubstitute(m_StringValue.c_str()); } return CMeasure::GetStringValue(autoScale, scale, decimals, percentual); }
/* ** Returns the time as string. ** */ const WCHAR* CMeasureDiskSpace::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual) { if (m_Type || m_Label) { return CheckSubstitute(m_DriveInfo.c_str()); } return CMeasure::GetStringValue(autoScale, scale, decimals, percentual); }
/* ** If the measured registry value is a string display it. Otherwise convert the ** value to string as normal. ** */ const WCHAR* CMeasureRegistry::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual) { if (m_StringValue.empty()) { return CMeasure::GetStringValue(autoScale, scale, decimals, percentual); } return CheckSubstitute(m_StringValue.c_str()); }
const WCHAR* MeasureNowPlaying::GetStringValue() { if (!m_Parent) return nullptr; const Player* player = m_Parent->player; static WCHAR buffer[32]; const WCHAR* str = nullptr; switch (m_Type) { case MEASURE_ARTIST: str = player->GetArtist(); break; case MEASURE_TITLE: str = player->GetTitle(); break; case MEASURE_ALBUM: str = player->GetAlbum(); break; case MEASURE_LYRICS: str = player->GetLyrics(); break; case MEASURE_COVER: str = player->GetCoverPath(); break; case MEASURE_FILE: str = player->GetFilePath(); break; case MEASURE_DURATION: SecondsToTime(player->GetDuration(), m_Parent->disableLeadingZero, buffer); str = buffer; break; case MEASURE_POSITION: SecondsToTime(player->GetPosition(), m_Parent->disableLeadingZero, buffer); str = buffer; break; case MEASURE_GENRE: str = player->GetGenre(); break; } return str ? CheckSubstitute(str) : nullptr; }
/* ** Returns the time as string. ** */ const WCHAR* CMeasureTime::GetStringValue() { static WCHAR tmpSz[MAX_LINE_LENGTH]; struct tm today; tmpSz[0] = 0; SYSTEMTIME sysToday; FILETIME ftToday; ftToday.dwHighDateTime = m_Time.HighPart; ftToday.dwLowDateTime = m_Time.LowPart; FileTimeToSystemTime(&ftToday, &sysToday); today.tm_isdst = 0; today.tm_hour = sysToday.wHour; today.tm_mday = sysToday.wDay; today.tm_min = sysToday.wMinute; today.tm_mon = sysToday.wMonth - 1; today.tm_sec = sysToday.wSecond; today.tm_wday = sysToday.wDayOfWeek; today.tm_yday = GetYearDay(sysToday.wYear, sysToday.wMonth, sysToday.wDay); today.tm_year = sysToday.wYear - 1900; // Create the string if (!m_Format.empty()) { const WCHAR* format = m_Format.c_str(); if (_wcsicmp(L"locale-time", format) == 0) { GetTimeFormat(LOCALE_USER_DEFAULT, 0, &sysToday, NULL, tmpSz, MAX_LINE_LENGTH); } else if (_wcsicmp(L"locale-date", format) == 0) { GetDateFormat(LOCALE_USER_DEFAULT, 0, &sysToday, NULL, tmpSz, MAX_LINE_LENGTH); } else { TimeToString(tmpSz, MAX_LINE_LENGTH, format, &today); } } else { TimeToString(tmpSz, MAX_LINE_LENGTH, L"%H:%M:%S", &today); } return CheckSubstitute(tmpSz); }
/* ** This method returns the value as text string. The actual value is ** get with GetValue() so we don't have to worry about m_Invert. ** ** autoScale If true, scale the value automatically to some sensible range. ** scale The scale to use if autoScale is false. ** decimals Number of decimals used in the value. If -1, get rid of ".00000" for dynamic variables. ** percentual Return the value as % from the maximum value. */ const WCHAR* CMeasure::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual) { static WCHAR buffer[MAX_LINE_LENGTH]; WCHAR format[32]; if (percentual) { double val = 100.0 * GetRelativeValue(); if (decimals == 0) { _itow_s((int)val, buffer, 10); } else { _snwprintf_s(format, _TRUNCATE, L"%%.%if", decimals); _snwprintf_s(buffer, _TRUNCATE, format, val); } } else if (autoScale != AUTOSCALE_OFF) { GetScaledValue(autoScale, decimals, GetValue(), buffer, _countof(buffer)); } else { double val = GetValue() / scale; if (decimals == 0) { val += (val >= 0) ? 0.5 : -0.5; _snwprintf_s(buffer, _TRUNCATE, L"%lli", (LONGLONG)val); } else if (decimals == -1) { int len = _snwprintf_s(buffer, _TRUNCATE, L"%.5f", val); RemoveTrailingZero(buffer, len); } else { _snwprintf_s(format, _TRUNCATE, L"%%.%if", decimals); _snwprintf_s(buffer, _TRUNCATE, format, val); } } return CheckSubstitute(buffer); }
/* ** Gets the string value from the plugin. ** */ const WCHAR* MeasurePlugin::GetStringValue() { if (m_GetStringFunc) { const WCHAR* ret; if (IsNewApi()) { ret = ((NEWGETSTRING)m_GetStringFunc)(m_PluginData); } else { ret = ((GETSTRING)m_GetStringFunc)(m_ID, 0); } if (ret) return CheckSubstitute(ret); } return nullptr; }
/* ** Returns the time as string. ** */ const WCHAR* MeasureDiskSpace::GetStringValue() { return (m_Type || m_Label) ? CheckSubstitute(m_StringValue.c_str()) : nullptr; }
/* ** Returns the value as a string. ** */ const WCHAR* MeasureScript::GetStringValue() { return (m_ValueType == LUA_TSTRING) ? CheckSubstitute(m_StringValue.c_str()) : nullptr; }
/* ** If the measured registry value is a string display it. Otherwise convert the ** value to string as normal. ** */ const WCHAR* MeasureRegistry::GetStringValue() { return !m_StringValue.empty() ? CheckSubstitute(m_StringValue.c_str()) : nullptr; }