You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConfigForm.cs 3.8 kB

12 years ago
12 years ago
12 years ago
10 years ago
12 years ago
12 years ago
10 years ago
10 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
10 years ago
10 years ago
10 years ago
10 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. using System.Diagnostics;
  8. using shadowsocks_csharp.Controller;
  9. using shadowsocks_csharp.Model;
  10. namespace shadowsocks_csharp.View
  11. {
  12. public partial class ConfigForm : Form
  13. {
  14. ShadowsocksController controller;
  15. public ConfigForm(ShadowsocksController controller)
  16. {
  17. InitializeComponent();
  18. notifyIcon1.ContextMenu = contextMenu1;
  19. this.controller = controller;
  20. controller.EnableStatusChanged += controller_EnableStatusChanged;
  21. controller.ConfigChanged += controller_ConfigChanged;
  22. updateUI();
  23. }
  24. private void controller_ConfigChanged(object sender, EventArgs e)
  25. {
  26. updateUI();
  27. }
  28. private void controller_EnableStatusChanged(object sender, EventArgs e)
  29. {
  30. updateUI();
  31. }
  32. private void showWindow()
  33. {
  34. this.Opacity = 1;
  35. this.Show();
  36. }
  37. private void updateUI()
  38. {
  39. Config config = controller.GetConfig();
  40. textBox1.Text = config.server;
  41. textBox2.Text = config.server_port.ToString();
  42. textBox3.Text = config.password;
  43. textBox4.Text = config.local_port.ToString();
  44. comboBox1.Text = config.method == null ? "aes-256-cfb" : config.method;
  45. enableItem.Checked = config.enabled;
  46. }
  47. private void Form1_Load(object sender, EventArgs e)
  48. {
  49. if (!controller.GetConfig().isDefault)
  50. {
  51. this.Opacity = 0;
  52. BeginInvoke(new MethodInvoker(delegate
  53. {
  54. this.Hide();
  55. }));
  56. }
  57. }
  58. private void Config_Click(object sender, EventArgs e)
  59. {
  60. showWindow();
  61. }
  62. private void Quit_Click(object sender, EventArgs e)
  63. {
  64. this.Close();
  65. }
  66. private void OKButton_Click(object sender, EventArgs e)
  67. {
  68. try
  69. {
  70. Config config = new Config
  71. {
  72. server = textBox1.Text,
  73. server_port = int.Parse(textBox2.Text),
  74. password = textBox3.Text,
  75. local_port = int.Parse(textBox4.Text),
  76. method = comboBox1.Text,
  77. isDefault = false
  78. };
  79. controller.SaveConfig(config);
  80. this.Hide();
  81. }
  82. catch (FormatException)
  83. {
  84. MessageBox.Show("illegal port number format");
  85. }
  86. catch (Exception ex)
  87. {
  88. MessageBox.Show(ex.Message);
  89. }
  90. }
  91. private void cancelButton_Click(object sender, EventArgs e)
  92. {
  93. this.Hide();
  94. updateUI();
  95. }
  96. private void Form1_FormClosed(object sender, FormClosedEventArgs e)
  97. {
  98. controller.Stop();
  99. }
  100. private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
  101. {
  102. Process.Start("https://github.com/clowwindy/shadowsocks-csharp");
  103. }
  104. private void notifyIcon1_DoubleClick(object sender, EventArgs e)
  105. {
  106. showWindow();
  107. }
  108. private void EnableItem_Click(object sender, EventArgs e)
  109. {
  110. enableItem.Checked = !enableItem.Checked;
  111. controller.ToggleEnable(enableItem.Checked);
  112. }
  113. }
  114. }