using Path = System.IO.Path; using Microsoft.Win32; namespace EZPPClient_Installer { class OsuUtil { public static string osuInstallDir() { string path = ""; string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"; string second_registry_key = @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"; using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key)) { if (key != null && key.GetSubKeyNames() != null) { foreach (string subkey_name in key.GetSubKeyNames()) { using (RegistryKey subkey = key.OpenSubKey(subkey_name)) { if (subkey != null) { if ((string)subkey.GetValue("DisplayName") == "osu!") { path = Path.GetDirectoryName(subkey.GetValue("DisplayIcon").ToString()); } } } } } } if (string.IsNullOrEmpty(path)) { using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(second_registry_key)) { if (key != null && key.GetSubKeyNames() != null) { foreach (string subkey_name in key.GetSubKeyNames()) { using (RegistryKey subkey = key.OpenSubKey(subkey_name)) { if (subkey != null) { if ((string)subkey.GetValue("DisplayName") == "osu!") { path = Path.GetDirectoryName(subkey.GetValue("DisplayIcon").ToString()); } } } } } } } return path; } } }