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.6 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. pacSrv.UpdatePACURL(config);
  39. pacUrl = pacSrv.PacUrl;
  40. }
  41. Sysproxy.SetIEProxy(true, false, null, pacUrl);
  42. }
  43. }
  44. else
  45. {
  46. Sysproxy.SetIEProxy(false, false, null, null);
  47. }
  48. }
  49. catch (ProxyException ex)
  50. {
  51. Logging.LogUsefulException(ex);
  52. if (ex.Type != ProxyExceptionType.Unspecific && !noRetry)
  53. {
  54. 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);
  55. if (ret == DialogResult.Yes)
  56. {
  57. Sysproxy.ResetIEProxy();
  58. Update(config, forceDisable, pacSrv, true);
  59. }
  60. }
  61. else
  62. {
  63. MessageBox.Show(I18N.GetString("Unrecoverable proxy setting error occured, see log for detail"), I18N.GetString("Shadowsocks"), MessageBoxButtons.OK, MessageBoxIcon.Error);
  64. }
  65. }
  66. }
  67. }
  68. }