当前位置: 首页>>代码示例>>C#>>正文


C# KeyValue.SaveToFile方法代码示例

本文整理汇总了C#中SteamKit2.KeyValue.SaveToFile方法的典型用法代码示例。如果您正苦于以下问题:C# KeyValue.SaveToFile方法的具体用法?C# KeyValue.SaveToFile怎么用?C# KeyValue.SaveToFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SteamKit2.KeyValue的用法示例。


在下文中一共展示了KeyValue.SaveToFile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: KeyValueBinarySerialization_LoadAsBinaryPreservesBuggyBehavior

        public void KeyValueBinarySerialization_LoadAsBinaryPreservesBuggyBehavior()
        {
            var kv = new KeyValue( "MessageObject" );
            kv.Children.Add( new KeyValue( "key", "value" ) );

            KeyValue deserializedKv;

            var temporaryFile = Path.GetTempFileName();
            try
            {
                kv.SaveToFile( temporaryFile, asBinary: true );
                deserializedKv = KeyValue.LoadAsBinary( temporaryFile );
            }
            finally
            {
                File.Delete( temporaryFile );
            }

            Assert.Null( deserializedKv.Name );
            Assert.Equal(1, deserializedKv.Children.Count );

            var actualKv = deserializedKv.Children[ 0 ];

            Assert.Equal( kv.Name, actualKv.Name );
            Assert.Equal( kv.Children.Count, actualKv.Children.Count );

            for ( int i = 0; i < kv.Children.Count; i++ )
            {
                var originalChild = kv.Children[ i ];
                var deserializedChild = actualKv.Children[ i ];
                
                Assert.Equal( originalChild.Name, deserializedChild.Name );
                Assert.Equal( originalChild.Value, deserializedChild.Value );
            }
        }
开发者ID:RaptorFactor,项目名称:SteamKit,代码行数:35,代码来源:KeyValueFacts.cs

示例2: KeyValueBinarySerializationIsSymmetric

        public void KeyValueBinarySerializationIsSymmetric()
        {
            var kv = new KeyValue( "MessageObject" );
            kv.Children.Add( new KeyValue( "key", "value" ) );

            KeyValue deserializedKv;

            var temporaryFile = Path.GetTempFileName();
            try
            {
                kv.SaveToFile( temporaryFile, asBinary: true );
                var loaded = KeyValue.TryLoadAsBinary( temporaryFile, out deserializedKv );
                Assert.True( loaded );
            }
            finally
            {
                File.Delete( temporaryFile );
            }

            Assert.Equal( kv.Name, deserializedKv.Name );
            Assert.Equal( kv.Children.Count, deserializedKv.Children.Count );

            for ( int i = 0; i < kv.Children.Count; i++ )
            {
                var originalChild = kv.Children[ i ];
                var deserializedChild = deserializedKv.Children[ i ];
                
                Assert.Equal( originalChild.Name, deserializedChild.Name );
                Assert.Equal( originalChild.Value, deserializedChild.Value );
            }
        }
开发者ID:RaptorFactor,项目名称:SteamKit,代码行数:31,代码来源:KeyValueFacts.cs

示例3: KeyValuesSavesTextToFile

        public void KeyValuesSavesTextToFile()
        {
            var expected = "\"RootNode\"\n{\n\t\"key1\"\t\t\"value1\"\n\t\"key2\"\n\t{\n\t\t\"ChildKey\"\t\t\"ChildValue\"\n\t}\n}\n";

            var kv = new KeyValue( "RootNode" )
            {
                Children =
                {
                    new KeyValue( "key1", "value1" ),
                    new KeyValue( "key2" )
                    {
                        Children =
                        {
                            new KeyValue( "ChildKey", "ChildValue" )
                        }
                    }
                }
            };

            string text;
            var temporaryFile = Path.GetTempFileName();
            try
            {
                kv.SaveToFile( temporaryFile, asBinary: false );
                text = File.ReadAllText( temporaryFile );
            }
            finally
            {
                File.Delete( temporaryFile );
            }

            Assert.Equal( expected, text );
        }
开发者ID:logtcn,项目名称:SteamKit,代码行数:33,代码来源:KeyValueFacts.cs

示例4: KeyValuesWritesBinary

        public void KeyValuesWritesBinary()
        {
            var expectedHexValue = "00525000017374617475730023444F54415F52505F424F54505241435449434500016E756D5F706172616D730030000" +
                "17761746368696E675F736572766572005B413A313A323130383933353136393A353431325D00017761746368696E675F66726F6D5F73" +
                "6572766572005B413A313A3836343436383939343A353431325D000808";

            var kv = new KeyValue( "RP" );
            kv.Children.Add( new KeyValue( "status", "#DOTA_RP_BOTPRACTICE" ) );
            kv.Children.Add( new KeyValue( "num_params", "0" ) );
            kv.Children.Add( new KeyValue( "watching_server", "[A:1:2108935169:5412]" ) );
            kv.Children.Add( new KeyValue( "watching_from_server", "[A:1:864468994:5412]" ) );

            string tempFileName = null;
            try
            {
                tempFileName = Path.GetTempFileName();

                kv.SaveToFile( tempFileName, asBinary: true );

                var binaryValue = File.ReadAllBytes( tempFileName );
                var hexValue = BitConverter.ToString( binaryValue ).Replace( "-", "" );

                Assert.Equal( expectedHexValue, hexValue );
            }
            finally
            {
                if ( tempFileName != null && File.Exists( tempFileName ) )
                {
                    File.Delete( tempFileName );
                }
            }
        }
开发者ID:RaptorFactor,项目名称:SteamKit,代码行数:32,代码来源:KeyValueFacts.cs

示例5: DownloadAndInstall

        public void DownloadAndInstall(int revision, HashWebClient.RemoteFileInfo archiveInfo, bool steamBeta,
			string steamBuild, UpdatesView view)
        {
            if (steamBeta)
            {
                const int appId = 33930;
                string gameName = "Arma 2: Operation Arrowhead Beta";
                DirectoryInfo armaPath = null;

                try
                {
                    armaPath = new DirectoryInfo(CalculatedGameSettings.Current.Arma2OAPath);
                }
                catch (ArgumentException aex)
                {
                    bool overridenPath = string.IsNullOrWhiteSpace(UserSettings.Current.GameOptions.Arma2OADirectoryOverride);

                    Execute.OnUiThreadSync(() =>
                    {
                        var popup = new InfoPopup("Invalid path", MainWindow.GetWindow(view));
                        popup.Headline.Content = "Game could not be found";
                        popup.SetMessage(overridenPath
                            ? "Invalid game override path, please enter a new game path or remove it"
                            : "Game could not located via the registry, please enter an override path");

                        popup.Show();
                    }, null, DispatcherPriority.Input);

                    return;
                }

                for (armaPath = armaPath.Parent; armaPath != null; armaPath = armaPath.Parent)
                {
                    if (armaPath.Name.Equals("steamapps", StringComparison.OrdinalIgnoreCase))
                    {
                        string manifestName = "appmanifest_" + appId.ToString() + ".acf";
                        string fullManifestPath = Path.Combine(armaPath.FullName, manifestName);
                        if (File.Exists(fullManifestPath))
                        {
                            // Kill Steam so we can edit the game configuration.
                            Process[] processes = Process.GetProcessesByName("Steam");

                            foreach (Process process in processes)
                            {
                                // #YOLO
                                try
                                {
                                    process.Kill();
                                    process.WaitForExit();
                                }
                                catch
                                {
                                    MessageBox.Show("Unable to shut down steam to start patching.",
                                        "Patch error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                                    return;
                                }
                            }

                            var acfKeys = new KeyValue();
                            var reader = new StreamReader(fullManifestPath);
                            var acfReader = new KVTextReader(acfKeys, reader.BaseStream);
                            reader.Close();
                            KeyValue currentBuild = acfKeys.Children.FirstOrDefault(k => k.Name == "buildid");
                            if (!String.IsNullOrEmpty(currentBuild.Value))
                            {
                                if (Equals(currentBuild.Value, steamBuild))
                                {
                                    Execute.OnUiThreadSync(() =>
                                    {
                                        var popup = new InfoPopup("User intervention required", MainWindow.GetWindow(view));
                                        popup.Headline.Content = "Game update using Steam";
                                        popup.SetMessage(gameName + " might be corrupted.\n" +
                                                         "Please validate your client files manually.\n" +
                                                         "Or by clicking on the following link:");
                                        popup.SetLink("steam://validate/" + appId.ToString() + "/", "Update " + gameName);
                                        popup.Closed += (sender, args) => view.CheckForUpdates();
                                        popup.Show();
                                    }, null, DispatcherPriority.Input);
                                }
                                else
                                {
                                    KeyValue gameState = acfKeys.Children.FirstOrDefault(k => k.Name == "StateFlags");
                                    if (!String.IsNullOrEmpty(gameState.Value))
                                    {
                                        currentBuild.Value = steamBuild;
                                        gameState.Value = "2";
                                        acfKeys.SaveToFile(fullManifestPath, false);

                                        Thread.Sleep(1000);

                                        Execute.OnUiThreadSync(() =>
                                        {
                                            var popup = new InfoPopup("User intervention required", MainWindow.GetWindow(view));
                                            popup.Headline.Content = "Game update using Steam";
                                            popup.SetMessage(gameName + " branch switched to BETA.\n" +
                                                             "Please restart Steam to download update.");
                                            popup.Closed += (sender, args) => view.CheckForUpdates();
                                            popup.Show();
                                        }, null, DispatcherPriority.Input);
                                    }
//.........这里部分代码省略.........
开发者ID:rajkosto,项目名称:DayZeroLauncher,代码行数:101,代码来源:Arma2Installer.cs


注:本文中的SteamKit2.KeyValue.SaveToFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。