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.4 kB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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)
  13. {
  14. bool global = config.global;
  15. bool enabled = config.enabled;
  16. if (forceDisable)
  17. {
  18. enabled = false;
  19. }
  20. if (enabled)
  21. {
  22. if (global)
  23. {
  24. WinINet.SetIEProxy(true, true, "127.0.0.1:" + config.localPort.ToString(), "");
  25. }
  26. else
  27. {
  28. string pacUrl;
  29. if (config.useOnlinePac && !config.pacUrl.IsNullOrEmpty())
  30. pacUrl = config.pacUrl;
  31. else
  32. pacUrl = $"http://127.0.0.1:{config.localPort}/pac?t={GetTimestamp(DateTime.Now)}";
  33. WinINet.SetIEProxy(true, false, "", pacUrl);
  34. }
  35. }
  36. else
  37. {
  38. WinINet.SetIEProxy(false, false, "", "");
  39. }
  40. }
  41. }
  42. }