Esempio n. 1
0
        public void BackupOptions()
        {
            if (!IsOptionsSaved())
            {
                MessageBox.Show(I18N.SaveChangeFirst);
                return;
            }

            var serverString = string.Empty;

            foreach (var server in Services.Servers.Instance.GetAllServersOrderByIndex())
            {
                // insert a space in the front for regex matching
                serverString += @" "
                                + VgcApis.Models.Datas.Enums.LinkTypes.v2cfg.ToString()
                                + @"://"
                                + Misc.Utils.Base64Encode(server.GetConfiger().GetConfig())
                                + Environment.NewLine;
            }

            var data = new Dictionary <string, string> {
                { BAK_IMPORT, JsonConvert.SerializeObject(setting.GetGlobalImportItems()) },
                { BAK_SUBSCRIPTION, JsonConvert.SerializeObject(setting.GetSubscriptionItems()) },
                { BAK_SERVERS, serverString },
                { BAK_PLUGINS, setting.AllPluginsSetting },
            };

            VgcApis.Misc.UI.SaveToFile(
                VgcApis.Models.Consts.Files.TxtExt,
                JsonConvert.SerializeObject(data));
        }
Esempio n. 2
0
        string MergeIntoCurSubsItems(string rawSubsSetting)
        {
            var subs = new List <Models.Datas.SubscriptionItem>();

            try
            {
                var items = JsonConvert.DeserializeObject <List <Models.Datas.SubscriptionItem> >(rawSubsSetting);
                if (items != null)
                {
                    subs = items;
                }
            }
            catch { }

            var curSubs = setting.GetSubscriptionItems();
            var urls    = curSubs.Select(s => s.url).ToList();

            curSubs.AddRange(subs.Where(s => !urls.Contains(s.url)));
            var sorted = curSubs.OrderBy(s => s.alias).ToList();

            return(JsonConvert.SerializeObject(sorted));
        }