mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 17:56:51 +13:00
ExternalCLIManager.cs changes
This commit is contained in:
parent
5d4533523c
commit
8028897007
5 changed files with 35 additions and 48 deletions
|
@ -10,7 +10,7 @@ namespace HelpersLib
|
|||
{
|
||||
public abstract class ExternalCLIManager : IDisposable
|
||||
{
|
||||
private Process CLI = new Process();
|
||||
private Process cli = new Process();
|
||||
|
||||
public StringBuilder Output = new StringBuilder();
|
||||
public StringBuilder Errors = new StringBuilder();
|
||||
|
@ -18,61 +18,51 @@ public abstract class ExternalCLIManager : IDisposable
|
|||
public delegate void ErrorDataReceivedHandler();
|
||||
public event ErrorDataReceivedHandler ErrorDataReceived;
|
||||
|
||||
public virtual void Open(string cliPath)
|
||||
public virtual void Open(string cliPath, string args = null)
|
||||
{
|
||||
ProcessStartInfo psi = new ProcessStartInfo(cliPath);
|
||||
psi.UseShellExecute = false;
|
||||
psi.ErrorDialog = false;
|
||||
psi.RedirectStandardInput = true;
|
||||
psi.RedirectStandardError = true;
|
||||
psi.RedirectStandardOutput = true;
|
||||
psi.WorkingDirectory = Path.GetDirectoryName(cliPath);
|
||||
|
||||
psi.WindowStyle = ProcessWindowStyle.Normal;
|
||||
|
||||
using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
|
||||
using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false))
|
||||
if (File.Exists(cliPath))
|
||||
{
|
||||
CLI.OutputDataReceived += (sender, e) =>
|
||||
{
|
||||
if (e.Data == null)
|
||||
{
|
||||
outputWaitHandle.Set();
|
||||
}
|
||||
else
|
||||
{
|
||||
Output.AppendLine(e.Data);
|
||||
}
|
||||
};
|
||||
ProcessStartInfo psi = new ProcessStartInfo(cliPath);
|
||||
psi.UseShellExecute = false;
|
||||
psi.ErrorDialog = false;
|
||||
psi.CreateNoWindow = true;
|
||||
psi.RedirectStandardInput = true;
|
||||
psi.RedirectStandardError = true;
|
||||
psi.RedirectStandardOutput = true;
|
||||
psi.WorkingDirectory = Path.GetDirectoryName(cliPath);
|
||||
psi.Arguments = args;
|
||||
|
||||
CLI.ErrorDataReceived += (sender, e) =>
|
||||
{
|
||||
if (e.Data == null)
|
||||
{
|
||||
errorWaitHandle.Set();
|
||||
}
|
||||
else
|
||||
{
|
||||
Errors.AppendLine(e.Data);
|
||||
}
|
||||
};
|
||||
cli.OutputDataReceived += (sender, e) => { if (e.Data != null) { Output.AppendLine(e.Data); } };
|
||||
cli.ErrorDataReceived += (sender, e) => { if (e.Data == null) { Errors.AppendLine(e.Data); } };
|
||||
|
||||
CLI.StartInfo = psi;
|
||||
CLI.Start();
|
||||
cli.EnableRaisingEvents = true;
|
||||
cli.StartInfo = psi;
|
||||
cli.Start();
|
||||
|
||||
Console.WriteLine("CLI Path: " + cliPath);
|
||||
Console.WriteLine("CLI Args: " + psi.Arguments);
|
||||
|
||||
cli.BeginOutputReadLine();
|
||||
cli.BeginErrorReadLine();
|
||||
|
||||
System.Windows.Forms.MessageBox.Show(Output.ToString());
|
||||
System.Windows.Forms.MessageBox.Show(Errors.ToString());
|
||||
|
||||
cli.WaitForExit();
|
||||
}
|
||||
}
|
||||
|
||||
public void SendCommand(string command)
|
||||
{
|
||||
if (CLI != null)
|
||||
if (cli != null)
|
||||
{
|
||||
CLI.StandardInput.WriteLine(command);
|
||||
cli.StandardInput.WriteLine(command);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Close()
|
||||
{
|
||||
CLI.CloseMainWindow();
|
||||
cli.CloseMainWindow();
|
||||
}
|
||||
|
||||
public virtual void OnErrorDataReceived()
|
||||
|
@ -85,9 +75,9 @@ public virtual void OnErrorDataReceived()
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
if (CLI != null)
|
||||
if (cli != null)
|
||||
{
|
||||
CLI.Dispose();
|
||||
cli.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
<Compile Include="Screencast\CLIEncoder.cs" />
|
||||
<Compile Include="Enums.cs" />
|
||||
<Compile Include="Screencast\FFmpegCLIHelper.cs" />
|
||||
<Compile Include="Screencast\AVIOptions.cs" />
|
||||
<Compile Include="Screencast\ScreencastOptions.cs" />
|
||||
<Compile Include="Screencast\AviWriter.cs" />
|
||||
<Compile Include="Screencast\FFmpegCache.cs" />
|
||||
<Compile Include="Screencast\FFmpegOptionsForm.cs">
|
||||
|
|
|
@ -55,8 +55,6 @@ public FFmpegCLIHelper(ScreencastOptions options)
|
|||
|
||||
public override void Record()
|
||||
{
|
||||
Open(Options.FFmpeg.CLIPath);
|
||||
|
||||
StringBuilder args = new StringBuilder();
|
||||
args.Append("-f dshow -i video=\"screen-capture-recorder\"");
|
||||
if (Options.FPS > 0)
|
||||
|
@ -65,7 +63,7 @@ public override void Record()
|
|||
}
|
||||
args.Append(string.Format(" -c:v libx264 -crf 23 -preset medium -pix_fmt yuv420p -y \"{0}\"", Options.OutputPath));
|
||||
|
||||
SendCommand(args.ToString());
|
||||
Open(Options.FFmpeg.CLIPath, args.ToString());
|
||||
}
|
||||
|
||||
public void ListDevices()
|
||||
|
|
|
@ -160,7 +160,6 @@ private void RecordUsingFFmpegCLI()
|
|||
{
|
||||
ffMpegCli = new FFmpegCLIHelper(Options);
|
||||
ffMpegCli.Record();
|
||||
ffMpegCli.ListDevices();
|
||||
}
|
||||
|
||||
private void RecordUsingCache()
|
||||
|
|
Loading…
Reference in a new issue