コード例 #1
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.unquoted_document.vdf"))
     {
         data = KVSerializer.Deserialize(stream);
     }
 }
コード例 #2
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.object_person_mixed_case.vdf"))
     {
         person = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize <Person>(stream);
     }
 }
コード例 #3
0
        public void SetUp()
        {
            var data = new byte[]
            {
                0x00, // object: TestObject
                0x54, 0x65, 0x73, 0x74, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x00,
                0x01, // string: key = value
                0x6B, 0x65, 0x79, 0x00,
                0x76, 0x61, 0x6C, 0x75, 0x65, 0x00,
                0x02,     // int32: int = 0x01020304
                0x69, 0x6E, 0x74, 0x00,
                0x04, 0x03, 0x02, 0x01,
                0x03,     // float32: flt = 1234.5678f
                0x66, 0x6C, 0x74, 0x00,
                0x2B, 0x52, 0x9A, 0x44,
                0x04,     // color: col = 0x10203040
                0x63, 0x6F, 0x6C, 0x00,
                0x40, 0x30, 0x20, 0x10,
                0x06,     // pointer: ptr = 0x11223344
                0x70, 0x74, 0x72, 0x00,
                0x44, 0x33, 0x22, 0x11,
                0x07,     // uint64: long = 0x1122334455667788
                0x6C, 0x6E, 0x67, 0x00,
                0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11,
                0x0A,     // int64, i64 = 0x0102030405070809
                0x69, 0x36, 0x34, 0x00,
                0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
                0x08, // end object
                0x08, // end document
            };

            obj = KVSerializer.Create(KVSerializationFormat.KeyValues1Binary).Deserialize(data);
        }
コード例 #4
0
 public void DeserializeWithNullStream()
 {
     Assert.That(
         () => KVSerializer.Deserialize(stream: null),
         Throws.Exception.TypeOf <ArgumentNullException>()
         .With.Property(nameof(ArgumentNullException.ParamName)).EqualTo("stream"));
 }
コード例 #5
0
        public void SetUp()
        {
            var data = new byte[]
            {
                0x00, // object: FirstObject
                0x46, 0x69, 0x72, 0x73, 0x74, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x00,
                0x01, // string: firstkey = firstvalue
                0x66, 0x69, 0x72, 0x73, 0x74, 0x6b, 0x65, 0x79, 0x00,
                0x66, 0x69, 0x72, 0x73, 0x74, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x00,
                0x08, // end object
                0x08, // end document

                0x00, // object: SecondObject
                0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x00,
                0x01, // string: secondkey = secondvalue
                0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x6b, 0x65, 0x79, 0x00,
                0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x00,
                0x08, // end object
                0x08, // end document
            };

            using var stream = new MemoryStream();
            stream.Write(data, 0, data.Length);
            stream.Seek(0, SeekOrigin.Begin);
            _firstObject = KVSerializer.Create(KVSerializationFormat.KeyValues1Binary).Deserialize <FirstObject>(stream);
            Assert.That(stream.Position, Is.EqualTo(36)); // ensure we read exactly 36 bytes
            _secondObject = KVSerializer.Create(KVSerializationFormat.KeyValues1Binary).Deserialize <SecondObject>(stream);
            Assert.That(stream.Position, Is.EqualTo(75)); // ensure we read exactly 39 bytes
        }
コード例 #6
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.object_person_mixed_case.vdf"))
     {
         person = KVSerializer.Deserialize <Person>(stream);
     }
 }
コード例 #7
0
        public static string GetAlyxPath(string SteamPath)
        {
            List <string> paths = new List <string>();

            if (Directory.Exists(SteamPath))
            {
                paths.Add(SteamPath);
                if (File.Exists(SteamPath + "\\steamapps\\libraryfolders.vdf"))
                {
                    var kv      = KVSerializer.Create(KVSerializationFormat.KeyValues1Text);
                    var kvalues = kv.Deserialize(File.OpenRead(SteamPath + "\\steamapps\\libraryfolders.vdf"));

                    foreach (var item in kvalues)
                    {
                        if (!int.TryParse(item.Name, out int num))
                        {
                            continue;
                        }
                        paths.Add(item.Value.ToString());
                    }
                }
            }
            foreach (var item in paths)
            {
                if (Directory.Exists(item + "\\steamapps\\common\\Half-Life Alyx\\game\\hlvr"))
                {
                    return(item.Replace("\\\\", "/", System.StringComparison.Ordinal) + "/steamapps/common/Half-Life Alyx");
                }
            }

            return(null);
        }
コード例 #8
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.escaped_quotation_marks.vdf"))
     {
         data = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize(stream);
     }
 }
コード例 #9
0
 KVObject IKVTextReader.Read(string resourceName, KVSerializerOptions options)
 {
     using (var stream = TestDataHelper.OpenResource(resourceName))
     {
         return(KVSerializer.Deserialize(stream, options));
     }
 }
        public void CanDeserializeToObject()
        {
            StronglyTypedCollectionDeserializationTestCase.RootObject <TDictionary> rootObject;

            using (var resourceStream = TestDataHelper.OpenResource("Text.list_of_objects.vdf"))
            {
                rootObject = KVSerializer.Create(KVSerializationFormat.KeyValues1Text)
                             .Deserialize <StronglyTypedCollectionDeserializationTestCase.RootObject <TDictionary> >(resourceStream);
            }

            Assert.That(rootObject, Is.Not.Null);
            Assert.That(rootObject.Numbers, Is.Not.Null);
            Assert.That(rootObject.Numbers, Is.InstanceOf <TDictionary>());

#pragma warning disable NUnit2022 // Missing property required for constraint - False-positive: https://github.com/nunit/nunit.analyzers/issues/407
            Assert.That(rootObject.Numbers, Has.Count.EqualTo(3));
#pragma warning restore NUnit2022

            Assert.That(rootObject.Numbers["0"], Is.Not.Null);
            Assert.That(rootObject.Numbers["0"].Name, Is.EqualTo("zero"));
            Assert.That(rootObject.Numbers["0"].Value, Is.EqualTo("nothing"));

            Assert.That(rootObject.Numbers["1"], Is.Not.Null);
            Assert.That(rootObject.Numbers["1"].Name, Is.EqualTo("one"));
            Assert.That(rootObject.Numbers["1"].Value, Is.EqualTo("a bit"));

            Assert.That(rootObject.Numbers["2"], Is.Not.Null);
            Assert.That(rootObject.Numbers["2"].Name, Is.EqualTo("two"));
            Assert.That(rootObject.Numbers["2"].Value, Is.EqualTo("a bit more"));
        }
コード例 #11
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.nested_object_graph.vdf"))
     {
         data = KVSerializer.Deserialize <ObjectGraph>(stream);
     }
 }
コード例 #12
0
 public static KVObject Deserialize(this KVSerializer serializer, byte[] data, KVSerializerOptions options = null)
 {
     using (var ms = new MemoryStream(data))
     {
         return(serializer.Deserialize(ms, options));
     }
 }
コード例 #13
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.nested_object_graph.vdf"))
     {
         data = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize <ObjectGraph>(stream);
     }
 }
コード例 #14
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.escaped_backslash_not_special.vdf"))
     {
         data = KVSerializer.Deserialize(stream);
     }
 }
コード例 #15
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.duplicate_keys.vdf"))
     {
         data = KVSerializer.Deserialize <Dictionary <string, string> >(stream);
     }
 }
コード例 #16
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.list_of_values.vdf"))
     {
         data = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize <ContainerClass>(stream);
     }
 }
コード例 #17
0
        public static void Load()
        {
            SettingsFilePath = Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule?.FileName), "settings.txt");

            if (!File.Exists(SettingsFilePath))
            {
                Save();
                return;
            }

            using (var stream = new FileStream(SettingsFilePath, FileMode.Open, FileAccess.Read))
            {
                Config = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize <AppConfig>(stream, KVSerializerOptions.DefaultOptions);
            }

            BackgroundColor = ColorTranslator.FromHtml(Config.BackgroundColor);

            if (Config.SavedCameras == null)
            {
                Config.SavedCameras = new Dictionary <string, float[]>();
            }

            if (string.IsNullOrEmpty(Config.OpenDirectory) && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Config.OpenDirectory = GetSteamPath();
            }
        }
コード例 #18
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.type_guessing.vdf"))
     {
         data = KVSerializer.Deserialize(stream);
     }
 }
コード例 #19
0
ファイル: ArrayTestCase.cs プロジェクト: xfw5/ValveKeyValue
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.list_of_values.vdf"))
     {
         data = KVSerializer.Deserialize <SerializedType>(stream);
     }
 }
コード例 #20
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.top_level_list_of_values.vdf"))
     {
         data = KVSerializer.Deserialize <TEnumerable>(stream);
     }
 }
コード例 #21
0
        public void SerializesValuesCorrectly()
        {
            var dataObject = new DataObject
            {
                Test = new Dictionary <string, float[]>
                {
                    ["test"]  = new[] { 1.1234f, 2.2345f, 3.54677f },
                    ["test2"] = new[] { 1.1234f, 2.2345f, 3.54677f }
                },
            };

            string text;

            using (var ms = new MemoryStream())
            {
                KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Serialize(ms, dataObject, "test");

                ms.Seek(0, SeekOrigin.Begin);
                using (var reader = new StreamReader(ms))
                {
                    text = reader.ReadToEnd();
                }
            }

            var expected = TestDataHelper.ReadTextResource("Text.dictionary_with_array_values.vdf");

            Assert.That(text, Is.EqualTo(expected));
        }
        public void CanDeserializeToObject()
        {
            StronglyTypedCollectionDeserializationTestCase.RootObject <TDictionary> rootObject;

            using (var resourceStream = TestDataHelper.OpenResource("Text.list_of_objects.vdf"))
            {
                rootObject = KVSerializer.Create(KVSerializationFormat.KeyValues1Text)
                             .Deserialize <StronglyTypedCollectionDeserializationTestCase.RootObject <TDictionary> >(resourceStream);
            }

            Assert.That(rootObject, Is.Not.Null);
            Assert.That(rootObject.Numbers, Is.Not.Null);
            Assert.That(rootObject.Numbers, Is.InstanceOf <TDictionary>());

            Assert.That(rootObject.Numbers, Has.Count.EqualTo(3));

            Assert.That(rootObject.Numbers["0"], Is.Not.Null);
            Assert.That(rootObject.Numbers["0"].Name, Is.EqualTo("zero"));
            Assert.That(rootObject.Numbers["0"].Value, Is.EqualTo("nothing"));

            Assert.That(rootObject.Numbers["1"], Is.Not.Null);
            Assert.That(rootObject.Numbers["1"].Name, Is.EqualTo("one"));
            Assert.That(rootObject.Numbers["1"].Value, Is.EqualTo("a bit"));

            Assert.That(rootObject.Numbers["2"], Is.Not.Null);
            Assert.That(rootObject.Numbers["2"].Name, Is.EqualTo("two"));
            Assert.That(rootObject.Numbers["2"].Value, Is.EqualTo("a bit more"));
        }
コード例 #23
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.escaped_quotation_marks.vdf"))
     {
         data = KVSerializer.Deserialize(stream);
     }
 }
コード例 #24
0
 public void InvalidTextSyntaxThrowsKeyValueException(string resourceName)
 {
     using var stream = TestDataHelper.OpenResource("Text." + resourceName + ".vdf");
     Assert.That(
         () => KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize(stream),
         Throws.Exception.TypeOf <KeyValueException>());
 }
コード例 #25
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.unquoted_document.vdf"))
     {
         data = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize(stream);
     }
 }
コード例 #26
0
        string PerformNewLineTest(string value, bool hasEscapeSequences)
        {
            KVObject convertedKv;
            var      kv      = new KVObject("newLineTestCase", value);
            var      options = new KVSerializerOptions {
                HasEscapeSequences = hasEscapeSequences
            };

            string text;

            using (var ms = new MemoryStream())
            {
                var serializer = KVSerializer.Create(KVSerializationFormat.KeyValues1Text);

                serializer.Serialize(ms, kv, options);

                ms.Seek(0, SeekOrigin.Begin);

                text = Encoding.ASCII.GetString(ms.GetBuffer(), 0, (int)ms.Length);

                convertedKv = serializer.Deserialize(ms, options);
            }

            Assert.That((string)convertedKv.Value, Is.EqualTo(value));

            return(text);
        }
コード例 #27
0
 public void SingleLineComment(string resourceName)
 {
     using (var stream = TestDataHelper.OpenResource("Text." + resourceName + ".vdf"))
     {
         Assert.That(() => KVSerializer.Deserialize(stream), Throws.Nothing);
     }
 }
コード例 #28
0
        public void ThrowsException()
        {
            var dataObject1 = new DataObject
            {
                Name = "First"
            };

            var dataObject2 = new DataObject
            {
                Name  = "Second",
                Other = dataObject1
            };

            dataObject1.Other = dataObject2;

            Assert.That(dataObject1.Other, Is.SameAs(dataObject2), "Sanity check");
            Assert.That(dataObject2.Other, Is.SameAs(dataObject1), "Sanity check");

            using (var ms = new MemoryStream())
            {
                Assert.That(
                    () => KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Serialize(ms, dataObject1, "test data"),
                    Throws.Exception.InstanceOf <KeyValueException>()
                    .With.Message.EqualTo("Serialization failed - circular object reference detected."));
            }
        }
コード例 #29
0
        public void CreatesTextDocument()
        {
            var dataObject = new[]
            {
                new DataObject
                {
                    Developer = "Valve Software",
                    Name      = "Dota 2",
                    Summary   = "Dota 2 is a complex game where you get sworn at\nin Russian all the time.",
                    ExtraData = "Hidden Stuff Here"
                },
                new DataObject
                {
                    Developer = "Valve Software",
                    Name      = "Team Fortress 2",
                    Summary   = "Known as \"America's #1 war-themed hat simulator\", this game lets you wear stupid items while killing people.",
                    ExtraData = "More Secrets"
                },
            };

            string text;

            using (var ms = new MemoryStream())
            {
                KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Serialize(ms, dataObject, "test data");

                ms.Seek(0, SeekOrigin.Begin);
                using var reader = new StreamReader(ms);
                text             = reader.ReadToEnd();
            }

            var expected = TestDataHelper.ReadTextResource("Text.serialization_expected.vdf");

            Assert.That(text, Is.EqualTo(expected));
        }
コード例 #30
0
 KVObject IKVTextReader.Read(string resourceName, KVSerializerOptions options)
 {
     using (var stream = TestDataHelper.OpenResource(resourceName))
     {
         return(KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize(stream, options));
     }
 }