Added method to check for compatible OS (#147)

* Added method to check for compatible OS

* Standardized const variables

* Fixed typo

* Negation of usage in if's

* Moved const variables

* simplified IsOSCompatible
This commit is contained in:
shadowlif 2017-06-04 00:15:56 +02:00 committed by Jonas Dellinger
parent 3eefa5a2dc
commit a932aaadc8

View File

@ -44,6 +44,8 @@ namespace SpotifyAPI.Local
}
}
private const int WindowsSevenMajorVersion = 6;
private const int WindowsSevenMinorVersion = 1;
private const byte VkMediaNextTrack = 0xb0;
private const byte VkMediaPrevTrack = 0xb1;
private const int KeyeventfExtendedkey = 0x1;
@ -134,6 +136,10 @@ namespace SpotifyAPI.Local
_eventTimer.Start();
}
private bool IsOSCompatible(int minMajor, int minMinor)
{
return Environment.OSVersion.Version.Major > minMajor || (Environment.OSVersion.Version.Major == minMajor && Environment.OSVersion.Version.Minor >= minMinor);
}
/// <summary>
/// Connects with Spotify. Needs to be called before all other SpotifyAPI functions
/// </summary>
@ -157,12 +163,7 @@ namespace SpotifyAPI.Local
/// </summary>
public void Mute()
{
//Windows < Windows Vista Check
if (Environment.OSVersion.Version.Major < 6)
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
//Windows Vista Check
if (Environment.OSVersion.Version.Major == 6)
if(Environment.OSVersion.Version.Minor == 0)
if(!IsOSCompatible(WindowsSevenMajorVersion, WindowsSevenMinorVersion))
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
VolumeMixerControl.MuteSpotify(true);
}
@ -172,12 +173,7 @@ namespace SpotifyAPI.Local
/// </summary>
public void UnMute()
{
//Windows < Windows Vista Check
if (Environment.OSVersion.Version.Major < 6)
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
//Windows Vista Check
if (Environment.OSVersion.Version.Major == 6)
if (Environment.OSVersion.Version.Minor == 0)
if (!IsOSCompatible(WindowsSevenMajorVersion, WindowsSevenMinorVersion))
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
VolumeMixerControl.MuteSpotify(false);
}
@ -188,12 +184,7 @@ namespace SpotifyAPI.Local
/// <returns>Null if an error occured, otherwise the muted state</returns>
public bool IsSpotifyMuted()
{
//Windows < Windows Vista Check
if (Environment.OSVersion.Version.Major < 6)
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
//Windows Vista Check
if (Environment.OSVersion.Version.Major == 6)
if (Environment.OSVersion.Version.Minor == 0)
if (!IsOSCompatible(WindowsSevenMajorVersion, WindowsSevenMinorVersion))
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
return VolumeMixerControl.IsSpotifyMuted();
}
@ -204,12 +195,7 @@ namespace SpotifyAPI.Local
/// <param name="volume">A value between 0 and 100</param>
public void SetSpotifyVolume(float volume = 100)
{
//Windows < Windows Vista Check
if (Environment.OSVersion.Version.Major < 6)
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
//Windows Vista Check
if (Environment.OSVersion.Version.Major == 6)
if (Environment.OSVersion.Version.Minor == 0)
if (!IsOSCompatible(WindowsSevenMajorVersion, WindowsSevenMinorVersion))
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
if (volume < 0 || volume > 100)
throw new ArgumentOutOfRangeException(nameof(volume));
@ -222,12 +208,7 @@ namespace SpotifyAPI.Local
/// <returns>Null if an error occured, otherwise a float between 0 and 100</returns>
public float GetSpotifyVolume()
{
//Windows < Windows Vista Check
if (Environment.OSVersion.Version.Major < 6)
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
//Windows Vista Check
if (Environment.OSVersion.Version.Major == 6)
if (Environment.OSVersion.Version.Minor == 0)
if (!IsOSCompatible(WindowsSevenMajorVersion, WindowsSevenMinorVersion))
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
return VolumeMixerControl.GetSpotifyVolume();
}