Exemple #1
0
 private void LoadConfig()
 {
     using (StreamReader reader = new StreamReader(File.OpenRead("config.toml")))
     {
         _config = TOML.Parse(reader);
     }
 }
Exemple #2
0
        public static List <string> load_config(string config_file)
        {
            List <string> result = new List <string>();
            TomlTable     configuration;

            using (StreamReader file = new StreamReader(File.OpenRead(config_file))) {
                try {
                    configuration = TOML.Parse(file);
                }
                catch (TomlParseException ex) {
                    configuration = ex.ParsedTable;

                    foreach (TomlSyntaxException syntax_ex in ex.SyntaxErrors)
                    {
                        message.send_error(p, $"error in configuration file: {syntax_ex.Column}:{syntax_ex.Line}: {syntax_ex.Message}");
                        message.send_information(p, "attempting to load configuration file either way");
                    }
                }

                // i cant figure this f*****g api out, so...
                result.Add(configuration["gimperbot"]["message"]);
                result.Add(configuration["gimperbot"]["url"]);
                result.Add(configuration["gimperbot"]["timeout"]);                 // I wish i could parse the timeout as string instead, i know theres a way but i cant be bothered to look at the documentation :(
            }

            message.send_success(p, $"loaded configuration file \"{config_file}\" successfully!");
            return(result);
        }
Exemple #3
0
        public static void Init()
        {
            if (File.Exists(configFile))
            {
                using (StreamReader reader = new StreamReader(File.OpenRead(configFile)))
                {
                    // Parse the table
                    TomlTable table = TOML.Parse(reader);

                    if (table.HasKey("Logger"))
                    {
                        LogLevel = (LogLevel)Enum.Parse(typeof(LogLevel), table["Logger"]["LogLevel"]);
                    }

                    if (table.HasKey("AutoUpdate"))
                    {
                        IsUpdateEnabled = table["AutoUpdate"]["enabled"];
                    }

                    if (table.HasKey("cli-wallet"))
                    {
                        CliExecName = table["cli-wallet"]["Name"];
                    }
                }
            }
        }
Exemple #4
0
        public void Initialize(GeneratorInitializationContext context)
        {
            var asm = Assembly.GetExecutingAssembly();

            using var stream = asm.GetManifestResourceStream("osu_database_reader.SourceGenerator.Data.BeatmapProperties.toml");
            using var sr     = new StreamReader(stream !);
            document         = TOML.Parse(sr);
        }
Exemple #5
0
        private static void Main(string[] args)
        {
            var input = Console.In.ReadToEnd();

            JSONNode.forceASCII = true;

            using (var sr = new StringReader(input))
            {
                var node = TOML.Parse(sr);
                var obj  = new JSONObject();
                Traverse(obj, node);
                Console.WriteLine(obj.ToString());
            }
        }
Exemple #6
0
        private static TomlTable DeletePasswordEntryFromTable(string title)
        {
            using (StreamReader reader = new StreamReader(File.OpenRead(passFile)))
            {
                TomlTable table = TOML.Parse(reader);

                if (table.HasKey(title))
                {
                    table.Delete(title);
                    return(table);
                }
            }

            return(null);
        }
Exemple #7
0
    public static TomlTable?Read(Config config)
    {
        var configPath = config.GetProjectConfigPath();

        if (!File.Exists(configPath))
        {
            ThunderstoreCLI.Write.Warn(
                "Unable to find project configuration file",
                $"Looked from {Dim(configPath)}"
                );
            return(null);
        }
        using var reader = new StreamReader(File.OpenRead(configPath));
        return(TOML.Parse(reader));
    }
Exemple #8
0
        private static bool GetPasswordEntryFromTable(string title)
        {
            using (StreamReader reader = new StreamReader(File.OpenRead(passFile)))
            {
                TomlTable table = TOML.Parse(reader);

                if (table.HasKey(title))
                {
                    table.TryGetNode(title, out TomlNode node);
                    Clipboard.SetText(node["password"]);
                    return(true);
                }
            }

            return(false);
        }
Exemple #9
0
        public void TestComments()
        {
            string input = @"
            # This is a test comment
            # The first comment will always be attached to the root node

            # This comment is related to the section
            [test]
            # This comment is related to the value
            val = 'foo'

            # Multiline comments are permitted
            # As long as you want!
            [test2]
            val = 'bar'
            ";

            var expectedNode = new TomlTable
            {
                Comment  = "This is a test comment\r\nThe first comment will always be attached to the root node",
                ["test"] =
                {
                    Comment = "This comment is related to the section",
                    ["val"] = new TomlString
                    {
                        Comment = "This comment is related to the value",
                        Value   = "foo"
                    }
                },
                ["test2"] =
                {
                    Comment = "Multiline comments are permitted\r\nAs long as you want!",
                    ["val"] = "bar"
                }
            };

            using (var sr = new StringReader(input))
            {
                Assert.That.TomlNodesAreEqual(expectedNode, TOML.Parse(sr), false);
            }
        }
Exemple #10
0
        // Method to get the preset for the UI from the Config.toml
        private void getConfig()
        {
            // Read from Config.toml file
            string path       = Directory.GetCurrentDirectory();
            string configData = "";

            // Check if Config.toml exist, if not use Config.sample.toml
            if (File.Exists(path + @"\Config.toml"))
            {
                configData = path + @"\Config.toml";
            }
            else
            {
                configData = path + @"\Config.sample.toml";
            }

            List <string> legendaryList = new List <string>();

            using (StreamReader reader = File.OpenText(@"data/boss_pokemon.json"))
            {
                string json = reader.ReadToEnd();
                foreach (var item in JObject.Parse(json).Properties())
                {
                    legendaryList.Add(Utils.ConvertBossIdToBossName(item.Name));
                }
            }

            List <string> nonLegendList = new List <string>();

            using (StreamReader reader = File.OpenText(@"data/rental_pokemon.json"))
            {
                string json2 = reader.ReadToEnd();
                foreach (var item in JObject.Parse(json2).Properties())
                {
                    nonLegendList.Add(item.Name);
                }
            }

            string[] ballList =
            {
                Utils.ConvertBallIdToBallName("beast-ball"),
                Utils.ConvertBallIdToBallName("dive-ball"),
                Utils.ConvertBallIdToBallName("dream-ball"),
                Utils.ConvertBallIdToBallName("dusk-ball"),
                Utils.ConvertBallIdToBallName("fast-ball"),
                Utils.ConvertBallIdToBallName("friend-ball"),
                Utils.ConvertBallIdToBallName("great-ball"),
                Utils.ConvertBallIdToBallName("heal-ball"),
                Utils.ConvertBallIdToBallName("heavy-ball"),
                Utils.ConvertBallIdToBallName("level-ball"),
                Utils.ConvertBallIdToBallName("love-ball"),
                Utils.ConvertBallIdToBallName("lure-ball"),
                Utils.ConvertBallIdToBallName("luxury-ball"),
                Utils.ConvertBallIdToBallName("master-ball"),
                Utils.ConvertBallIdToBallName("moon-ball"),
                Utils.ConvertBallIdToBallName("nest-ball"),
                Utils.ConvertBallIdToBallName("net-ball"),
                Utils.ConvertBallIdToBallName("poke-ball"),
                Utils.ConvertBallIdToBallName("premier-ball"),
                Utils.ConvertBallIdToBallName("quick-ball"),
                Utils.ConvertBallIdToBallName("repeat-ball"),
                Utils.ConvertBallIdToBallName("safari-ball"),
                Utils.ConvertBallIdToBallName("sport-ball"),
                Utils.ConvertBallIdToBallName("timer-ball"),
                Utils.ConvertBallIdToBallName("ultra-ball")
            };

            using (StreamReader reader = new StreamReader(File.OpenRead(configData)))
            {
                TomlTable t = TOML.Parse(reader);

                // Create Lists for each stat +,=,-
                List <string> arr  = new List <string>();
                List <string> arr1 = new List <string>();
                List <string> arr2 = new List <string>();
                List <string> arr3 = new List <string>();
                List <string> arr4 = new List <string>();
                List <string> arr5 = new List <string>();

                // Loops to get all nodes from TomlNode into the list
                foreach (TomlNode node in t["stats"]["ATTACK_STATS"]["positive"])
                {
                    arr.Add(node);
                }
                foreach (TomlNode node in t["stats"]["ATTACK_STATS"]["neutral"])
                {
                    arr1.Add(node);
                }
                foreach (TomlNode node in t["stats"]["ATTACK_STATS"]["negative"])
                {
                    arr2.Add(node);
                }

                foreach (TomlNode node in t["stats"]["SPEED_STATS"]["positive"])
                {
                    arr3.Add(node);
                }

                foreach (TomlNode node in t["stats"]["SPEED_STATS"]["neutral"])
                {
                    arr4.Add(node);
                }

                foreach (TomlNode node in t["stats"]["SPEED_STATS"]["negative"])
                {
                    arr5.Add(node);
                }

                // Join all strings in list and display in box
                boxAttackPos.Text  = String.Join(",", arr);
                boxAttackNeut.Text = String.Join(",", arr1);
                boxAttackNeg.Text  = String.Join(",", arr2);
                boxSpeedPos.Text   = String.Join(",", arr3);
                boxSpeedNeut.Text  = String.Join(",", arr4);
                boxSpeedNeg.Text   = String.Join(",", arr5);

                boxPokemon.Items.AddRange(legendaryList.ToArray());
                SetConfigValue(boxPokemon, Utils.ConvertBossIdToBossName(t["BOSS"]), t["BOSS"].Comment);

                boxBaseBall.Items.AddRange(ballList);
                SetConfigValue(boxBaseBall, Utils.ConvertBallIdToBallName(t["BASE_BALL"]), t["BASE_BALL"].Comment);

                boxLegendBall.Items.AddRange(ballList);
                SetConfigValue(boxLegendBall, Utils.ConvertBallIdToBallName(t["LEGENDARY_BALL"]), t["LEGENDARY_BALL"].Comment);

                SetConfigValue(boxMode, t["MODE"], t["MODE"].Comment);
                SetConfigValue(boxPathWins, t["FIND_PATH_WINS"], t["FIND_PATH_WINS"].Comment);
                SetConfigValue(boxComPort, t["COM_PORT"], t["COM_PORT"].Comment);

                // Get every Video Capture device and put it into the combobox (with right order)
                List <DsDevice> devices = new List <DsDevice>(DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice));
                foreach (var device in devices)
                {
                    boxVideoCapture.Items.Add(device.Name);
                }
                int videoIndex = t["VIDEO_INDEX"];
                if (videoIndex < devices.Count)
                {
                    boxVideoCapture.Text = devices[videoIndex].Name;
                }

                SetConfigValue(boxTesseract, t["TESSERACT_PATH"], t["TESSERACT_PATH"].Comment);
                SetConfigValue(boxVideoScale, t["advanced"]["VIDEO_SCALE"], t["advanced"]["VIDEO_SCALE"].Comment);
                SetConfigValue(boxVideoDelay, t["advanced"]["VIDEO_EXTRA_DELAY"], t["advanced"]["VIDEO_EXTRA_DELAY"].Comment);

                boxPABotBaseHex.Checked = t["advanced"]["PABOTBASE_HEX"];
                this.toolTip.SetToolTip(this.boxPABotBaseHex, t["advanced"]["PABOTBASE_HEX"].Comment);

                string bossIndexAsText = "";
                if (t["advanced"]["BOSS_INDEX"] == 0)
                {
                    bossIndexAsText = "Top";
                }
                else if (t["advanced"]["BOSS_INDEX"] == 1)
                {
                    bossIndexAsText = "Middle";
                }
                else if (t["advanced"]["BOSS_INDEX"] == 2)
                {
                    bossIndexAsText = "Bottom";
                }
                SetConfigValue(boxBossIndex, bossIndexAsText, t["advanced"]["BOSS_INDEX"].Comment);
                SetConfigValue(boxDyniteOre, t["advanced"]["DYNITE_ORE"], t["advanced"]["DYNITE_ORE"].Comment);
                SetConfigValue(boxConsecutiveResets, t["advanced"]["CONSECUTIVE_RESETS"], t["advanced"]["CONSECUTIVE_RESETS"].Comment);

                boxNonLegend.Items.Add("default");
                boxNonLegend.Items.AddRange(nonLegendList.ToArray());
                SetConfigValue(boxNonLegend, t["advanced"]["NON_LEGEND"], t["advanced"]["NON_LEGEND"].Comment);

                SetConfigValue(boxMaxDynite, t["advanced"]["MAXIMUM_ORE_COST"], t["advanced"]["MAXIMUM_ORE_COST"].Comment);
                SetConfigValue(boxNonLegend, t["NON_LEGEND"], t["NON_LEGEND"].Comment);

                checkBoxDebugLogs.Checked = t["advanced"]["ENABLE_DEBUG_LOGS"];
                this.toolTip.SetToolTip(this.checkBoxDebugLogs, t["advanced"]["ENABLE_DEBUG_LOGS"].Comment);

                boxCheckAttack.Checked = t["stats"]["CHECK_ATTACK_STAT"];
                this.toolTip.SetToolTip(this.boxCheckAttack, t["CHECK_ATTACK_STAT"].Comment);

                boxCheckSpeed.Checked = t["stats"]["CHECK_SPEED_STAT"];
                this.toolTip.SetToolTip(this.boxCheckSpeed, t["CHECK_SPEED_STAT"].Comment);

                SetConfigValue(boxWebhookID, t["discord"]["WEBHOOK_ID"], t["discord"]["WEBHOOK_ID"].Comment);
                SetConfigValue(boxWebhookToken, t["discord"]["WEBHOOK_TOKEN"], t["discord"]["WEBHOOK_TOKEN"].Comment);
                SetConfigValue(boxUserID, t["discord"]["USER_ID"], t["discord"]["USER_ID"].Comment);
                SetConfigValue(boxPingName, t["discord"]["USER_SHORT_NAME"], t["discord"]["USER_SHORT_NAME"].Comment);
                SetConfigValue(boxPingSettings, t["discord"]["UPDATE_LEVELS"], t["discord"]["UPDATE_LEVELS"].Comment);
                SetConfigValue(boxGameLanguage, t["language"]["LANGUAGE"], t["language"]["LANGUAGE"].Comment);
            }
        }
Exemple #11
0
        // Method to change the Config.toml
        private void setConfig()
        {
            // Read the sample to get the language settings + the paths

            string samplePath = Directory.GetCurrentDirectory() + @"\Config.sample.toml";

            using (StreamReader reader = new StreamReader(File.OpenRead(samplePath)))
            {
                TomlTable tt = TOML.Parse(reader);

                // Change the table in the toml file
                string path       = Directory.GetCurrentDirectory();
                string configData = path + @"\Config.toml";

                int boss = 0;
                if (boxBossIndex.Text == "Top")
                {
                    boss = 0;
                }
                if (boxBossIndex.Text == "Middle")
                {
                    boss = 1;
                }
                if (boxBossIndex.Text == "Bottom")
                {
                    boss = 2;
                }

                TomlTable t = new TomlTable();

                t = tt;

                // Get all values in a string-array
                string[] atkPos    = boxAttackPos.Text.Split(',').ToArray();
                string[] atkNeut   = boxAttackNeut.Text.Split(',').ToArray();
                string[] atkNeg    = boxAttackNeg.Text.Split(',').ToArray();
                string[] speedPos  = boxSpeedPos.Text.Split(',').ToArray();
                string[] speedNeut = boxSpeedNeut.Text.Split(',').ToArray();
                string[] speedNeg  = boxSpeedNeg.Text.Split(',').ToArray();

                // General Settings
                t["BOSS"].AsString.Value            = Utils.ConvertBossNameToBossId(boxPokemon.Text);
                t["BASE_BALL"].AsString.Value       = Utils.ConvertBallNameToBallId(boxBaseBall.Text);
                t["LEGENDARY_BALL"].AsString.Value  = Utils.ConvertBallNameToBallId(boxLegendBall.Text);
                t["MODE"].AsString.Value            = boxMode.Text.ToUpper();
                t["FIND_PATH_WINS"].AsInteger.Value = int.Parse(boxPathWins.Text);
                t["COM_PORT"].AsString.Value        = boxComPort.Text;
                t["VIDEO_INDEX"].AsInteger.Value    = boxVideoCapture.SelectedIndex;
                t["TESSERACT_PATH"].AsString.Value  = boxTesseract.Text;

                // Advanced Settings
                t["advanced"]["VIDEO_SCALE"].AsFloat.Value          = float.Parse(boxVideoScale.Text);
                t["advanced"]["VIDEO_EXTRA_DELAY"].AsFloat.Value    = float.Parse(boxVideoDelay.Text);
                t["advanced"]["PABOTBASE_HEX"].AsBoolean.Value      = boxPABotBaseHex.Checked;
                t["advanced"]["BOSS_INDEX"].AsInteger.Value         = boss;
                t["advanced"]["DYNITE_ORE"].AsInteger.Value         = int.Parse(boxDyniteOre.Text);
                t["advanced"]["CONSECUTIVE_RESETS"].AsInteger.Value = int.Parse(boxConsecutiveResets.Text);
                t["advanced"]["NON_LEGEND"].AsString.Value          = boxNonLegend.Text;
                t["advanced"]["MAXIMUM_ORE_COST"].AsInteger.Value   = int.Parse(boxMaxDynite.Text);
                t["advanced"]["ENABLE_DEBUG_LOGS"].AsBoolean.Value  = checkBoxDebugLogs.Checked;

                // Stat Settings
                t["stats"]["CHECK_ATTACK_STAT"].AsBoolean.Value = boxCheckAttack.Checked;
                t["stats"]["CHECK_SPEED_STAT"].AsBoolean.Value  = boxCheckSpeed.Checked;

                // Create TomlNodes for each stat +,=,-
                TomlNode node  = new TomlNode[] { };
                TomlNode node1 = new TomlNode[] { };
                TomlNode node2 = new TomlNode[] { };
                TomlNode node3 = new TomlNode[] { };
                TomlNode node4 = new TomlNode[] { };
                TomlNode node5 = new TomlNode[] { };

                // Get all values from the array into int and add it to the node
                for (int i = 0; i < atkPos.Length; i++)
                {
                    node.Add(int.Parse(atkPos[i]));
                }
                for (int i = 0; i < atkNeut.Length; i++)
                {
                    node1.Add(int.Parse(atkNeut[i]));
                }
                for (int i = 0; i < atkNeg.Length; i++)
                {
                    node2.Add(int.Parse(atkNeg[i]));
                }
                for (int i = 0; i < speedPos.Length; i++)
                {
                    node3.Add(int.Parse(speedPos[i]));
                }
                for (int i = 0; i < speedNeut.Length; i++)
                {
                    node4.Add(int.Parse(speedNeut[i]));
                }
                for (int i = 0; i < speedNeg.Length; i++)
                {
                    node5.Add(int.Parse(speedNeg[i]));
                }

                // Stats
                t["stats"]["ATTACK_STATS"]["positive"] = node;
                t["stats"]["ATTACK_STATS"]["neutral"]  = node1;
                t["stats"]["ATTACK_STATS"]["negative"] = node2;
                t["stats"]["SPEED_STATS"]["positive"]  = node3;
                t["stats"]["SPEED_STATS"]["neutral"]   = node4;
                t["stats"]["SPEED_STATS"]["negative"]  = node5;

                // Discord Settings
                t["discord"]["WEBHOOK_ID"].AsString.Value      = boxWebhookID.Text;
                t["discord"]["WEBHOOK_TOKEN"].AsString.Value   = boxWebhookToken.Text;
                t["discord"]["USER_ID"].AsString.Value         = boxUserID.Text;
                t["discord"]["USER_SHORT_NAME"].AsString.Value = boxPingName.Text;
                t["discord"]["UPDATE_LEVELS"].AsString.Value   = boxPingSettings.Text;

                // Game Language Settings
                t["language"]["LANGUAGE"].AsString.Value = boxGameLanguage.Text;

                using (StreamWriter writer = new StreamWriter(File.Open(configData, FileMode.Create)))
                {
                    t.WriteTo(writer);
                    writer.Flush();
                }
            }
        }
        public static List <SettingBase> LoadSettings(string content)
        {
            TomlTable table;

            using (StringReader reader = new StringReader(content))
                table = TOML.Parse(reader);
            List <SettingBase> settingsList = new List <SettingBase>();

            foreach (TomlTable setting in table["settings"])
            {
                SettingBase baseSetting = null;

                if (setting.HasKey("options"))
                {
                    OptionSetting optionSetting = new OptionSetting();
                    baseSetting              = optionSetting;
                    optionSetting.Default    = setting["default"];
                    optionSetting.Value      = optionSetting.Default;
                    optionSetting.StartValue = optionSetting.Default;

                    foreach (TomlTable option in setting["options"])
                    {
                        var opt = new OptionSettingOption();
                        opt.Name = option["name"];
                        if (option.HasKey("help"))
                        {
                            opt.Help = option["help"];
                        }
                        if (option.HasKey("text"))
                        {
                            opt.Text = option["text"];
                        }
                        else if (opt.Name == optionSetting.Default)
                        {
                            opt.Text = opt.Name + " (Default)";
                        }
                        opt.OptionSetting = optionSetting;
                        optionSetting.Options.Add(opt);
                    }
                }
                else
                {
                    StringSetting stringSetting = new StringSetting();
                    baseSetting           = stringSetting;
                    stringSetting.Default = setting.HasKey("default") ? setting["default"].ToString() : "";
                }

                baseSetting.Name   = setting["name"];
                baseSetting.Filter = setting["filter"];

                if (setting.HasKey("help"))
                {
                    baseSetting.Help = setting["help"];
                }
                if (setting.HasKey("helpurl"))
                {
                    baseSetting.HelpURL = setting["helpurl"];
                }
                if (setting.HasKey("width"))
                {
                    baseSetting.Width = setting["width"];
                }
                if (setting.HasKey("type"))
                {
                    baseSetting.Type = setting["type"];
                }

                settingsList.Add(baseSetting);
            }
            return(settingsList);
        }
Exemple #13
0
        public static List <SettingBase> LoadSettings(string filepath)
        {
            TomlTable table;

            using (StreamReader reader = new StreamReader(File.OpenRead(filepath)))
                table = TOML.Parse(reader);
            List <SettingBase> settingsList = new List <SettingBase>();

            foreach (TomlTable setting in table["settings"])
            {
                SettingBase baseSetting = null;

                if (setting.HasKey("options"))
                {
                    OptionSetting optionSetting = new OptionSetting();
                    baseSetting           = optionSetting;
                    optionSetting.Default = setting["default"];
                    optionSetting.Value   = optionSetting.Default;

                    foreach (TomlTable option in setting["options"])
                    {
                        var opt = new OptionSettingOption();
                        opt.Name = option["name"];
                        if (option.HasKey("help"))
                        {
                            opt.Help = option["help"];
                        }
                        if (option.HasKey("text"))
                        {
                            opt.Text = option["text"];
                        }
                        else if (opt.Name == optionSetting.Default)
                        {
                            opt.Text = opt.Name + " (Default)";
                        }
                        opt.OptionSetting = optionSetting;
                        optionSetting.Options.Add(opt);
                    }
                }
                else if (setting["default"].IsString)
                {
                    StringSetting stringSetting = new StringSetting();
                    baseSetting           = stringSetting;
                    stringSetting.Default = setting["default"];
                    if (setting.HasKey("folder"))
                    {
                        stringSetting.IsFolder = true;
                    }
                }

                baseSetting.Name   = setting["name"];
                baseSetting.Filter = setting["filter"];
                if (setting.HasKey("help"))
                {
                    baseSetting.Help = setting["help"];
                }
                if (setting.HasKey("helpurl"))
                {
                    baseSetting.HelpURL = setting["helpurl"];
                }
                if (setting.HasKey("alias"))
                {
                    baseSetting.Alias = setting["alias"];
                }
                if (setting.HasKey("width"))
                {
                    baseSetting.Width = setting["width"];
                }
                settingsList.Add(baseSetting);
            }
            return(settingsList);
        }
Exemple #14
0
 public static TomlTable CreateTomlTable(string input)
 {
     using var reader = new StringReader(input);
     return(TOML.Parse(reader));
 }
Exemple #15
0
        private static SynoCtrlConfig Parse(string content)
        {
            using (var reader = new StringReader(content))
            {
                TomlTable data;

                try
                {
                    data = TOML.Parse(reader);
                }
                catch (TomlParseException e)
                {
                    throw new SynoCtrlConfigParseException("Error in Toml Syntax: " + e.Message);
                }

                string defaultName = null;
                List <SingleDeviceConfig> devices = new List <SingleDeviceConfig>();

                if (data.HasKey("Default"))
                {
                    if (data["Default"] is TomlString s)
                    {
                        if (!string.IsNullOrWhiteSpace(s))
                        {
                            defaultName = s;
                        }
                    }
                    else
                    {
                        throw new SynoCtrlConfigParseException("Key [Default] must be a string");
                    }
                }

                if (data["Device"] is TomlArray a)
                {
                    foreach (TomlNode n in a)
                    {
                        if (n is TomlTable t)
                        {
                            string cfgName = null;
                            if (!t.HasKey("Name"))
                            {
                                throw new SynoCtrlConfigParseException("Missing key [Name]");
                            }
                            if (t["Name"] is TomlString vName)
                            {
                                cfgName = vName;
                            }

                            var cfg = new SingleDeviceConfig(cfgName, false);

                            if (t.HasKey("IP"))
                            {
                                if (t["IP"]       is TomlString vIP)
                                {
                                    cfg.IPAddress = vIP.Value.Trim();
                                }
                                else
                                {
                                    throw new SynoCtrlConfigParseException("Key [IP] must be a string");
                                }
                            }
                            if (t.HasKey("Mac"))
                            {
                                if (t["Mac"]      is TomlString vMac)
                                {
                                    cfg.MACAddress = vMac.Value.Trim();
                                }
                                else
                                {
                                    throw new SynoCtrlConfigParseException("Key [Mac] must be a string");
                                }
                            }
                            if (t.HasKey("Username"))
                            {
                                if (t["Username"] is TomlString vUsername)
                                {
                                    cfg.Username = vUsername.Value.Trim();
                                }
                                else
                                {
                                    throw new SynoCtrlConfigParseException("Key [Username] must be a string");
                                }
                            }
                            if (t.HasKey("Password"))
                            {
                                if (t["Password"] is TomlString vPassword)
                                {
                                    cfg.Password = vPassword.Value.Trim();
                                }
                                else
                                {
                                    throw new SynoCtrlConfigParseException("Key [Password] must be a string");
                                }
                            }
                            if (t.HasKey("Port"))
                            {
                                if (t["Port"]     is TomlInteger vPort)
                                {
                                    cfg.Port = vPort.Value;
                                }
                                else
                                {
                                    throw new SynoCtrlConfigParseException("Key [Password] must be a string");
                                }
                            }
                            if (t.HasKey("HTTPS"))
                            {
                                if (t["HTTPS"]    is TomlBoolean vTLS)
                                {
                                    cfg.UseTLS = vTLS.Value;
                                }
                                else
                                {
                                    throw new SynoCtrlConfigParseException("Key [Password] must be a string");
                                }
                            }

                            devices.Add(cfg);
                        }
                    }
                }

                var result = new SynoCtrlConfig {
                    _configs = devices
                };
                if (defaultName != null)
                {
                    result._default = result._configs.FirstOrDefault(c => string.Equals(c.Name, defaultName, StringComparison.CurrentCultureIgnoreCase));
                    if (result._default == null)
                    {
                        throw new SynoCtrlConfigParseException($"Device '{defaultName}' not found");
                    }
                }
                else
                {
                    result._default = new SingleDeviceConfig("%%AutoGenerated%%", true);
                    result._configs.Add(result._default);
                }

                if (SynoCtrlProgram.Arguments["<name>"] != null)
                {
                    var selName = $"{SynoCtrlProgram.Arguments["<name>"].Value}";
                    result.Selected = result._configs.FirstOrDefault(c => string.Equals(c.Name, selName, StringComparison.CurrentCultureIgnoreCase));
                    if (result.Selected == null)
                    {
                        throw new SynoCtrlConfigParseException($"Device '{selName}' not found");
                    }
                }
                else
                {
                    result.Selected = result._default;
                }

                return(result);
            }
        }
        private JObject ReadVideoDataInfoToml(string pathToml)
        {
            TomlTable tinfo;

            try
            {
                tinfo = TOML.Parse(new StringReader(File.ReadAllText(pathToml)));
            }
            catch (Exception e)
            {
                throw new Exception($"Could not parse file: '{pathToml}'", e);
            }

            var uid           = tinfo.HasKey("id")            ? tinfo["id"].AsString.Value                                                        : null;
            var title         = tinfo.HasKey("title")         ? tinfo["title"].AsString.Value                                                     : null;
            var extrac        = tinfo.HasKey("extractor_key") ? tinfo["extractor_key"].AsString.Value                                             : null;
            var upload_date   = tinfo.HasKey("upload_date")   ? tinfo["upload_date"].AsString.Value                                               : null;
            var like_count    = tinfo.HasKey("like_count")    ? (int?)tinfo["like_count"].AsInteger.Value                                         : null;
            var dislike_count = tinfo.HasKey("dislike_count") ? (int?)tinfo["dislike_count"].AsInteger.Value                                      : null;
            var uploader      = tinfo.HasKey("uploader")      ? tinfo["uploader"].AsString.Value                                                  : null;
            var duration      = tinfo.HasKey("duration")      ? (int?)tinfo["duration"].AsFloat?.Value ?? (int?)tinfo["duration"].AsInteger.Value : null;
            var webpage_url   = tinfo.HasKey("webpage_url")   ? tinfo["webpage_url"].AsString.Value                                               : null;
            var view_count    = tinfo.HasKey("view_count")    ? (int?)tinfo["view_count"].AsInteger.Value                                         : null;
            var width         = tinfo.HasKey("width")         ? (int?)tinfo["width"].AsInteger.Value                                              : null;
            var height        = tinfo.HasKey("height")        ? (int?)tinfo["height"].AsInteger.Value                                             : null;

            var dir = Path.GetDirectoryName(pathToml);

            if (dir == null)
            {
                return(null);
            }

            var filenameToml = Path.GetFileName(pathToml);

            var filenameBase = filenameToml.Substring(0, filenameToml.Length - ".info.toml".Length);

            var pathVideo = Program.ExtVideo.Select(ext => Path.Combine(dir, filenameBase + "." + ext)).FirstOrDefault(p => _datafiles.Contains(p));

            if (pathVideo == null)
            {
                return(null);
            }

            var meta = new JProperty("meta", new JObject
                                     (
                                         new JProperty("path_toml", pathToml)
                                     ));

            if (uid != null)
            {
                meta.Value["uid"] = uid;
            }
            if (uid != null)
            {
                meta.Value["ext_order_id"] = uid;
            }

            var data = new JProperty("data", new JObject
                                     (
                                         new JProperty("info", new JObject())
                                     ));

            if (title != null)
            {
                data.Value["title"] = title;
            }
            if (extrac != null)
            {
                data.Value["info"]["extractor_key"] = extrac;
            }
            if (upload_date != null)
            {
                data.Value["info"]["upload_date"] = upload_date;
            }
            if (like_count != null)
            {
                data.Value["info"]["like_count"] = like_count;
            }
            if (dislike_count != null)
            {
                data.Value["info"]["dislike_count"] = dislike_count;
            }
            if (uploader != null)
            {
                data.Value["info"]["uploader"] = uploader;
            }
            if (duration != null)
            {
                data.Value["info"]["duration"] = duration;
            }
            if (webpage_url != null)
            {
                data.Value["info"]["webpage_url"] = webpage_url;
            }
            if (view_count != null)
            {
                data.Value["info"]["view_count"] = view_count;
            }
            if (width != null)
            {
                data.Value["info"]["width"] = width;
            }
            if (height != null)
            {
                data.Value["info"]["height"] = height;
            }

            var vidData = new JObject(meta, data);

            return(vidData);
        }