コード例 #1
0
 internal static void EditBind(ConsoleButton button)
 {
     File.WriteAllText(BIND_FILE, File.ReadAllText(BIND_FILE).Replace(GuuConsole.customButtons[button.ID].ToString(), button.ToString()));
 }
コード例 #2
0
        /// <summary>
        /// Registers a new button to the console
        /// </summary>
        /// <param name="button">The button to register</param>
        /// <param name="replace">Set to true to replace the button if it already exists</param>
        /// <returns>True if registered, false otherwise</returns>
        public static bool RegisterButton(ConsoleButton button, bool replace = false)
        {
            string id = button.ID.ToLowerInvariant();

            if (id.Equals(string.Empty))
            {
                GuuCore.LOGGER.LogWarning($"Trying to register a button with an empty id, such if not possible!");
                return(false);
            }

            if (id.Equals("all"))
            {
                (Loader.ModLoader.Context == null ? GuuCore.LOGGER : Loader.ModLoader.Context.Logger)
                .LogWarning("Trying to register command button with id '<color=white>all</color>' but '<color=white>all</color>' is not a valid id!");
                return(false);
            }

            if (button.Custom)
            {
                if (customButtons.ContainsKey(id) && !replace)
                {
                    GuuCore.LOGGER?.LogWarning($"Trying to register custom command button with id '<color=white>{id}</color>' but the ID is already registered!");
                    return(false);
                }

                if (replace)
                {
                    if (!button.NoBinder)
                    {
                        ConsoleBinder.EditBind(button);
                    }
                    customButtons[id] = button;
                }
                else
                {
                    if (!button.NoBinder)
                    {
                        ConsoleBinder.RegisterBind(button);
                    }
                    customButtons.Add(id, button);
                }

                return(true);
            }

            if (buttons.ContainsKey(id) && !replace)
            {
                (Loader.ModLoader.Context == null ? GuuCore.LOGGER : Loader.ModLoader.Context.Logger)
                .LogWarning($"Trying to register command button with id '<color=white>{id}</color>' but the ID is already registered!");
                return(false);
            }

            if (replace)
            {
                buttons[id] = button;
            }
            else
            {
                buttons.Add(id, button);
            }

            return(true);
        }
コード例 #3
0
 internal static void RegisterBind(ConsoleButton button)
 {
     File.AppendAllText(BIND_FILE, $"{button}\n");
 }