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