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.1 kB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Diagnostics;
  9. namespace shadowsocks_csharp
  10. {
  11. public partial class Form1 : Form
  12. {
  13. Local local;
  14. Config config;
  15. public Form1()
  16. {
  17. config = Config.Load();
  18. InitializeComponent();
  19. configToTextBox();
  20. }
  21. private void showWindow()
  22. {
  23. this.Opacity = 1;
  24. this.Show();
  25. }
  26. private void configToTextBox()
  27. {
  28. textBox1.Text = config.server;
  29. textBox2.Text = config.server_port.ToString();
  30. textBox3.Text = config.password;
  31. textBox4.Text = config.local_port.ToString();
  32. }
  33. private void Form1_Load(object sender, EventArgs e)
  34. {
  35. if (!config.isDefault)
  36. {
  37. this.Opacity = 0;
  38. reload(config); BeginInvoke(new MethodInvoker(delegate
  39. {
  40. this.Hide();
  41. }));
  42. }
  43. }
  44. private void reload(Config config)
  45. {
  46. if (local != null)
  47. {
  48. local.Stop();
  49. }
  50. local = new Local(config.local_port);
  51. local.Start();
  52. }
  53. private void Config_Click(object sender, EventArgs e)
  54. {
  55. showWindow();
  56. }
  57. private void Quit_Click(object sender, EventArgs e)
  58. {
  59. this.Close();
  60. }
  61. private void OKButton_Click(object sender, EventArgs e)
  62. {
  63. try
  64. {
  65. Config config = new Config
  66. {
  67. server = textBox1.Text,
  68. server_port = int.Parse(textBox2.Text),
  69. password = textBox3.Text,
  70. local_port = int.Parse(textBox4.Text),
  71. isDefault = false
  72. };
  73. Config.Save(config);
  74. this.config = config;
  75. reload(config);
  76. this.Hide();
  77. }
  78. catch (FormatException)
  79. {
  80. MessageBox.Show("there is format problem");
  81. }
  82. catch (Exception)
  83. {
  84. MessageBox.Show("there is some problem with parameters");
  85. }
  86. }
  87. private void cancelButton_Click(object sender, EventArgs e)
  88. {
  89. this.Hide();
  90. configToTextBox();
  91. }
  92. private void Form1_FormClosed(object sender, FormClosedEventArgs e)
  93. {
  94. local.Stop();
  95. }
  96. private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
  97. {
  98. Process.Start("https://github.com/clowwindy/shadowsocks-csharp");
  99. }
  100. private void notifyIcon1_DoubleClick(object sender, EventArgs e)
  101. {
  102. showWindow();
  103. }
  104. }
  105. }

No Description

Contributors (1)