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 4.5 kB

12 years ago
10 years ago
12 years ago
10 years ago
12 years ago
10 years ago
12 years ago
12 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 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
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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.Controller;
  9. using Shadowsocks.Model;
  10. namespace Shadowsocks.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. controller.PACFileReadyToOpen += controller_PACFileReadyToOpen;
  23. updateUI();
  24. }
  25. private void controller_ConfigChanged(object sender, EventArgs e)
  26. {
  27. updateUI();
  28. }
  29. private void controller_EnableStatusChanged(object sender, EventArgs e)
  30. {
  31. updateUI();
  32. }
  33. void controller_PACFileReadyToOpen(object sender, ShadowsocksController.PathEventArgs e)
  34. {
  35. string argument = @"/select, " + e.Path;
  36. System.Diagnostics.Process.Start("explorer.exe", argument);
  37. }
  38. private void showWindow()
  39. {
  40. this.Opacity = 1;
  41. this.Show();
  42. }
  43. private void updateUI()
  44. {
  45. Server server = controller.GetCurrentServer();
  46. IPTextBox.Text = server.server;
  47. ServerPortTextBox.Text = server.server_port.ToString();
  48. PasswordTextBox.Text = server.password;
  49. ProxyPortTextBox.Text = server.local_port.ToString();
  50. EncryptionSelect.Text = server.method == null ? "aes-256-cfb" : server.method;
  51. enableItem.Checked = controller.GetConfiguration().enabled;
  52. }
  53. private void CinfigForm_Load(object sender, EventArgs e)
  54. {
  55. if (!controller.GetConfiguration().isDefault)
  56. {
  57. this.Opacity = 0;
  58. BeginInvoke(new MethodInvoker(delegate
  59. {
  60. this.Hide();
  61. }));
  62. }
  63. }
  64. private void Config_Click(object sender, EventArgs e)
  65. {
  66. showWindow();
  67. }
  68. private void Quit_Click(object sender, EventArgs e)
  69. {
  70. this.Close();
  71. }
  72. private void OKButton_Click(object sender, EventArgs e)
  73. {
  74. try
  75. {
  76. Server server = new Server
  77. {
  78. server = IPTextBox.Text,
  79. server_port = int.Parse(ServerPortTextBox.Text),
  80. password = PasswordTextBox.Text,
  81. local_port = int.Parse(ProxyPortTextBox.Text),
  82. method = EncryptionSelect.Text
  83. };
  84. Configuration config = controller.GetConfiguration();
  85. config.configs.Clear();
  86. config.configs.Add(server);
  87. config.index = 0;
  88. controller.SaveConfig(config);
  89. this.Hide();
  90. }
  91. catch (FormatException)
  92. {
  93. MessageBox.Show("illegal port number format");
  94. }
  95. catch (Exception ex)
  96. {
  97. MessageBox.Show(ex.Message);
  98. }
  99. }
  100. private void CancelButton_Click(object sender, EventArgs e)
  101. {
  102. this.Hide();
  103. updateUI();
  104. }
  105. private void ConfigForm_FormClosed(object sender, FormClosedEventArgs e)
  106. {
  107. controller.Stop();
  108. }
  109. private void AboutItem_Click(object sender, EventArgs e)
  110. {
  111. Process.Start("https://github.com/clowwindy/shadowsocks-csharp");
  112. }
  113. private void notifyIcon1_DoubleClick(object sender, EventArgs e)
  114. {
  115. showWindow();
  116. }
  117. private void EnableItem_Click(object sender, EventArgs e)
  118. {
  119. enableItem.Checked = !enableItem.Checked;
  120. controller.ToggleEnable(enableItem.Checked);
  121. }
  122. private void EditPACFileItem_Click(object sender, EventArgs e)
  123. {
  124. controller.TouchPACFile();
  125. }
  126. }
  127. }