From 26b5f8054d7ef3ec1da6ced33e65081a45b536cd Mon Sep 17 00:00:00 2001 From: Ferdin Handoko <9620862+ferdinh@users.noreply.github.com> Date: Fri, 10 Nov 2017 03:37:10 +1300 Subject: [PATCH] add api to check if spotify is installed (#193) --- SpotifyAPI/Local/SpotifyLocalAPI.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/SpotifyAPI/Local/SpotifyLocalAPI.cs b/SpotifyAPI/Local/SpotifyLocalAPI.cs index d5707b85..245ca1c2 100644 --- a/SpotifyAPI/Local/SpotifyLocalAPI.cs +++ b/SpotifyAPI/Local/SpotifyLocalAPI.cs @@ -302,6 +302,31 @@ namespace SpotifyAPI.Local return Process.GetProcessesByName("spotifywebhelper").Length >= 1; } + /// + /// Determines whether [spotify is installed]. + /// + /// + /// true if [spotify is installed]; otherwise, false. + /// + public static bool IsSpotifyInstalled() + { + bool isInstalled = false; + + // Checks if UWP Spotify is installed. + string uwpSpotifyPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Packages\SpotifyAB.SpotifyMusic_zpdnekdrzrea0"); + + isInstalled = Directory.Exists(uwpSpotifyPath); + + // If UWP Spotify is not installed, try look for desktop version + if (!isInstalled) + { + string desktopSpotifyPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Spotify\Spotify.exe"); + isInstalled = File.Exists(desktopSpotifyPath); + } + + return isInstalled; + } + /// /// Runs Spotify ///