@@ -44,6 +44,8 @@ public ISynchronizeInvoke SynchronizingObject
4444 }
4545 }
4646
47+ private const int WindowsSevenMajorVersion = 6 ;
48+ private const int WindowsSevenMinorVersion = 1 ;
4749 private const byte VkMediaNextTrack = 0xb0 ;
4850 private const byte VkMediaPrevTrack = 0xb1 ;
4951 private const int KeyeventfExtendedkey = 0x1 ;
@@ -134,6 +136,10 @@ private void ElapsedTick(object sender, ElapsedEventArgs e)
134136 _eventTimer . Start ( ) ;
135137 }
136138
139+ private bool IsOSCompatible ( int minMajor , int minMinor )
140+ {
141+ return Environment . OSVersion . Version . Major > minMajor || ( Environment . OSVersion . Version . Major == minMajor && Environment . OSVersion . Version . Minor >= minMinor ) ;
142+ }
137143 /// <summary>
138144 /// Connects with Spotify. Needs to be called before all other SpotifyAPI functions
139145 /// </summary>
@@ -157,13 +163,8 @@ public StatusResponse GetStatus()
157163 /// </summary>
158164 public void Mute ( )
159165 {
160- //Windows < Windows Vista Check
161- if ( Environment . OSVersion . Version . Major < 6 )
166+ if ( ! IsOSCompatible ( WindowsSevenMajorVersion , WindowsSevenMinorVersion ) )
162167 throw new NotSupportedException ( "This feature is only available on Windows 7 or newer" ) ;
163- //Windows Vista Check
164- if ( Environment . OSVersion . Version . Major == 6 )
165- if ( Environment . OSVersion . Version . Minor == 0 )
166- throw new NotSupportedException ( "This feature is only available on Windows 7 or newer" ) ;
167168 VolumeMixerControl . MuteSpotify ( true ) ;
168169 }
169170
@@ -172,13 +173,8 @@ public void Mute()
172173 /// </summary>
173174 public void UnMute ( )
174175 {
175- //Windows < Windows Vista Check
176- if ( Environment . OSVersion . Version . Major < 6 )
176+ if ( ! IsOSCompatible ( WindowsSevenMajorVersion , WindowsSevenMinorVersion ) )
177177 throw new NotSupportedException ( "This feature is only available on Windows 7 or newer" ) ;
178- //Windows Vista Check
179- if ( Environment . OSVersion . Version . Major == 6 )
180- if ( Environment . OSVersion . Version . Minor == 0 )
181- throw new NotSupportedException ( "This feature is only available on Windows 7 or newer" ) ;
182178 VolumeMixerControl . MuteSpotify ( false ) ;
183179 }
184180
@@ -188,13 +184,8 @@ public void UnMute()
188184 /// <returns>Null if an error occured, otherwise the muted state</returns>
189185 public bool IsSpotifyMuted ( )
190186 {
191- //Windows < Windows Vista Check
192- if ( Environment . OSVersion . Version . Major < 6 )
187+ if ( ! IsOSCompatible ( WindowsSevenMajorVersion , WindowsSevenMinorVersion ) )
193188 throw new NotSupportedException ( "This feature is only available on Windows 7 or newer" ) ;
194- //Windows Vista Check
195- if ( Environment . OSVersion . Version . Major == 6 )
196- if ( Environment . OSVersion . Version . Minor == 0 )
197- throw new NotSupportedException ( "This feature is only available on Windows 7 or newer" ) ;
198189 return VolumeMixerControl . IsSpotifyMuted ( ) ;
199190 }
200191
@@ -204,13 +195,8 @@ public bool IsSpotifyMuted()
204195 /// <param name="volume">A value between 0 and 100</param>
205196 public void SetSpotifyVolume ( float volume = 100 )
206197 {
207- //Windows < Windows Vista Check
208- if ( Environment . OSVersion . Version . Major < 6 )
198+ if ( ! IsOSCompatible ( WindowsSevenMajorVersion , WindowsSevenMinorVersion ) )
209199 throw new NotSupportedException ( "This feature is only available on Windows 7 or newer" ) ;
210- //Windows Vista Check
211- if ( Environment . OSVersion . Version . Major == 6 )
212- if ( Environment . OSVersion . Version . Minor == 0 )
213- throw new NotSupportedException ( "This feature is only available on Windows 7 or newer" ) ;
214200 if ( volume < 0 || volume > 100 )
215201 throw new ArgumentOutOfRangeException ( nameof ( volume ) ) ;
216202 VolumeMixerControl . SetSpotifyVolume ( volume ) ;
@@ -222,13 +208,8 @@ public void SetSpotifyVolume(float volume = 100)
222208 /// <returns>Null if an error occured, otherwise a float between 0 and 100</returns>
223209 public float GetSpotifyVolume ( )
224210 {
225- //Windows < Windows Vista Check
226- if ( Environment . OSVersion . Version . Major < 6 )
211+ if ( ! IsOSCompatible ( WindowsSevenMajorVersion , WindowsSevenMinorVersion ) )
227212 throw new NotSupportedException ( "This feature is only available on Windows 7 or newer" ) ;
228- //Windows Vista Check
229- if ( Environment . OSVersion . Version . Major == 6 )
230- if ( Environment . OSVersion . Version . Minor == 0 )
231- throw new NotSupportedException ( "This feature is only available on Windows 7 or newer" ) ;
232213 return VolumeMixerControl . GetSpotifyVolume ( ) ;
233214 }
234215
0 commit comments