diff --git a/TileIconifier.Core/Custom/Steam/KeyValues/KeyValues.cs b/TileIconifier.Core/Custom/Steam/KeyValues/KeyValues.cs index fa9f3f1..f964e37 100644 --- a/TileIconifier.Core/Custom/Steam/KeyValues/KeyValues.cs +++ b/TileIconifier.Core/Custom/Steam/KeyValues/KeyValues.cs @@ -1,30 +1,26 @@ #region LICENCE -// /* -// The MIT License (MIT) -// -// Copyright (c) 2021 Johnathon M -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// -// */ - +/**************************************************************************** + * Library: KeyValues + * Version: 1.0.0.0 + * By: Callysto.net (http://www.callysto.net) + * Target: .NET FRAMEWORK 2.0 + * + * + * This library is inspired on "Source Engine" (HL2SDK) KeyValues Class + * http://developer.valvesoftware.com/wiki/KeyValues_class (SourceSDK KeyValues Class) + * It was used to save data and for send data to a entity. + * It can have unlimited keys and subkeys inside a KeyValue + * SourceSDK KeyValues metods: http://svn.alliedmods.net/viewvc.cgi/hl2sdk/public/tier1/KeyValues.h?view=co&root=sourcemm + * Diferences: + * * More Metods + * ** More easy to loop all keys + * *** Easy to update or add features + * + * + * + * *************************************************************************** +*/ #endregion using System; @@ -138,6 +134,25 @@ public KeyValues(string setName, string firstKey, string firstValue, string firs SetComment(secoundKey, secoundComment); } + public List GetFlattenedKeyValuePairs() + { + return GetFlattenedItems(this).Distinct().ToList(); + } + private static IEnumerable GetFlattenedItems(KeyValues keyValues) + { + foreach (var knv in keyValues.KeyNameValues) + { + yield return knv; + } + foreach (var childItem in keyValues.KeyChilds) + { + foreach (var flattened in GetFlattenedItems(childItem)) + { + yield return flattened; + } + } + } + public KeyValues(string setName, KeyValuesData keyValue) : this(setName) { @@ -260,7 +275,7 @@ public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - return obj is KeyValues && Equals((KeyValues) obj); + return obj is KeyValues && Equals((KeyValues)obj); } /// @@ -273,16 +288,22 @@ public override bool Equals(object obj) /// 2 public override int GetHashCode() { - // Getting hash codes from volatile variables doesn't seem a good move... //TODO Find an immutable way? - var result = Name?.GetHashCode() ?? 0; - result = (result*397) ^ (KeyNameValues?.GetHashCode() ?? 0); - result = (result*397) ^ (KeyChilds?.GetHashCode() ?? 0); - result = (result*397) ^ (FirstParent?.GetHashCode() ?? 0); - result = (result*397) ^ (Parent?.GetHashCode() ?? 0); - result = (result*397) ^ NextSubKeyIndex.GetHashCode(); - result = (result*397) ^ NextKeyValueIndex.GetHashCode(); - result = (result*397) ^ DistanceFromTop.GetHashCode(); - return result; + unchecked + { + // Getting hash codes from volatile variables doesn't seem a good move... //TODO Find an immutable way? + var result = Name?.GetHashCode() ?? 0; + result = (result * 397) ^ (KeyNameValues?.GetHashCode() ?? 0); + result = (result * 397) ^ (KeyChilds?.GetHashCode() ?? 0); + if (FirstParent != this) //prevent stack overflow when hitting top level parent + { + result = (result * 397) ^ (FirstParent?.GetHashCode() ?? 0); + } + result = (result * 397) ^ (Parent?.GetHashCode() ?? 0); + result = (result * 397) ^ NextSubKeyIndex.GetHashCode(); + result = (result * 397) ^ NextKeyValueIndex.GetHashCode(); + result = (result * 397) ^ DistanceFromTop.GetHashCode(); + return result; + } } /// @@ -544,7 +565,7 @@ private static KeyValuePair ReadToken(string line, out bool wasQ { wasQuoted = true; line = line.Remove(0, 1); - var delimeedString = line.Split(new[] {'"'}, StringSplitOptions.RemoveEmptyEntries); + var delimeedString = line.Split(new[] { '"' }, StringSplitOptions.RemoveEmptyEntries); var assertSplit = false; foreach (var s in delimeedString) { @@ -623,13 +644,13 @@ private static KeyValuePair ReadToken(string line, out bool wasQ private uint RetriveIndex(List lines, string search, uint startIndex) { if (string.IsNullOrEmpty(search)) return 0; - for (var i = (int) startIndex; i < lines.Count; i++) + for (var i = (int)startIndex; i < lines.Count; i++) { bool wasQuote; bool wasComment; var kvPair = ReadToken(lines[i], out wasQuote, out wasComment); if (kvPair.Key == search && !wasComment && !wasQuote) - return (uint) i; + return (uint)i; } return 0; } @@ -669,7 +690,7 @@ private bool LoadFromList(List stream, uint startPos, ref uint endPos) { bool wasQuoted; bool wasComment; - var kvPair = ReadToken(stream[(int) i], out wasQuoted, out wasComment); + var kvPair = ReadToken(stream[(int)i], out wasQuoted, out wasComment); if (string.IsNullOrEmpty(kvPair.Key)) continue; endPos = i; // Is the end of KeyValues Class? @@ -930,7 +951,7 @@ public KeyValues GetNextSubKey() if (NextSubKeyIndex < KeyChilds.Count) { NextSubKeyIndex++; - return KeyChilds[(int) NextSubKeyIndex - 1]; + return KeyChilds[(int)NextSubKeyIndex - 1]; } return null; } @@ -951,7 +972,7 @@ public KeyValuesData GetNextKeyValue() if (NextKeyValueIndex < KeyNameValues.Count) { NextKeyValueIndex++; - return KeyNameValues[(int) NextKeyValueIndex - 1]; + return KeyNameValues[(int)NextKeyValueIndex - 1]; } return null; } @@ -970,7 +991,7 @@ public uint RemoveAllKeyNames(uint startPos) uint count = 0; for (var i = startPos; i < KeyNameValues.Count; i++) { - KeyNameValues[(int) i].Parent = null; + KeyNameValues[(int)i].Parent = null; count++; } KeyNameValues.Clear(); @@ -1033,7 +1054,7 @@ public bool SetComment(uint index, string value) return false; if (index >= KeyNameValues.Count) return false; - KeyNameValues[(int) index].Comment = value; + KeyNameValues[(int)index].Comment = value; return true; } diff --git a/TileIconifier.Core/Custom/Steam/KeyValues/KeyValues_Data.cs b/TileIconifier.Core/Custom/Steam/KeyValues/KeyValues_Data.cs index 6074ff7..3ec7f8f 100644 --- a/TileIconifier.Core/Custom/Steam/KeyValues/KeyValues_Data.cs +++ b/TileIconifier.Core/Custom/Steam/KeyValues/KeyValues_Data.cs @@ -1,30 +1,26 @@ #region LICENCE -// /* -// The MIT License (MIT) -// -// Copyright (c) 2021 Johnathon M -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// -// */ - +/**************************************************************************** + * Library: KeyValues + * Version: 1.0.0.0 + * By: Callysto.net (http://www.callysto.net) + * Target: .NET FRAMEWORK 2.0 + * + * + * This library is inspired on "Source Engine" (HL2SDK) KeyValues Class + * http://developer.valvesoftware.com/wiki/KeyValues_class (SourceSDK KeyValues Class) + * It was used to save data and for send data to a entity. + * It can have unlimited keys and subkeys inside a KeyValue + * SourceSDK KeyValues metods: http://svn.alliedmods.net/viewvc.cgi/hl2sdk/public/tier1/KeyValues.h?view=co&root=sourcemm + * Diferences: + * * More Metods + * ** More easy to loop all keys + * *** Easy to update or add features + * + * + * + * *************************************************************************** +*/ #endregion using System; diff --git a/TileIconifier.Core/Custom/Steam/KeyValues/Utils.cs b/TileIconifier.Core/Custom/Steam/KeyValues/Utils.cs index e5048ec..14c0642 100644 --- a/TileIconifier.Core/Custom/Steam/KeyValues/Utils.cs +++ b/TileIconifier.Core/Custom/Steam/KeyValues/Utils.cs @@ -1,29 +1,26 @@ #region LICENCE -// /* -// The MIT License (MIT) -// -// Copyright (c) 2021 Johnathon M -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// -// */ +/**************************************************************************** + * Library: KeyValues + * Version: 1.0.0.0 + * By: Callysto.net (http://www.callysto.net) + * Target: .NET FRAMEWORK 2.0 + * + * + * This library is inspired on "Source Engine" (HL2SDK) KeyValues Class + * http://developer.valvesoftware.com/wiki/KeyValues_class (SourceSDK KeyValues Class) + * It was used to save data and for send data to a entity. + * It can have unlimited keys and subkeys inside a KeyValue + * SourceSDK KeyValues metods: http://svn.alliedmods.net/viewvc.cgi/hl2sdk/public/tier1/KeyValues.h?view=co&root=sourcemm + * Diferences: + * * More Metods + * ** More easy to loop all keys + * *** Easy to update or add features + * + * + * + * *************************************************************************** +*/ #endregion diff --git a/TileIconifier.Core/Custom/Steam/SteamLibrary.cs b/TileIconifier.Core/Custom/Steam/SteamLibrary.cs index 0b50e05..4c5d899 100644 --- a/TileIconifier.Core/Custom/Steam/SteamLibrary.cs +++ b/TileIconifier.Core/Custom/Steam/SteamLibrary.cs @@ -31,7 +31,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text.RegularExpressions; using TileIconifier.Core.Shortcut; namespace TileIconifier.Core.Custom.Steam @@ -103,9 +102,10 @@ public List GetLibraryFolders() var kv = new KeyValues.KeyValues("LibraryFolders"); kv.LoadFromFile(GetLibraryFoldersVdf()); + var flattenedKvp = kv.GetFlattenedKeyValuePairs(); foreach ( var keyValuePair in - kv.KeyNameValues.Where(keyValuePair => Regex.Match(keyValuePair.Key, @"\d+").Success)) + flattenedKvp.Where(keyValuePair => keyValuePair.Key == "path")) { try { diff --git a/TileIconifier.Core/Properties/AssemblyInfo.cs b/TileIconifier.Core/Properties/AssemblyInfo.cs index 306d5ce..57c4351 100644 --- a/TileIconifier.Core/Properties/AssemblyInfo.cs +++ b/TileIconifier.Core/Properties/AssemblyInfo.cs @@ -64,4 +64,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.1.1.1")] \ No newline at end of file +[assembly: AssemblyVersion("3.1.1.2")] \ No newline at end of file diff --git a/TileIconifier/Properties/AssemblyInfo.cs b/TileIconifier/Properties/AssemblyInfo.cs index 6bf39de..4ca7390 100644 --- a/TileIconifier/Properties/AssemblyInfo.cs +++ b/TileIconifier/Properties/AssemblyInfo.cs @@ -64,4 +64,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.1.1.1")] \ No newline at end of file +[assembly: AssemblyVersion("3.1.1.2")] \ No newline at end of file