public static VProperty AddProperty(this VToken vdf, string key, object value = null) { var property = new VProperty(key, new VValue(value ?? "")); (vdf as VObject).Add(property); return(property); }
public static string[] GetSteamLibraryPaths() { string[] libraryPaths = Array.Empty <string>(); using (RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))// Doesn't work in 32 bit mode without this { using (RegistryKey steamKey = hklm?.OpenSubKey(STEAM_PATH_KEY)) { string path = (string)steamKey?.GetValue("InstallPath", string.Empty); if (path != null && path.Length > 0) { string configPath = Path.Combine(path, STEAM_CONFIG_PATH); if (File.Exists(configPath)) { VProperty v = VdfConvert.Deserialize(File.ReadAllText(configPath)); VToken ics = v?.Value; VToken soft = ics?["Software"]; VToken valve = soft?["Valve"]; VObject steamSettings = valve?["Steam"] as VObject; VProperty[] settings = steamSettings?.Children <VProperty>()?.ToArray(); if (settings != null) { libraryPaths = settings.Where(p => p.Key.StartsWith("BaseInstallFolder")) .Select(p => p.Value.ToString()).ToArray(); } } } } } return(libraryPaths); }
public static IEnumerable <LoginUsers> GetLoginUsers() { dynamic volvo = VdfConvert.Deserialize(GetLoginUsersConfig()); VToken v2 = volvo.Value; return(v2.Children().Select(child => new LoginUsers(child)).Where(user => user.RememberPassword).ToList()); }
public void DeepEqualsSucceedsCorrectly() { VProperty prop1 = new VProperty("key1", new VValue("value1")); VProperty prop2 = new VProperty("key1", new VValue("value1")); Assert.True(VToken.DeepEquals(prop1, prop2)); }
public void CommentsDeserializeCorrectly() { const string vdf = @" // Comment type A (at the start of the file) ""root"" { // Comment type B (as a child to an object) key1 ""value1"" ""key2"" // Comment type C (to the right of a property name) { ""key3"" ""value3"" // Comment type D (to the right of a property value) } } // Comment type E (at the end of the file) "; VProperty result = VdfConvert.Deserialize(vdf); VProperty expected = new VProperty("root", new VObject { VValue.CreateComment(" Comment type B (as a child to an object)"), new VProperty("key1", new VValue("value1")), new VProperty("key2", new VObject { new VProperty("key3", new VValue("value3")), VValue.CreateComment(" Comment type D (to the right of a property value)"), }), }); Assert.True(VToken.DeepEquals(result, expected)); }
public void DeepEqualsFailsCorrectly() { VValue val1 = new VValue("value1"); VValue val2 = new VValue("value2"); Assert.False(VToken.DeepEquals(val1, val2)); }
public void DeepEqualsSucceedsCorrectly() { VValue val1 = new VValue("value1"); VValue val2 = new VValue("value1"); Assert.True(VToken.DeepEquals(val1, val2)); }
public void DeepEqualsFailsCorrectly() { VProperty prop1 = new VProperty("key1", new VValue("value1")); VProperty prop2 = new VProperty("key2", new VValue("value1")); VProperty prop3 = new VProperty("key1", new VValue("value2")); Assert.False(VToken.DeepEquals(prop1, prop2)); Assert.False(VToken.DeepEquals(prop1, prop3)); }
public static IEnumerable <User2Json.SteamLoginUsers> GetLoginUsers() { if (SteamPath.SteamLocation == null) { SteamPath.Init(); } dynamic volvo = VdfConvert.Deserialize(File.ReadAllText(SteamPath.SteamLocation + @"\config\loginusers.vdf")); VToken v2 = volvo.Value; return(v2.Children().Select(child => new SteamLoginUsers((VProperty)child)).OrderByDescending(user => user.LastLoginTime).ToList()); }
public VToken[] GetTokens() { clang.tokenize(TranslationUnit, Extent, out IntPtr pointer, out uint numPointers); var tokens = new VToken[numPointers]; var sizeInBytes = Marshal.SizeOf(typeof(CXToken)); for (int i = 0; i < numPointers; i++) { var ptr = pointer + (i * sizeInBytes); tokens[i] = new VToken(this, Marshal.PtrToStructure <CXToken>(ptr)); } return(tokens); }
public static IEnumerable <SteamLoginUsers> GetLoginUsers() { if (Helpers.Extensions.SteamLocation == null) { Helpers.Extensions.Init(); } dynamic volvo = VdfConvert.Deserialize(File.ReadAllText(Helpers.Extensions.SteamLocation + @"\config\loginusers.vdf")); VToken v2 = volvo.Value; return(v2.Children().Select(child => new SteamLoginUsers(child)).OrderByDescending(user => user.LastLoginTime).ToList()); //.Where(user => user.RememberPassword) }
public static string Serialize(VToken value, VdfSerializerSettings settings) { if (value == null) { throw new ArgumentNullException(nameof(value)); } StringBuilder stringBuilder = new StringBuilder(256); StringWriter stringWriter = new StringWriter(stringBuilder, CultureInfo.InvariantCulture); (new VdfSerializer(settings)).Serialize(stringWriter, value); return(stringWriter.ToString()); }
public static SteamLaunchableModSource Make(UInt32 HostAppID, string ModDir, VObject gameInfo = null) { VObject GameInfoObj = (VObject)(gameInfo.ContainsKey("GameInfo") ? gameInfo["GameInfo"] : null); VToken GameObj = GameInfoObj != null?GameInfoObj.ContainsKey("game") ? GameInfoObj["game"] : null : null; VToken IconObj = GameInfoObj != null?GameInfoObj.ContainsKey("icon") ? GameInfoObj["icon"] : null : null; SteamLaunchableModSource src = new SteamLaunchableModSource(HostAppID, ModDir, GameObj?.ToString()) { ModIcon = IconObj?.ToString() }; return(src); }
public void DeepEqualsFailsCorrectly() { VObject obj1 = new VObject { new VProperty("key1", new VValue("value1")), new VProperty("key2", new VValue("value2")), }; VObject obj2 = new VObject { new VProperty("key1", new VValue("value1")), new VProperty("key2", new VValue("value3")), }; Assert.False(VToken.DeepEquals(obj1, obj2)); }
public void DoubleSlashInValueDeserializesCorrectly() { const string vdf = @" ""root"" { ""key1"" ""//"" } "; VProperty result = VdfConvert.Deserialize(vdf); VProperty expected = new VProperty("root", new VObject { new VProperty("key1", new VValue("//")), }); Assert.True(VToken.DeepEquals(result, expected)); }
public static VToken GetValue(this VToken vdf, params string[] keys) { VToken token = vdf; foreach (var key in keys) { if ((token as VObject).TryGetValue(key, out var value)) { token = value.Value; } else { return(null); } } return(token); }
public virtual VToken Create(Tuple <ITokenSource, ICharStream> source, int type, string text, int channel, int start, int stop, int line, int charPositionInLine) { VToken myToken = new VToken(source, type, channel, start, stop) { Line = line, Column = charPositionInLine }; if (text != null) { myToken.Text = text; } else if (this.copyText && source.Item2 != null) { myToken.Text = source.Item2.GetText(Interval.Of(start, stop)); } return(myToken); }
public static VToken Create(this VToken vdf, params string[] keys) { VToken token = vdf; foreach (var key in keys) { if ((token as VObject).TryGetValue(key, out var value)) { token = value.Value; } else { var val = new VObject(); (token as VObject).Add(key, val); token = val; } } return(token); }
public List <SteamLaunchableModSource> GetSourceMods() { // source mods List <SteamLaunchableModSource> SourceMods = new List <SteamLaunchableModSource>(); { string sourceMods = SteamProcessInfo.GetSourceModPath(); if (Directory.Exists(sourceMods)) { Directory.GetDirectories(sourceMods) .Where(dr => File.Exists(Path.Combine(dr, "gameinfo.txt"))) .ToList().ForEach(dr => { VObject rootObj = new VObject(); rootObj.Add(VdfConvert.Deserialize(File.ReadAllText(Path.Combine(dr, "gameinfo.txt")))); VObject GameInfoObj = (VObject)rootObj["GameInfo"]; VObject FileSystemObj = (VObject)GameInfoObj["FileSystem"]; VToken appID = FileSystemObj["SteamAppId"]; UInt32 appIdCheck = 0; if (!UInt32.TryParse(appID.ToString(), out appIdCheck)) { return; } if (appIdCheck == 0) { return; } string AppInstallDir = SteamApps.GetAppInstallDir(appIdCheck); if (!string.IsNullOrWhiteSpace(AppInstallDir)) { SteamLaunchableModSource mod = SteamLaunchableModSource.Make(appIdCheck, dr, rootObj); if (mod != null) { SourceMods.Add(mod); } } }); } } return(SourceMods); }
public static JToken ToJson(this VToken tok, VdfJsonConversionSettings settings = null) { if (settings == null) { settings = new VdfJsonConversionSettings(); } switch (tok) { case VValue val: return(val.ToJson()); case VProperty prop: return(prop.ToJson(settings)); case VObject obj: return(obj.ToJson(settings)); default: throw new InvalidOperationException("Unrecognized VToken."); } }
public static VObject ToVObject(this VToken v) { return((VObject)v); }
/// <summary> /// Adds a new token of any type to the collection. /// </summary> /// <param name="token"></param> public void AddToken(VToken token) { string uniqueKey = GetUniqueKey(token.Key); tokens.Add(uniqueKey, token); }
private void WriteGameInfo(VToken info) { var updated = EnableFormatting ? VdfConvert.Serialize(info, VdfSerializerSettings.Common) : VdfConvert.Serialize(info, VdfSerializerSettings.Default); File.WriteAllText(_path, updated, Windows1252); }
public static VToken GetValue(this VToken vdf, string key) => (vdf as VObject).GetValue(key);
public static string GetString(this VToken vdf, string key) => (vdf as VObject).GetValue(key).ToString();
public void Serialize(TextWriter textWriter, VToken value) { using VdfWriter vdfWriter = new VdfTextWriter(textWriter, _settings); value.WriteTo(vdfWriter); }
public static VValue ToVValue(this VToken v) { return((VValue)v); }
public static string Serialize(VToken value) { return(Serialize(value, VdfSerializerSettings.Common)); }
public static VProperty ToVProperty(this VToken v) { return((VProperty)v); }