コード例 #1
0
        internal ConsoleScript()
        {
            Tick    += OnTick;
            KeyDown += OnKeyDown;

            _outputQueue = new ConcurrentQueue <string[]>();
            _commands    = new Dictionary <String, List <Tuple <ConsoleCommand, MethodInfo> > >();

            _input          = "";
            _isOpen         = false;
            _page           = 1;
            _cursorPos      = 0;
            _commandPos     = -1;
            _lines          = new LinkedList <String>();
            _commandHistory = new List <String>();

            Version version = Assembly.GetExecutingAssembly().GetName().Version;

            Info("--- Community Script Hook V .NET {0} ---", version);
            Info("--- Type \"Help()\" to print an overview of available commands ---");

            //Start a update check Task
            Task.Factory.StartNew(DoUpdateCheck);

            RegisterCommands(typeof(DefaultConsoleCommands), true);

            String         assemblyPath     = Assembly.GetExecutingAssembly().Location;
            String         assemblyFilename = Path.GetFileNameWithoutExtension(assemblyPath);
            ScriptSettings settings         = ScriptSettings.Load(Path.ChangeExtension(assemblyPath, ".ini"));

            ToggleKey   = settings.GetValue <Keys>("Console", "ToggleKey", Keys.F3);
            PageDownKey = settings.GetValue <Keys>("Console", "PageDown", Keys.PageDown);
            PageUpKey   = settings.GetValue <Keys>("Console", "PageUp", Keys.PageUp);
        }
コード例 #2
0
ファイル: Settings.cs プロジェクト: PourrezJ/platform
        /// <summary>
        /// Loads a <see cref="ScriptSettings"/> from the specified file.
        /// </summary>
        /// <param name="filename">The filename to load the settings from.</param>
        public static ScriptSettings Load(string filename)
        {
            var result = new ScriptSettings(filename);

            if (!File.Exists(filename))
            {
                return(result);
            }

            string       line    = null;
            string       section = String.Empty;
            StreamReader reader  = null;

            try
            {
                reader = new StreamReader(filename);
            }
            catch (IOException)
            {
                return(result);
            }

            try
            {
                while (!ReferenceEquals(line = reader.ReadLine(), null))
                {
                    line = line.Trim();

                    if (line.Length == 0 || line.StartsWith(";") || line.StartsWith("//"))
                    {
                        continue;
                    }

                    if (line.StartsWith("[") && line.Contains("]"))
                    {
                        section = line.Substring(1, line.IndexOf(']') - 1).Trim();
                        continue;
                    }
                    else if (line.Contains("="))
                    {
                        int    index = line.IndexOf('=');
                        string key   = line.Substring(0, index).Trim();
                        string value = line.Substring(index + 1).Trim();

                        if (value.Contains("//"))
                        {
                            value = value.Substring(0, value.IndexOf("//") - 1).TrimEnd();
                        }
                        if (value.StartsWith("\"") && value.EndsWith("\""))
                        {
                            value = value.Substring(1, value.Length - 2);
                        }

                        string lookup = $"[{section}]{key}//0".ToUpper();

                        if (result._values.ContainsKey(lookup))
                        {
                            for (int i = 1; result._values.ContainsKey(lookup = $"[{section}]{key}//{i}".ToUpper()); ++i)
                            {
                                continue;
                            }
                        }

                        result._values.Add(lookup, value);
                    }
                }
            }
            finally
            {
                reader.Close();
            }

            return(result);
        }
コード例 #3
0
        public static ScriptSettings Load(string filename)
        {
            StreamReader   streamReader1  = (StreamReader)null;
            ScriptSettings scriptSettings = new ScriptSettings(filename);

            if (!File.Exists(filename))
            {
                return(scriptSettings);
            }
            string str1 = string.Empty;

            streamReader1 = (StreamReader)null;
            StreamReader streamReader2;

            try
            {
                streamReader2 = new StreamReader(filename);
            }
            catch (IOException ex)
            {
                return(scriptSettings);
            }
            try
            {
                while (true)
                {
                    string str2;
                    do
                    {
                        do
                        {
                            string str3 = streamReader2.ReadLine();
                            if (!object.ReferenceEquals((object)str3, (object)null))
                            {
                                str2 = str3.Trim();
                            }
                            else
                            {
                                goto label_20;
                            }
                        }while (str2.Length == 0 || str2.StartsWith(";") || str2.StartsWith("//"));
                        if (str2.StartsWith("[") && str2.Contains("]"))
                        {
                            str1 = str2.Substring(1, str2.IndexOf(']') - 1).Trim();
                        }
                    }while (!str2.Contains("="));
                    int    length = str2.IndexOf('=');
                    string str4   = str2.Substring(0, length).Trim();
                    string str5   = str2.Substring(length + 1).Trim();
                    if (str5.Contains("//"))
                    {
                        char[] chArray = new char[0];
                        str5 = str5.Substring(0, str5.IndexOf("//") - 1).TrimEnd(chArray);
                    }
                    if (str5.StartsWith("\"") && str5.EndsWith("\""))
                    {
                        str5 = str5.Substring(1, str5.Length - 2);
                    }
                    string upper = string.Format("[{0}]{1}", (object)str1, (object)str4).ToUpper();
                    if (scriptSettings._values.ContainsKey(upper))
                    {
                        int num = 1;
                        while (true)
                        {
                            upper = string.Format("[{0}]{1}//{2}", (object)str1, (object)str4, (object)num).ToUpper();
                            if (scriptSettings._values.ContainsKey(upper))
                            {
                                ++num;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    scriptSettings._values.Add(upper, str5);
                }
            }
            finally
            {
                streamReader2.Close();
            }
label_20:
            return(scriptSettings);
        }
コード例 #4
0
        public static ScriptSettings Load(string filename)
        {
            StreamReader   reader   = null;
            ScriptSettings settings = new ScriptSettings(filename);

            if (!File.Exists(filename))
            {
                return(settings);
            }
            string str4 = string.Empty;

            reader = null;
            try
            {
                reader = new StreamReader(filename);
            }
            catch (IOException)
            {
                return(settings);
            }
            while (true)
            {
                try
                {
                    while (true)
                    {
                        string objA = reader.ReadLine();
                        if (ReferenceEquals(objA, null))
                        {
                            return(settings);
                        }
                        else
                        {
                            objA = objA.Trim();
                            if ((objA.Length != 0) && (!objA.StartsWith(";") && !objA.StartsWith("//")))
                            {
                                if (objA.StartsWith("[") && objA.Contains("]"))
                                {
                                    str4 = objA.Substring(1, objA.IndexOf(']') - 1).Trim();
                                }
                                else if (objA.Contains("="))
                                {
                                    int    index = objA.IndexOf('=');
                                    string str5  = objA.Substring(0, index).Trim();
                                    string str2  = objA.Substring(index + 1).Trim();
                                    if (str2.Contains("//"))
                                    {
                                        char[] trimChars = new char[0];
                                        str2 = str2.Substring(0, str2.IndexOf("//") - 1).TrimEnd(trimChars);
                                    }
                                    if (str2.StartsWith("\"") && str2.EndsWith("\""))
                                    {
                                        str2 = str2.Substring(1, str2.Length - 2);
                                    }
                                    string key = $"[{str4}]{str5}".ToUpper();
                                    if (settings._values.ContainsKey(key))
                                    {
                                        int num = 1;
                                        while (true)
                                        {
                                            key = $"[{str4}]{str5}//{num}".ToUpper();
                                            if (!settings._values.ContainsKey(key))
                                            {
                                                break;
                                            }
                                            num++;
                                        }
                                    }
                                    settings._values.Add(key, str2);
                                }
                            }
                        }
                        break;
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
        }