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

10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
8 years ago
8 years ago
8 years ago
10 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. public static void Update(Configuration config, bool forceDisable, PACServer pacSrv, bool noRetry = false)
  12. {
  13. bool global = config.global;
  14. bool enabled = config.enabled;
  15. if (forceDisable || WinINet.operational)
  16. {
  17. enabled = false;
  18. }
  19. try
  20. {
  21. if (enabled)
  22. {
  23. if (global)
  24. {
  25. WinINet.ProxyGlobal("localhost:" + config.localPort.ToString(), "<local>");
  26. }
  27. else
  28. {
  29. string pacUrl;
  30. if (config.useOnlinePac && !config.pacUrl.IsNullOrEmpty())
  31. {
  32. pacUrl = config.pacUrl;
  33. }
  34. else
  35. {
  36. pacUrl = pacSrv.PacUrl;
  37. }
  38. WinINet.ProxyPAC(pacUrl);
  39. }
  40. }
  41. else
  42. {
  43. WinINet.Restore();
  44. }
  45. }
  46. catch (ProxyException ex)
  47. {
  48. logger.LogUsefulException(ex);
  49. if (ex.Type != ProxyExceptionType.Unspecific && !noRetry)
  50. {
  51. 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);
  52. if (ret == DialogResult.Yes)
  53. {
  54. WinINet.Reset();
  55. Update(config, forceDisable, pacSrv, true);
  56. }
  57. }
  58. else
  59. {
  60. MessageBox.Show(I18N.GetString("Unrecoverable proxy setting error occured, see log for detail"), I18N.GetString("Shadowsocks"), MessageBoxButtons.OK, MessageBoxIcon.Error);
  61. }
  62. }
  63. }
  64. }
  65. }