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


C# Config.Exists方法代码示例

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


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

示例1: LoadSignatures

        private static void LoadSignatures(Config config)
        {
            if (sigloaded)
                return;

            //Determine if there are manually configured signatures
            if (config.Exists("sigversion"))
            {
                //If so, first determine if there are new internally built ones and clobber the manual ones if so.
                if (config.Get("sigversion", "") != Application.ProductVersion)
                {
                    config.Remove("sigversion");
                    config.Remove("SIG_MY_ID");
                    config.Remove("SIG_MY_TARGET");
                    config.Remove("SIG_SPAWN_END");
                    config.Remove("SIG_SPAWN_START");
                    config.Remove("SIG_ZONE_ID");
                    config.Remove("SIG_ZONE_SHORT");
                }

                //push the manually configured signatures
                SIG_MY_ID = config.Get("SIG_MY_ID", DEFAULT_SIG_MY_ID);
                SIG_MY_TARGET = config.Get("SIG_MY_TARGET", DEFAULT_SIG_MY_TARGET);
                SIG_SPAWN_END = config.Get("SIG_SPAWN_END", DEFAULT_SIG_SPAWN_END);
                SIG_SPAWN_START = config.Get("SIG_SPAWN_START", DEFAULT_SIG_SPAWN_START);
                SIG_ZONE_ID = config.Get("SIG_ZONE_ID", DEFAULT_SIG_ZONE_ID);
                SIG_ZONE_SHORT = config.Get("SIG_ZONE_SHORT", DEFAULT_SIG_ZONE_SHORT);
            }
            sigloaded = true;
        }
开发者ID:stsy,项目名称:mappy,代码行数:30,代码来源:FFXIGameInstance.cs

示例2: LoadConfig

        /// <summary> Loads configuration settings from a file called botsettings.txt </summary>
        private void LoadConfig()
        {
            try {
                config = new Config( "botsettings.txt" );
                if( !config.Exists() ) {
                    using( StreamWriter sw = new StreamWriter( "botsettings.txt" ) ) {
                        sw.WriteLine("UseRemoteServer: false");
                        sw.WriteLine("RemotePort: ");
                        sw.WriteLine("RemotePassword: ");
                        sw.WriteLine("CommandsRequireOperator: true");
                        sw.WriteLine("ReconnectAfterKick: true");
                        sw.WriteLine("SaveMap: false");
                        sw.WriteLine("Operators:");
                        sw.WriteLine("#And now, a little explaination on what all these mean.");
                        sw.WriteLine("#UseRemoteServer - Allows remote clients to connect and perform actions on the bot / chat through it. By default, this is disabled." +
                                     "If you choose to use the remote function, you may need to forward the port and/or add an exception to your firewall.");
                        sw.WriteLine("#RemotePort - The port the server will listen on for remote clients. It is fine to leave this blank if UseRemoteServer is false.");
                        sw.WriteLine("#RemotePassword - The password to use for verifying remote clients. " +
                                     "If UseRemoteServer is true and this is blank, the password will be set to \"password\". ");
                        sw.WriteLine("#CommandsRequireOperators - This determines whether bot commands require the person who called them to be in the operators file." +
                                     "Usually you would want this to be true.");
                        sw.WriteLine("#ReconnectAfterKick - This determines if the bot will reconnect after being kicked. Note that if the bot receives a kick packet before" +
                                     "a ServerIdentification packet, it will abort, and assume it has been banned from connecting.");
                        sw.WriteLine("#SaveMap - This determines if the bot will save the map when the chunk packets are sent to it." +
                                     "If this is true, it will be saved as a fCraft compatible map. (Large maps of 512 x 512 x 512 " +
                                     "can use up to ~150 megabytes of RAM when saving, so be wary. After saving, memory usage should return to normal.");
                        sw.WriteLine( "#Operators: Comma separated list of operators, with no spaces. (e.g. test,test1,test2)" );
                        Events.RaiseConfigCreating( new ConfigCreatingEventArgs( config, sw ) );
                    }
                }

                config.Load();
                if( !config.TryParseValueOrDefault( "useremoteserver", false, out UseRemoteServer ) )
                    Log( LogType.Warning, "Couldn't load value for useremoteserver from config. Setting to default value of false" );
                if( UseRemoteServer ) {
                    int remotePort;
                    if( !config.TryParseValueOrDefault( "remoteport", 25561, out remotePort ) ) {
                        Log( LogType.Warning, "Couldn't load value for remoteport from config. Setting to default value of 25561" );
                    }
                    string remotePassword;
                    config.TryGetRawValue( "remotepassword", out remotePassword );
                    if( String.IsNullOrEmpty( remotePassword ) ) {
                        remotePassword = "password";
                        Log( LogType.Warning, "Couldn't load value for remotepassword from config. Setting to default value of \"password\"" );
                    }

                    server = new Server();
                    server.Start( this, remotePort, remotePassword );
                }

                if( !config.TryParseValueOrDefault( "commandsrequireoperator", true, out _requiresop ) )
                    Log( LogType.Warning, "Couldn't load value for commandsrequireoperator from config. Setting to default value of true" );
                if( !config.TryParseValueOrDefault( "reconnectafterkick", true, out _reconnectonkick ) )
                    Log( LogType.Warning, "Couldn't load value for reconnectafterkick from config. Setting to default value of true" );
                if( !config.TryParseValueOrDefault( "savemap", false, out _savemap ) )
                    Log( LogType.Warning, "Couldn't load value for savemap from config. Setting to default value of false" );
                string rawUsers; // Comma separated.
                config.TryGetRawValue( "operators", out rawUsers );
                if( String.IsNullOrEmpty( rawUsers ) ) {
                    Log( LogType.Warning, "Couldn't load value for operators from config. Setting to default value of empty." );
                } else {
                    string[] users = rawUsers.Split( ',' );
                    bool fixedNames = false;
                    for( int i = 0; i < users.Length; i++ ) {
                        if( users[i].IndexOf( ' ' ) != -1 ) {
                            fixedNames = true;
                            users[i] = users[i].Replace( " ", String.Empty );
                        }
                    }
                    if( fixedNames ) {
                        config.AddOrUpdateValue( "operators", String.Join( ",", users ) );
                        Log( LogType.BotActivity, "Fixed up spaces in the list of operators." );
                        config.Save();
                    }
                    Users.AddRange( users );
                }

                Events.RaiseConfigLoading( new ConfigLoadingEventArgs( config ) );
            } catch( Exception e ) {
                Log( LogType.Error, "Couldn't load config:", e.ToString() );
            }
        }
开发者ID:Grivaryg,项目名称:LibClassicBot,代码行数:83,代码来源:MainBot.cs


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