Пример #1
0
        public static void SavePluginSettings(string settings, bool enabled, PluginProperty[] properties)
        {
            try
            {
                //Create settings file

                string content = "//This file is automatically generated by the\n" +
                                 "//WebClash binary and should not be modified.\n\n" +
                                 "//ENABLED=" + enabled.ToString().ToLower() + "\n\n";

                //For all properties, add property to content

                for (int p = 0; p < properties.Length; p++)
                {
                    if (properties[p] == null)
                    {
                        continue;
                    }

                    PluginProperty pp = properties[p];

                    switch (pp)
                    {
                    case PluginStringProperty psp:
                        content += "//@string\n";
                        break;

                    case PluginNumberProperty pnp:
                        content += "//@number\n";
                        break;

                    case PluginBoolProperty pbp:
                        content += "//@bool\n";
                        break;
                    }

                    content += "let " + pp.name + " = " + pp.GetValue() + "\n";
                }

                //Write settings

                File.WriteAllText(settings, content);
            }
            catch (Exception exc)
            {
                Logger.Error("Could not save plugin settings: ", exc);
            }
        }