/// <summary> /// Reads as much useful information as possible from the registry, such as Steam and Half-Life's install paths. /// </summary> private static void ReadFromRegistry() { // read SteamExe using (RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Valve\\Steam")) { if (key != null) { Settings.SteamExeFullPath = (string)key.GetValue("SteamExe", ""); if (Settings.SteamExeFullPath == null) { Settings.SteamExeFullPath = ""; } else { Settings.SteamExeFullPath = Common.SanitisePath(Settings.SteamExeFullPath); // this registry value always seems to be lower case. replace steam.exe with Steam.exe Settings.SteamExeFullPath = Settings.SteamExeFullPath.Replace("steam.exe", "Steam.exe"); } } } // check if SteamExe is valid (contains Steam.exe) if (File.Exists(Settings.SteamExeFullPath)) { // Find an account name (first folder in "SteamApps" that isn't "common" or "SourceMods") // "common" created by peggle extreme, left 4 dead etc. DirectoryInfo steamAppsDirInfo = new DirectoryInfo(Path.GetDirectoryName(Settings.SteamExeFullPath) + "\\SteamApps"); foreach (DirectoryInfo dirInfo in steamAppsDirInfo.GetDirectories()) { if (dirInfo.Name.ToLower() != "common" && dirInfo.Name.ToLower() != "sourcemods") { Settings.SteamAccountFolder = dirInfo.Name; break; } } } else { // bad steam exe path, make the user enter it manually Settings.SteamExeFullPath = ""; } // read half-life folder path, add hl.exe to it using (RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Valve\\Half-Life")) { if (key != null) { Settings.HlExeFullPath = (String)key.GetValue("InstallPath"); if (Settings.HlExeFullPath == null) { Settings.HlExeFullPath = ""; } else { Common.SanitisePath(Settings.HlExeFullPath); Settings.HlExeFullPath += "\\hl.exe"; if (!File.Exists(Settings.HlExeFullPath)) { // bad hl.exe path, make the user enter it manually Settings.HlExeFullPath = ""; } } } } }