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.

SystemProxy.cs 2.5 kB

11 years ago
11 years ago
11 years ago
11 years ago
9 years ago
9 years ago
9 years ago
9 years ago
11 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Windows.Forms;
  3. using Shadowsocks.Model;
  4. using Shadowsocks.Util.SystemProxy;
  5. namespace Shadowsocks.Controller
  6. {
  7. public static class SystemProxy
  8. {
  9. private static string GetTimestamp(DateTime value)
  10. {
  11. return value.ToString("yyyyMMddHHmmssfff");
  12. }
  13. public static void Update(Configuration config, bool forceDisable, PACServer pacSrv, bool noRetry = false)
  14. {
  15. bool global = config.global;
  16. bool enabled = config.enabled;
  17. if (forceDisable)
  18. {
  19. enabled = false;
  20. }
  21. try
  22. {
  23. if (enabled)
  24. {
  25. if (global)
  26. {
  27. Sysproxy.SetIEProxy(true, true, "localhost:" + config.localPort.ToString(), null);
  28. }
  29. else
  30. {
  31. string pacUrl;
  32. if (config.useOnlinePac && !config.pacUrl.IsNullOrEmpty())
  33. {
  34. pacUrl = config.pacUrl;
  35. }
  36. else
  37. {
  38. pacUrl = pacSrv.PacUrl;
  39. }
  40. Sysproxy.SetIEProxy(true, false, null, pacUrl);
  41. }
  42. }
  43. else
  44. {
  45. Sysproxy.SetIEProxy(false, false, null, null);
  46. }
  47. }
  48. catch (ProxyException ex)
  49. {
  50. Logging.LogUsefulException(ex);
  51. if (ex.Type != ProxyExceptionType.Unspecific && !noRetry)
  52. {
  53. var ret = MessageBox.Show(I18N.GetString("Error occured when process proxy setting, do you want reset current setting and retry?"), I18N.GetString("Shadowsocks"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
  54. if (ret == DialogResult.Yes)
  55. {
  56. Sysproxy.ResetIEProxy();
  57. Update(config, forceDisable, pacSrv, true);
  58. }
  59. }
  60. else
  61. {
  62. MessageBox.Show(I18N.GetString("Unrecoverable proxy setting error occured, see log for detail"), I18N.GetString("Shadowsocks"), MessageBoxButtons.OK, MessageBoxIcon.Error);
  63. }
  64. }
  65. }
  66. }
  67. }