public static bool Check() { try { var path = $@"""{Utils.GetExecutablePath()}"""; var service = new StartupService(Key); return(service.Check(path)); } catch (Exception e) { Logging.LogUsefulException(e); return(false); } }
static HttpProxyRunner() { try { var uid = Directory.GetCurrentDirectory().GetClassicHashCode(); UNIQUE_CONFIG_FILE = $@"privoxy_{uid}.conf"; PRIVOXY_JOB = new(); FileManager.DecompressFile(Utils.GetTempPath(ExeName), Resources.privoxy_exe); } catch (IOException e) { Logging.LogUsefulException(e); } }
private static bool IsChildProcess(Process process) { try { var path = process.MainModule?.FileName; return(Utils.GetTempPath(ExeName).Equals(path)); } catch (Exception ex) { /* * Sometimes Process.GetProcessesByName will return some processes that * are already dead, and that will cause exceptions here. * We could simply ignore those exceptions. */ Logging.LogUsefulException(ex); return(false); } }
public void Start(Configuration configuration) { if (_process == null) { var existingPrivoxy = Process.GetProcessesByName(ExeNameNoExt); foreach (var p in existingPrivoxy.Where(IsChildProcess)) { KillProcess(p); } var privoxyConfig = Resources.privoxy_conf; RunningPort = GetFreePort(); privoxyConfig = privoxyConfig.Replace(@"__SOCKS_PORT__", configuration.LocalPort.ToString()); privoxyConfig = privoxyConfig.Replace(@"__PRIVOXY_BIND_PORT__", RunningPort.ToString()); privoxyConfig = privoxyConfig.Replace(@"__PRIVOXY_BIND_IP__", configuration.ShareOverLan ? Global.AnyHost : Global.LocalHost) .Replace(@"__SOCKS_HOST__", Global.LocalHost); FileManager.ByteArrayToFile(Utils.GetTempPath(UNIQUE_CONFIG_FILE), Encoding.UTF8.GetBytes(privoxyConfig)); _process = new Process { // Configure the process using the StartInfo properties. StartInfo = { FileName = ExeName, Arguments = UNIQUE_CONFIG_FILE, WorkingDirectory = Utils.TempPath, WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = true, CreateNoWindow = true } }; _process.Start(); /* * Add this process to job obj associated with this ss process, so that * when ss exit unexpectedly, this process will be forced killed by system. */ PRIVOXY_JOB.AddProcess(_process); } }
public static bool Set(bool enabled) { try { var path = $@"""{Utils.GetExecutablePath()}"""; var service = new StartupService(Key); if (enabled) { service.Set(path); } else { service.Delete(); } return(true); } catch (Exception e) { Logging.LogUsefulException(e); return(false); } }