Exemplo n.º 1
0
        protected override void LoadConfig()
        {
            base.LoadConfig();
            config = Config.ReadObject <PluginConfig>();
            DateTime BlockEnd;

            if (!DateTime.TryParseExact(config.BlockEndStr, "dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out BlockEnd))
            {
                BlockEnd = SaveRestore.SaveCreatedTime.AddHours(config.HoursOfBlock);
                PrintWarning($"Unable to parse block end date format, block end set to {BlockEnd.ToString("dd.MM.yyyy HH:mm:ss")}");
                config.BlockEndStr = BlockEnd.ToString("dd.MM.yyyy HH:mm:ss");
                SaveConfig();
            }
            config.BlockEnd = BlockEnd;
            permission.RegisterPermission(config.BypassPermission, this);
            if (!string.IsNullOrEmpty(config.Gui.Image.Image))
            {
                if (!config.Gui.Image.Image.ToLower().Contains("http"))
                {
                    config.Gui.Image.Image = "file://" + Interface.Oxide.DataDirectory + Path.DirectorySeparatorChar + config.Gui.Image.Image;
                }
            }
            LoadData();
            permission.RegisterPermission("itemsblocker.refresh", this);
        }
Exemplo n.º 2
0
        private static void FormatCodeBlock(this string text, int indent, List <string> lines)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            if (lines == null)
            {
                throw new ArgumentNullException(nameof(lines));
            }

            int beginPos = 0;
            int endPos   = 0;

            void AddCodeLines(string txt, int idt, List <string> list)
            {
                string[] items = txt.SplitBlockLine();

                list.AddRange(items.Where(l => l.Length > 0)
                              .Select(l => l.SetIndent(idt))
                              .ToArray());
            }

            if (GetBlockPositions(text, ref beginPos, ref endPos) == true)
            {
                AddCodeLines(text.Partialstring(0, beginPos - 1), indent, lines);

                if (BlockStartPrefix.Equals(Environment.NewLine))
                {
                    lines.Add(BlockStart.ToString().SetIndent(indent));
                }
                else
                {
                    lines[lines.Count - 1] = $"{lines[lines.Count - 1]}{BlockStartPrefix}{BlockStart}";
                }

                text.Partialstring(beginPos + 1, endPos - 1).FormatCodeBlock(indent + 1, lines);

                if (BlockEndPrefix.Equals(Environment.NewLine))
                {
                    lines.Add(BlockEnd.ToString().SetIndent(indent));
                }
                else
                {
                    lines[lines.Count - 1] = $"{lines[lines.Count - 1]}{BlockEndPrefix}{BlockEnd}";
                }

                text.Partialstring(endPos + 1, text.Length - 1).FormatCodeBlock(indent, lines);
            }
            else
            {
                AddCodeLines(text, indent, lines);
            }
        }