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 1.6 kB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using Shadowsocks.Model;
  3. using Shadowsocks.Util.SystemProxy;
  4. namespace Shadowsocks.Controller
  5. {
  6. public static class SystemProxy
  7. {
  8. private static string GetTimestamp(DateTime value)
  9. {
  10. return value.ToString("yyyyMMddHHmmssfff");
  11. }
  12. public static void Update(Configuration config, bool forceDisable, PACServer pacSrv)
  13. {
  14. bool global = config.global;
  15. bool enabled = config.enabled;
  16. if (forceDisable)
  17. {
  18. enabled = false;
  19. }
  20. try
  21. {
  22. if (enabled)
  23. {
  24. if (global)
  25. {
  26. WinINet.SetIEProxy(true, true, "127.0.0.1:" + config.localPort.ToString(), "");
  27. }
  28. else
  29. {
  30. string pacUrl;
  31. if (config.useOnlinePac && !config.pacUrl.IsNullOrEmpty())
  32. pacUrl = config.pacUrl;
  33. else
  34. pacUrl = $"http://127.0.0.1:{config.localPort}/pac?t={GetTimestamp(DateTime.Now)}{pacSrv.PacSecret}";
  35. WinINet.SetIEProxy(true, false, "", pacUrl);
  36. }
  37. }
  38. else
  39. {
  40. WinINet.SetIEProxy(false, false, "", "");
  41. }
  42. }
  43. catch (ProxyException ex)
  44. {
  45. Logging.LogUsefulException(ex);
  46. }
  47. }
  48. }
  49. }