From c7924ca2b6cf7df572de98db1092cbb6d5365d1d Mon Sep 17 00:00:00 2001 From: database64128 Date: Tue, 20 Oct 2020 15:31:28 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Cleanup=20and=20fix=20dependenci?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/Service/UpdateChecker.cs | 9 - shadowsocks-csharp/Model/NlogConfig.cs | 2 +- shadowsocks-csharp/View/MenuViewController.cs | 84 +------ .../View/OnlineConfigForm.Designer.cs | 218 ------------------ shadowsocks-csharp/View/OnlineConfigForm.cs | 153 ------------ shadowsocks-csharp/View/OnlineConfigForm.resx | 120 ---------- shadowsocks-csharp/shadowsocks-csharp.csproj | 22 +- 7 files changed, 20 insertions(+), 588 deletions(-) delete mode 100644 shadowsocks-csharp/View/OnlineConfigForm.Designer.cs delete mode 100644 shadowsocks-csharp/View/OnlineConfigForm.cs delete mode 100644 shadowsocks-csharp/View/OnlineConfigForm.resx diff --git a/shadowsocks-csharp/Controller/Service/UpdateChecker.cs b/shadowsocks-csharp/Controller/Service/UpdateChecker.cs index 39d091b7..8ece7da9 100644 --- a/shadowsocks-csharp/Controller/Service/UpdateChecker.cs +++ b/shadowsocks-csharp/Controller/Service/UpdateChecker.cs @@ -32,15 +32,6 @@ namespace Shadowsocks.Controller public string NewReleaseVersion { get; private set; } public string NewReleaseZipFilename { get; private set; } - private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) - { - CheckUpdateTimer timer = (CheckUpdateTimer)sender; - Configuration config = timer.config; - timer.Elapsed -= Timer_Elapsed; - timer.Enabled = false; - timer.Dispose(); - CheckUpdate(config); - } public event EventHandler CheckUpdateCompleted; public static readonly string Version = Assembly.GetEntryAssembly().GetName().Version.ToString(); diff --git a/shadowsocks-csharp/Model/NlogConfig.cs b/shadowsocks-csharp/Model/NlogConfig.cs index cbee2496..65384b10 100644 --- a/shadowsocks-csharp/Model/NlogConfig.cs +++ b/shadowsocks-csharp/Model/NlogConfig.cs @@ -25,7 +25,7 @@ namespace Shadowsocks.Model { get { - if (_NLOG_CONFIG_FILE_NAME.IsNullOrEmpty()) + if (string.IsNullOrEmpty(_NLOG_CONFIG_FILE_NAME)) { _NLOG_CONFIG_FILE_NAME = Path.Combine(Environment.CurrentDirectory, "NLog.config"); } diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 7565db36..12801cff 100644 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -460,7 +460,7 @@ namespace Shadowsocks.View } } - void notifyIcon1_BalloonTipClicked(object sender, EventArgs e) + private void CheckUpdateForFirstRun() { Configuration config = controller.GetCurrentConfiguration(); if (config.firstRun) @@ -604,80 +604,6 @@ namespace Shadowsocks.View disableItem.Checked = !controller.GetCurrentConfiguration().enabled; } - private void CheckUpdateForFirstRun() - { - Configuration config = controller.GetConfigurationCopy(); - if (config.isDefault) return; - _isStartupChecking = true; - updateChecker.CheckUpdate(config, 3000); - } - - #endregion - - #region Main menu - - void controller_ShareOverLANStatusChanged(object sender, EventArgs e) - { - ShareOverLANItem.Checked = controller.GetConfigurationCopy().shareOverLan; - } - - private void proxyItem_Click(object sender, EventArgs e) - { - ShowProxyForm(); - } - - private void OnlineConfig_Click(object sender, EventArgs e) - { - ShowOnlineConfigForm(); - } - - private void hotKeyItem_Click(object sender, EventArgs e) - { - ShowHotKeySettingsForm(); - } - - private void ShareOverLANItem_Click(object sender, EventArgs e) - { - ShareOverLANItem.Checked = !ShareOverLANItem.Checked; - controller.ToggleShareOverLAN(ShareOverLANItem.Checked); - } - - private void AutoStartupItem_Click(object sender, EventArgs e) - { - AutoStartupItem.Checked = !AutoStartupItem.Checked; - if (!AutoStartup.Set(AutoStartupItem.Checked)) - { - MessageBox.Show(I18N.GetString("Failed to update registry")); - } - LoadCurrentConfiguration(); - } - - private void ProtocolHandlerItem_Click(object sender, EventArgs e) - { - ProtocolHandlerItem.Checked = !ProtocolHandlerItem.Checked; - if (!ProtocolHandler.Set(ProtocolHandlerItem.Checked)) - { - MessageBox.Show(I18N.GetString("Failed to update registry")); - } - LoadCurrentConfiguration(); - } - - private void Quit_Click(object sender, EventArgs e) - { - controller.Stop(); - _notifyIcon.Visible = false; - Application.Exit(); - } - - #endregion - - #region System proxy - - private void controller_EnableStatusChanged(object sender, EventArgs e) - { - disableItem.Checked = !controller.GetConfigurationCopy().enabled; - } - private void EnableItem_Click(object sender, EventArgs e) { controller.ToggleEnable(false); @@ -757,8 +683,9 @@ namespace Shadowsocks.View Configuration configuration = controller.GetCurrentConfiguration(); foreach (var server in configuration.configs) { - if (Configuration.ChecksServer(server)) + try { + Configuration.CheckServer(server); var name = server.ToString(); if (!items.OfType().Any(ts => ts.Text == name)) { @@ -769,6 +696,9 @@ namespace Shadowsocks.View serverCount++; } } + catch + { + } } foreach (var item in items) @@ -807,7 +737,7 @@ namespace Shadowsocks.View ShowConfigForm(); } - void openURLFromQRCode(object sender, FormClosedEventArgs e) + void openURLFromQRCode() { Utils.OpenInBrowser(_urlToOpen); } diff --git a/shadowsocks-csharp/View/OnlineConfigForm.Designer.cs b/shadowsocks-csharp/View/OnlineConfigForm.Designer.cs deleted file mode 100644 index d9787dde..00000000 --- a/shadowsocks-csharp/View/OnlineConfigForm.Designer.cs +++ /dev/null @@ -1,218 +0,0 @@ -namespace Shadowsocks.View -{ - partial class OnlineConfigForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); - this.UrlListBox = new System.Windows.Forms.ListBox(); - this.label1 = new System.Windows.Forms.Label(); - this.UrlTextBox = new System.Windows.Forms.TextBox(); - this.UpdateButton = new System.Windows.Forms.Button(); - this.AddButton = new System.Windows.Forms.Button(); - this.DeleteButton = 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(); - // - // tableLayoutPanel1 - // - this.tableLayoutPanel1.ColumnCount = 3; - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); - this.tableLayoutPanel1.Controls.Add(this.UrlListBox, 0, 0); - this.tableLayoutPanel1.Controls.Add(this.label1, 0, 1); - this.tableLayoutPanel1.Controls.Add(this.UrlTextBox, 1, 1); - this.tableLayoutPanel1.Controls.Add(this.UpdateButton, 0, 2); - this.tableLayoutPanel1.Controls.Add(this.AddButton, 1, 2); - this.tableLayoutPanel1.Controls.Add(this.DeleteButton, 2, 2); - this.tableLayoutPanel1.Controls.Add(this.OkButton, 1, 3); - this.tableLayoutPanel1.Controls.Add(this.UpdateAllButton, 0, 3); - this.tableLayoutPanel1.Controls.Add(this.CancelButton, 2, 3); - this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; - this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); - this.tableLayoutPanel1.Name = "tableLayoutPanel1"; - this.tableLayoutPanel1.Padding = new System.Windows.Forms.Padding(3); - this.tableLayoutPanel1.RowCount = 4; - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel1.Size = new System.Drawing.Size(482, 453); - this.tableLayoutPanel1.TabIndex = 0; - // - // UrlListBox - // - this.tableLayoutPanel1.SetColumnSpan(this.UrlListBox, 3); - this.UrlListBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.UrlListBox.FormattingEnabled = true; - this.UrlListBox.ItemHeight = 15; - this.UrlListBox.Location = new System.Drawing.Point(13, 13); - this.UrlListBox.Margin = new System.Windows.Forms.Padding(10); - this.UrlListBox.Name = "UrlListBox"; - this.UrlListBox.Size = new System.Drawing.Size(456, 334); - this.UrlListBox.TabIndex = 0; - this.UrlListBox.SelectedIndexChanged += new System.EventHandler(this.UrlListBox_SelectedIndexChanged); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Dock = System.Windows.Forms.DockStyle.Fill; - this.label1.Location = new System.Drawing.Point(6, 357); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(152, 31); - this.label1.TabIndex = 1; - this.label1.Text = "Online config URL"; - this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight; - // - // UrlTextBox - // - this.tableLayoutPanel1.SetColumnSpan(this.UrlTextBox, 2); - this.UrlTextBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.UrlTextBox.Location = new System.Drawing.Point(164, 360); - this.UrlTextBox.Margin = new System.Windows.Forms.Padding(3, 3, 15, 3); - this.UrlTextBox.Name = "UrlTextBox"; - this.UrlTextBox.Size = new System.Drawing.Size(300, 25); - this.UrlTextBox.TabIndex = 2; - // - // UpdateButton - // - this.UpdateButton.Dock = System.Windows.Forms.DockStyle.Fill; - this.UpdateButton.Location = new System.Drawing.Point(23, 391); - this.UpdateButton.Margin = new System.Windows.Forms.Padding(20, 3, 20, 3); - this.UpdateButton.MaximumSize = new System.Drawing.Size(0, 25); - this.UpdateButton.MinimumSize = new System.Drawing.Size(0, 25); - this.UpdateButton.Name = "UpdateButton"; - this.UpdateButton.Size = new System.Drawing.Size(118, 25); - this.UpdateButton.TabIndex = 3; - this.UpdateButton.Text = "&Update"; - this.UpdateButton.UseVisualStyleBackColor = true; - this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); - // - // AddButton - // - this.AddButton.Dock = System.Windows.Forms.DockStyle.Fill; - this.AddButton.Location = new System.Drawing.Point(181, 391); - this.AddButton.Margin = new System.Windows.Forms.Padding(20, 3, 20, 3); - this.AddButton.MaximumSize = new System.Drawing.Size(0, 25); - this.AddButton.MinimumSize = new System.Drawing.Size(0, 25); - this.AddButton.Name = "AddButton"; - this.AddButton.Size = new System.Drawing.Size(118, 25); - this.AddButton.TabIndex = 4; - this.AddButton.Text = "&Add"; - this.AddButton.UseVisualStyleBackColor = true; - this.AddButton.Click += new System.EventHandler(this.AddButton_Click); - // - // DeleteButton - // - this.DeleteButton.Dock = System.Windows.Forms.DockStyle.Fill; - this.DeleteButton.Location = new System.Drawing.Point(339, 391); - this.DeleteButton.Margin = new System.Windows.Forms.Padding(20, 3, 20, 3); - this.DeleteButton.MaximumSize = new System.Drawing.Size(0, 25); - this.DeleteButton.MinimumSize = new System.Drawing.Size(0, 25); - this.DeleteButton.Name = "DeleteButton"; - this.DeleteButton.Size = new System.Drawing.Size(120, 25); - this.DeleteButton.TabIndex = 5; - this.DeleteButton.Text = "&Delete"; - this.DeleteButton.UseVisualStyleBackColor = true; - this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); - // - // OkButton - // - this.OkButton.Dock = System.Windows.Forms.DockStyle.Fill; - this.OkButton.Location = new System.Drawing.Point(181, 422); - this.OkButton.Margin = new System.Windows.Forms.Padding(20, 3, 20, 3); - this.OkButton.MaximumSize = new System.Drawing.Size(0, 25); - this.OkButton.MinimumSize = new System.Drawing.Size(0, 25); - this.OkButton.Name = "OkButton"; - this.OkButton.Size = new System.Drawing.Size(118, 25); - this.OkButton.TabIndex = 7; - this.OkButton.Text = "OK"; - this.OkButton.UseVisualStyleBackColor = true; - this.OkButton.Click += new System.EventHandler(this.OkButton_Click); - // - // UpdateAllButton - // - this.UpdateAllButton.Dock = System.Windows.Forms.DockStyle.Fill; - this.UpdateAllButton.Location = new System.Drawing.Point(23, 422); - this.UpdateAllButton.Margin = new System.Windows.Forms.Padding(20, 3, 20, 3); - this.UpdateAllButton.MaximumSize = new System.Drawing.Size(0, 25); - this.UpdateAllButton.MinimumSize = new System.Drawing.Size(0, 25); - this.UpdateAllButton.Name = "UpdateAllButton"; - this.UpdateAllButton.Size = new System.Drawing.Size(118, 25); - this.UpdateAllButton.TabIndex = 6; - this.UpdateAllButton.Text = "U&pdate All"; - this.UpdateAllButton.UseVisualStyleBackColor = true; - this.UpdateAllButton.Click += new System.EventHandler(this.UpdateAllButton_Click); - // - // CancelButton - // - this.CancelButton.Dock = System.Windows.Forms.DockStyle.Fill; - this.CancelButton.Location = new System.Drawing.Point(339, 422); - this.CancelButton.Margin = new System.Windows.Forms.Padding(20, 3, 20, 3); - this.CancelButton.MaximumSize = new System.Drawing.Size(0, 25); - this.CancelButton.MinimumSize = new System.Drawing.Size(0, 25); - this.CancelButton.Name = "CancelButton"; - this.CancelButton.Size = new System.Drawing.Size(120, 25); - this.CancelButton.TabIndex = 8; - this.CancelButton.Text = "Cancel"; - this.CancelButton.UseVisualStyleBackColor = true; - this.CancelButton.Click += new System.EventHandler(this.CancelButton_Click); - // - // OnlineConfigForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(482, 453); - this.Controls.Add(this.tableLayoutPanel1); - this.MinimizeBox = false; - this.MinimumSize = new System.Drawing.Size(400, 400); - this.Name = "OnlineConfigForm"; - this.Text = "Online config"; - this.tableLayoutPanel1.ResumeLayout(false); - this.tableLayoutPanel1.PerformLayout(); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; - private System.Windows.Forms.ListBox UrlListBox; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.TextBox UrlTextBox; - private System.Windows.Forms.Button UpdateButton; - private System.Windows.Forms.Button AddButton; - private System.Windows.Forms.Button DeleteButton; - private System.Windows.Forms.Button OkButton; - private System.Windows.Forms.Button UpdateAllButton; - private System.Windows.Forms.Button CancelButton; - } -} \ No newline at end of file diff --git a/shadowsocks-csharp/View/OnlineConfigForm.cs b/shadowsocks-csharp/View/OnlineConfigForm.cs deleted file mode 100644 index fca0ed57..00000000 --- a/shadowsocks-csharp/View/OnlineConfigForm.cs +++ /dev/null @@ -1,153 +0,0 @@ -using System; -using System.Data; -using System.Linq; -using System.Windows.Forms; -using Shadowsocks.Controller; -using Shadowsocks.Model; -using Shadowsocks.Properties; - -namespace Shadowsocks.View -{ - public partial class OnlineConfigForm : Form - { - private ShadowsocksController controller; - private Configuration config; - - public OnlineConfigForm(ShadowsocksController controller) - { - this.controller = controller; - InitializeComponent(); - LoadConfig(); - Icon = System.Drawing.Icon.FromHandle(Resources.ssw128.GetHicon()); - I18N.TranslateForm(this); - } - - private void LoadConfig() - { - config = controller.GetConfigurationCopy(); - var idx = UrlListBox.SelectedIndex; - UrlListBox.Items.Clear(); - - foreach (var item in config.onlineConfigSource) - { - UrlListBox.Items.Add(item); - } - - if (idx >= UrlListBox.Items.Count) idx = 0; - if (idx < 0 && UrlListBox.Items.Count > 0) idx = 0; - if (UrlListBox.Items.Count == 0) return; - UrlListBox.SelectedIndex = idx; - SelectItem(); - } - - private void SelectItem() - { - UrlTextBox.Text = (string)UrlListBox.SelectedItem; - } - - private bool ValidateUrl() - { - try - { - var scheme = new Uri(UrlTextBox.Text).Scheme; - if (scheme != "http" && scheme != "https") return false; - if (UrlListBox.Items.OfType().Contains(UrlTextBox.Text)) return false; - } - catch - { - return false; - } - return true; - } - - private void Commit() - { - if (UrlListBox.SelectedIndex < 0) return; - if ((string)UrlListBox.SelectedItem == UrlTextBox.Text) - { - LoadConfig(); - return; - } - - if (ValidateUrl()) - { - - UrlListBox.Items[UrlListBox.SelectedIndex] = UrlTextBox.Text; - } - controller.SaveOnlineConfigSource(UrlListBox.Items.OfType().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct()); - LoadConfig(); - return; - } - - private void AddButton_Click(object sender, EventArgs e) - { - if (string.IsNullOrWhiteSpace(UrlTextBox.Text)) return; - UrlListBox.Items.Add(UrlTextBox.Text); - UrlListBox.SelectedIndex = UrlListBox.Items.Count - 1; - UrlTextBox.Text = ""; - Commit(); - } - - private async void UpdateButton_Click(object sender, EventArgs e) - { - string old = (string)UrlListBox.SelectedItem; - // update content, also update online config - Commit(); - string current = (string)UrlListBox.SelectedItem; - if (UrlListBox.Items.Count == 0) return; - tableLayoutPanel1.Enabled = false; - bool ok = await controller.UpdateOnlineConfig(current); - if (!ok) - { - MessageBox.Show(I18N.GetString("online config failed to update")); - tableLayoutPanel1.Enabled = true; - return; - } - if (old != current) controller.RemoveOnlineConfig(old); - tableLayoutPanel1.Enabled = true; - } - - private void UrlListBox_SelectedIndexChanged(object sender, EventArgs e) - { - if (!UrlListBox.CanSelect) - { - return; - } - SelectItem(); - } - - private void DeleteButton_Click(object sender, EventArgs e) - { - if (UrlListBox.Items.Count == 0) return; - string url = (string)UrlListBox.SelectedItem; - if (!string.IsNullOrWhiteSpace(url)) - { - controller.RemoveOnlineConfig(url); - } - LoadConfig(); - } - - private async void UpdateAllButton_Click(object sender, EventArgs e) - { - if (UrlListBox.Items.Count == 0) return; - tableLayoutPanel1.Enabled = false; - int fail = await controller.UpdateAllOnlineConfig(); - if (fail > 0) - { - MessageBox.Show(I18N.GetString("{0} online config failed to update", fail)); - } - tableLayoutPanel1.Enabled = true; - } - - private void OkButton_Click(object sender, EventArgs e) - { - Commit(); - Close(); - } - - private void CancelButton_Click(object sender, EventArgs e) - { - Close(); - } - } -} diff --git a/shadowsocks-csharp/View/OnlineConfigForm.resx b/shadowsocks-csharp/View/OnlineConfigForm.resx deleted file mode 100644 index 1af7de15..00000000 --- a/shadowsocks-csharp/View/OnlineConfigForm.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 7db867be..238bb61a 100644 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -4,6 +4,7 @@ WinExe netcoreapp3.1 Shadowsocks + true true clowwindy & community 2020 Shadowsocks @@ -76,22 +77,23 @@ - - all + runtime; build; native; contentfiles; analyzers; buildtransitive - + + - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + + + + +