diff --git a/shadowsocks-csharp/Controller/Service/OnlineConfigResolver.cs b/shadowsocks-csharp/Controller/Service/OnlineConfigResolver.cs index 480dc366..fe3e16c1 100644 --- a/shadowsocks-csharp/Controller/Service/OnlineConfigResolver.cs +++ b/shadowsocks-csharp/Controller/Service/OnlineConfigResolver.cs @@ -29,7 +29,12 @@ namespace Shadowsocks.Controller.Service try { string str = await httpClient.GetStringAsync(url); - return Get(str); + var ret = Get(str); + foreach (var item in ret) + { + item.group = url; + } + return ret; } catch (Exception e) { @@ -62,11 +67,9 @@ namespace Shadowsocks.Controller.Service { var l = new List(); if (o == null) return l; - try - { + if (IsServerObject(o)) return new List { o.ToObject() }; - } - catch { }; + foreach (var kv in o) { JToken v = kv.Value; @@ -87,5 +90,10 @@ namespace Shadowsocks.Controller.Service return SearchJArray(t as JArray); } } + + private static bool IsServerObject(JObject o) + { + return new[] { "server", "server_port", "password", "method" }.All(i => o.ContainsKey(i)); + } } } diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 2728b3d0..c2f8e0d4 100644 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -698,7 +698,7 @@ namespace Shadowsocks.Controller .Concat(onlineServer) ); _config.index = _config.configs.IndexOf(selected); - Configuration.Save(_config); + SaveConfig(_config); } public async Task UpdateAllOnlineConfig() @@ -714,7 +714,7 @@ namespace Shadowsocks.Controller .Concat(r.SelectMany(s => s)) ); _config.index = _config.configs.IndexOf(selected); - Configuration.Save(_config); + SaveConfig(_config); } public void SaveOnlineConfigSource(IEnumerable vs) diff --git a/shadowsocks-csharp/View/OnlineConfigForm.Designer.cs b/shadowsocks-csharp/View/OnlineConfigForm.Designer.cs index f80e5ba6..f15503ce 100644 --- a/shadowsocks-csharp/View/OnlineConfigForm.Designer.cs +++ b/shadowsocks-csharp/View/OnlineConfigForm.Designer.cs @@ -35,8 +35,8 @@ this.UpdateButton = new System.Windows.Forms.Button(); this.AddButton = new System.Windows.Forms.Button(); this.DeleteButton = new System.Windows.Forms.Button(); - this.UpdateAllButton = new System.Windows.Forms.Button(); this.OkButton = new System.Windows.Forms.Button(); + this.UpdateAllButton = new System.Windows.Forms.Button(); this.CancelButton = new System.Windows.Forms.Button(); this.tableLayoutPanel1.SuspendLayout(); this.SuspendLayout(); @@ -77,6 +77,7 @@ this.UrlListBox.Name = "UrlListBox"; this.UrlListBox.Size = new System.Drawing.Size(482, 344); this.UrlListBox.TabIndex = 0; + this.UrlListBox.SelectedIndexChanged += new System.EventHandler(this.UrlListBox_SelectedIndexChanged); // // label1 // @@ -110,6 +111,7 @@ this.UpdateButton.TabIndex = 3; this.UpdateButton.Text = "Update"; this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); // // AddButton // @@ -137,19 +139,7 @@ this.DeleteButton.TabIndex = 5; this.DeleteButton.Text = "Delete"; this.DeleteButton.UseVisualStyleBackColor = true; - // - // UpdateAllButton - // - this.UpdateAllButton.Dock = System.Windows.Forms.DockStyle.Fill; - this.UpdateAllButton.Location = new System.Drawing.Point(20, 428); - this.UpdateAllButton.Margin = new System.Windows.Forms.Padding(20, 5, 20, 5); - this.UpdateAllButton.MaximumSize = new System.Drawing.Size(0, 32); - this.UpdateAllButton.MinimumSize = new System.Drawing.Size(0, 32); - this.UpdateAllButton.Name = "UpdateAllButton"; - this.UpdateAllButton.Size = new System.Drawing.Size(122, 32); - this.UpdateAllButton.TabIndex = 6; - this.UpdateAllButton.Text = "Update all"; - this.UpdateAllButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); // // OkButton // @@ -164,6 +154,20 @@ this.OkButton.Text = "OK"; this.OkButton.UseVisualStyleBackColor = true; // + // UpdateAllButton + // + this.UpdateAllButton.Dock = System.Windows.Forms.DockStyle.Fill; + this.UpdateAllButton.Location = new System.Drawing.Point(20, 428); + this.UpdateAllButton.Margin = new System.Windows.Forms.Padding(20, 5, 20, 5); + this.UpdateAllButton.MaximumSize = new System.Drawing.Size(0, 32); + this.UpdateAllButton.MinimumSize = new System.Drawing.Size(0, 32); + this.UpdateAllButton.Name = "UpdateAllButton"; + this.UpdateAllButton.Size = new System.Drawing.Size(122, 32); + this.UpdateAllButton.TabIndex = 6; + this.UpdateAllButton.Text = "Update all"; + this.UpdateAllButton.UseVisualStyleBackColor = true; + this.UpdateAllButton.Click += new System.EventHandler(this.UpdateAllButton_Click); + // // CancelButton // this.CancelButton.Dock = System.Windows.Forms.DockStyle.Fill; diff --git a/shadowsocks-csharp/View/OnlineConfigForm.cs b/shadowsocks-csharp/View/OnlineConfigForm.cs index 782ef65e..0c23be10 100644 --- a/shadowsocks-csharp/View/OnlineConfigForm.cs +++ b/shadowsocks-csharp/View/OnlineConfigForm.cs @@ -39,6 +39,12 @@ namespace Shadowsocks.View if (idx >= UrlListBox.Items.Count) idx = 0; UrlListBox.SelectedIndex = idx; + SelectItem(); + } + + private void SelectItem() + { + UrlTextBox.Text = (string)UrlListBox.SelectedItem; } private bool ValidateUrl() @@ -57,10 +63,11 @@ namespace Shadowsocks.View private bool Commit() { - if (!ValidateUrl()) return false; - - UrlListBox.Items[UrlListBox.SelectedIndex] = UrlTextBox.Text; - controller.SaveOnlineConfigSource(UrlListBox.Items.OfType().Where(s=>!string.IsNullOrWhiteSpace(s))); + if (ValidateUrl()) + { + UrlListBox.Items[UrlListBox.SelectedIndex] = UrlTextBox.Text; + } + controller.SaveOnlineConfigSource(UrlListBox.Items.OfType().Where(s => !string.IsNullOrWhiteSpace(s))); LoadConfig(); return true; } @@ -72,5 +79,34 @@ namespace Shadowsocks.View UrlTextBox.Text = DefaultPrefix; UrlListBox.SelectedIndex = UrlListBox.Items.Count - 1; } + + private void UpdateButton_Click(object sender, EventArgs e) + { + // update content, also update online config + Commit(); + + _ = controller.UpdateOnlineConfig(UrlTextBox.Text); + } + + private void UrlListBox_SelectedIndexChanged(object sender, EventArgs e) + { + if (!UrlListBox.CanSelect) + { + return; + } + SelectItem(); + } + + private void DeleteButton_Click(object sender, EventArgs e) + { + int idx = UrlListBox.SelectedIndex; + UrlListBox.Items.RemoveAt(idx); + Commit(); + } + + private void UpdateAllButton_Click(object sender, EventArgs e) + { + _ = controller.UpdateAllOnlineConfig(); + } } }