private static Vdf Get(VdfTokenizer tokenizer, bool child = false) { var section = new Vdf(); while (!tokenizer.IsFinished) { switch (tokenizer.ReadNext()) { case null: if (child) throw new Exception("Unexpected end of file"); return section; case VdfToken.End: if (!child) throw new Exception("Unexpected end of section"); return section; case VdfToken.Begin: throw new Exception("Unexpected begin of section"); } var key = tokenizer.Consume(); switch (tokenizer.ReadNext()) { case null: throw new Exception("Unexpected end of file"); case VdfToken.End: throw new Exception("Unexpected end of section"); case VdfToken.Begin: section.Children[key] = Get(tokenizer, true); break; case VdfToken.String: section.Values[key] = tokenizer.Consume(); break; } } return section; }
public static IEnumerable <SteamProfile> TryToFind() { // TODO: if (OptionForceValue != null) return OptionForceValue; Vdf parsed; try { var regKey = Registry.CurrentUser.OpenSubKey(@"Software\Valve\Steam"); if (regKey == null) { yield break; } var steamPath = regKey.GetValue("SteamPath").ToString(); var config = File.ReadAllText(Path.Combine(steamPath, @"config", @"loginusers.vdf")); parsed = Vdf.Parse(config).Children.GetValueOrDefault("users"); if (parsed == null) { throw new Exception("Config is invalid"); } } catch (Exception e) { NonfatalError.Notify("Can’t get Steam ID from its config", e); yield break; } string selectedId = null; try { var selectedKey = new IniFile(FileUtils.GetRaceIniFilename()); selectedId = selectedKey["REMOTE"].GetNonEmpty("GUID"); } catch (Exception) { // ignored } Vdf selectedSection; if (selectedId != null && parsed.Children.TryGetValue(selectedId, out selectedSection)) { yield return(new SteamProfile(selectedId, selectedSection.Values.GetValueOrDefault("PersonaName"))); } foreach (var pair in parsed.Children.Where(x => x.Key != selectedId)) { yield return(new SteamProfile(pair.Key, pair.Value.Values.GetValueOrDefault("PersonaName"))); } }
private static Vdf Get(VdfTokenizer tokenizer, bool child = false) { var section = new Vdf(); while (!tokenizer.IsFinished) { switch (tokenizer.ReadNext()) { case null: if (child) { throw new Exception("Unexpected end of file"); } return(section); case VdfToken.End: if (!child) { throw new Exception("Unexpected end of section"); } return(section); case VdfToken.Begin: throw new Exception("Unexpected begin of section"); } var key = tokenizer.Consume(); switch (tokenizer.ReadNext()) { case null: throw new Exception("Unexpected end of file"); case VdfToken.End: throw new Exception("Unexpected end of section"); case VdfToken.Begin: section.Children[key] = Get(tokenizer, true); break; case VdfToken.String: section.Values[key] = tokenizer.Consume(); break; } } return(section); }