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.

PolipoRunner.cs 2.2 kB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using shadowsocks_csharp.Model;
  2. using shadowsocks_csharp.Properties;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.IO.Compression;
  8. using System.Text;
  9. namespace shadowsocks_csharp.Controller
  10. {
  11. class PolipoRunner
  12. {
  13. private Process process;
  14. public void Start(Server config)
  15. {
  16. if (process == null)
  17. {
  18. Process[] existingPolipo = Process.GetProcessesByName("ss_polipo");
  19. foreach (Process p in existingPolipo)
  20. {
  21. p.Kill();
  22. p.WaitForExit();
  23. }
  24. string temppath = Path.GetTempPath();
  25. string polipoConfig = Resources.polipo_config;
  26. polipoConfig = polipoConfig.Replace("__SOCKS_PORT__", config.local_port.ToString());
  27. FileManager.ByteArrayToFile(temppath + "/polipo.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig));
  28. FileManager.UncompressFile(temppath + "/ss_polipo.exe", Resources.polipo_exe);
  29. process = new Process();
  30. // Configure the process using the StartInfo properties.
  31. process.StartInfo.FileName = temppath + "/ss_polipo.exe";
  32. process.StartInfo.Arguments = "-c \"" + temppath + "/polipo.conf\"";
  33. process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  34. process.StartInfo.UseShellExecute = false;
  35. process.StartInfo.CreateNoWindow = true;
  36. process.StartInfo.RedirectStandardOutput = true;
  37. process.StartInfo.RedirectStandardError = true;
  38. //process.StandardOutput
  39. process.Start();
  40. }
  41. }
  42. public void Stop()
  43. {
  44. if (process != null)
  45. {
  46. process.Kill();
  47. try
  48. {
  49. process.WaitForExit();
  50. }
  51. catch (InvalidOperationException)
  52. {
  53. // do nothing
  54. }
  55. process = null;
  56. }
  57. }
  58. }
  59. }