private void Bgworker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show("MFG exited unexpectedly, something went wrong."); } spliter?.Stop(); buttonStart.IsEnabled = true; buttonStop.IsEnabled = false; }
private void Bgworker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { int?inuse = Forwarder.Nettools.isPortInUse(new List <int> { Properties.Settings.Default.MFGPort, Properties.Settings.Default.ListenPort }); if (inuse != null) { MessageBox.Show("Port " + inuse + " is already in use!"); buttonSettings.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } else { spliter = new Forwarder.Spliter( Properties.Settings.Default.UpstreamPort, Properties.Settings.Default.MFGPort, Properties.Settings.Default.ListenPort); spliter.Start(); System.IO.File.WriteAllText(System.IO.Path.Combine(basepath, "MyFleetGirls/application.conf"), @" url { post: ""https://myfleet.moe"" proxy { port: " + Properties.Settings.Default.UpstreamPort + @" host: ""localhost"" } } proxy { port: " + Properties.Settings.Default.MFGPort + @" host: ""localhost"" } upstream_proxy { port: " + Properties.Settings.Default.UpstreamPort + @" host: ""localhost"" } auth { pass: "******" }"); if (System.IO.File.Exists(System.IO.Path.Combine(basepath, "log-lastrun.txt"))) { System.IO.File.Delete(System.IO.Path.Combine(basepath, "log-lastrun.txt")); } if (System.IO.File.Exists(System.IO.Path.Combine(basepath, "log.txt"))) { System.IO.File.Move(System.IO.Path.Combine(basepath, "log.txt"), System.IO.Path.Combine(basepath, "log-lastrun.txt")); } sw = new System.IO.StreamWriter(System.IO.Path.Combine(basepath, "log.txt")); proc = new System.Diagnostics.Process(); proc.StartInfo.FileName = "java"; proc.StartInfo.Arguments = "-jar MyFleetGirls.jar"; proc.StartInfo.WorkingDirectory = System.IO.Path.Combine(basepath, "MyFleetGirls"); proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.RedirectStandardError = true; proc.OutputDataReceived += Proc_OutputDataReceived; proc.ErrorDataReceived += Proc_OutputDataReceived; proc.Start(); proc.BeginOutputReadLine(); proc.BeginErrorReadLine(); proc.WaitForExit(); sw.Close(); spliter.Stop(); System.Threading.Thread.Sleep(250); } }
private void Bgworker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { int? inuse = Forwarder.Nettools.isPortInUse(new List<int> { Properties.Settings.Default.MFGPort, Properties.Settings.Default.ListenPort }); if (inuse != null) { MessageBox.Show("Port " + inuse + " is already in use!"); buttonSettings.RaiseEvent(new RoutedEventArgs(Button.ClickEvent)); } else { spliter = new Forwarder.Spliter( Properties.Settings.Default.UpstreamPort, Properties.Settings.Default.MFGPort, Properties.Settings.Default.ListenPort); spliter.Start(); System.IO.File.WriteAllText(System.IO.Path.Combine(basepath, "MyFleetGirls/application.conf"), @" url { post: ""https://myfleet.moe"" proxy { port: " + Properties.Settings.Default.UpstreamPort + @" host: ""localhost"" } } proxy { port: " + Properties.Settings.Default.MFGPort + @" host: ""localhost"" } upstream_proxy { port: " + Properties.Settings.Default.UpstreamPort + @" host: ""localhost"" } auth { pass: "******" }"); if (System.IO.File.Exists(System.IO.Path.Combine(basepath, "log-lastrun.txt"))) System.IO.File.Delete(System.IO.Path.Combine(basepath, "log-lastrun.txt")); if (System.IO.File.Exists(System.IO.Path.Combine(basepath, "log.txt"))) System.IO.File.Move(System.IO.Path.Combine(basepath, "log.txt"), System.IO.Path.Combine(basepath, "log-lastrun.txt")); sw = new System.IO.StreamWriter(System.IO.Path.Combine(basepath, "log.txt")); proc = new System.Diagnostics.Process(); proc.StartInfo.FileName = "java"; proc.StartInfo.Arguments = "-jar MyFleetGirls.jar"; proc.StartInfo.WorkingDirectory = System.IO.Path.Combine(basepath, "MyFleetGirls"); proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.RedirectStandardError = true; proc.OutputDataReceived += Proc_OutputDataReceived; proc.ErrorDataReceived += Proc_OutputDataReceived; proc.Start(); proc.BeginOutputReadLine(); proc.BeginErrorReadLine(); proc.WaitForExit(); sw.Close(); spliter.Stop(); System.Threading.Thread.Sleep(250); } }