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.

Form1.cs 3.7 kB

12 years ago
12 years ago
10 years ago
10 years ago
12 years ago
12 years ago
12 years ago
10 years ago
10 years ago
10 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 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. namespace shadowsocks_csharp
  9. {
  10. public partial class Form1 : Form
  11. {
  12. Local local;
  13. PACServer pacServer;
  14. Config config;
  15. PolipoRunner polipoRunner;
  16. public Form1()
  17. {
  18. config = Config.Load();
  19. InitializeComponent();
  20. configToTextBox();
  21. }
  22. private void showWindow()
  23. {
  24. this.Opacity = 1;
  25. this.Show();
  26. }
  27. private void configToTextBox()
  28. {
  29. textBox1.Text = config.server;
  30. textBox2.Text = config.server_port.ToString();
  31. textBox3.Text = config.password;
  32. textBox4.Text = config.local_port.ToString();
  33. comboBox1.Text = config.method == null ? "table" : config.method;
  34. }
  35. private void Form1_Load(object sender, EventArgs e)
  36. {
  37. if (!config.isDefault)
  38. {
  39. this.Opacity = 0;
  40. reload(config); BeginInvoke(new MethodInvoker(delegate
  41. {
  42. this.Hide();
  43. }));
  44. }
  45. pacServer = new PACServer();
  46. pacServer.Start();
  47. }
  48. private void reload(Config config)
  49. {
  50. if (local != null)
  51. {
  52. local.Stop();
  53. if (polipoRunner != null)
  54. {
  55. polipoRunner.Stop();
  56. }
  57. }
  58. local = new Local(config);
  59. local.Start();
  60. if (polipoRunner == null)
  61. {
  62. polipoRunner = new PolipoRunner();
  63. }
  64. polipoRunner.Start(config);
  65. }
  66. private void Config_Click(object sender, EventArgs e)
  67. {
  68. showWindow();
  69. }
  70. private void Quit_Click(object sender, EventArgs e)
  71. {
  72. this.Close();
  73. }
  74. private void OKButton_Click(object sender, EventArgs e)
  75. {
  76. try
  77. {
  78. Config config = new Config
  79. {
  80. server = textBox1.Text,
  81. server_port = int.Parse(textBox2.Text),
  82. password = textBox3.Text,
  83. local_port = int.Parse(textBox4.Text),
  84. method = comboBox1.Text,
  85. isDefault = false
  86. };
  87. Config.Save(config);
  88. this.config = config;
  89. reload(config);
  90. this.Hide();
  91. }
  92. catch (FormatException)
  93. {
  94. MessageBox.Show("there is format problem");
  95. }
  96. catch (Exception ex)
  97. {
  98. MessageBox.Show(ex.ToString());
  99. }
  100. }
  101. private void cancelButton_Click(object sender, EventArgs e)
  102. {
  103. this.Hide();
  104. configToTextBox();
  105. }
  106. private void Form1_FormClosed(object sender, FormClosedEventArgs e)
  107. {
  108. if (local != null) local.Stop();
  109. if (polipoRunner != null) polipoRunner.Stop();
  110. }
  111. private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
  112. {
  113. Process.Start("https://github.com/clowwindy/shadowsocks-csharp");
  114. }
  115. private void notifyIcon1_DoubleClick(object sender, EventArgs e)
  116. {
  117. showWindow();
  118. }
  119. }
  120. }