Handled process used error in previous push

This commit is contained in:
McoreD 2014-05-10 12:17:56 +08:00
parent 380d4be6ec
commit b56d018b25
4 changed files with 45 additions and 24 deletions

View file

@ -50,6 +50,7 @@ public partial class DownloaderForm : Form
public InstallType InstallType { get; set; }
public bool AutoStartInstall { get; set; }
public DownloaderFormStatus Status { get; private set; }
public bool RunInstallerInBackground { get; set; }
private FileDownloader fileDownloader;
private FileStream fileStream;
@ -70,6 +71,7 @@ private DownloaderForm()
AutoStartDownload = true;
InstallType = InstallType.Silent;
AutoStartInstall = true;
RunInstallerInBackground = true;
}
public DownloaderForm(UpdateChecker updateChecker)
@ -124,10 +126,12 @@ private void btnAction_MouseClick(object sender, MouseEventArgs e)
}
else if (Status == DownloaderFormStatus.DownloadCompleted)
{
DialogResult = DialogResult.OK;
Install();
}
else
{
DialogResult = DialogResult.Cancel;
Close();
}
}
@ -147,12 +151,20 @@ public void Install()
// This function will give time for ShareX to close so installer won't tell ShareX is already running
private void RunInstallerWithDelay(int delay = 1000)
{
Thread thread = new Thread(() =>
if (RunInstallerInBackground)
{
Thread.Sleep(delay);
Thread thread = new Thread(() =>
{
Thread.Sleep(delay);
RunInstaller();
});
thread.Start();
}
else
{
Hide();
RunInstaller();
});
thread.Start();
}
}
private void RunInstaller()
@ -192,6 +204,7 @@ protected void OnInstallRequested()
{
if (InstallRequested != null)
{
DialogResult = DialogResult.OK;
InstallRequested(SavePath);
}
}
@ -207,8 +220,8 @@ private void ChangeProgress()
{
pbProgress.Value = (int)Math.Round(fileDownloader.DownloadPercentage);
lblProgress.Text = String.Format(CultureInfo.CurrentCulture,
"Progress: {0:0.##}%\nDownload speed: {1:0.##} kB/s\nFile size: {2:n0} / {3:n0} kB",
fileDownloader.DownloadPercentage, fileDownloader.DownloadSpeed / 1024, fileDownloader.DownloadedSize / 1024,
"Progress: {0:0.0}%\nDownload speed: {1:0.0} kB/s\nFile size: {2:n0} / {3:n0} KiB",
fileDownloader.DownloadPercentage, fileDownloader.DownloadSpeed / 1000, fileDownloader.DownloadedSize / 1024,
fileDownloader.FileSize / 1024);
}
}

View file

@ -140,25 +140,30 @@ private void btnDownload_Click(object sender, EventArgs e)
DownloadFFmpeg();
}
public void DownloadFFmpeg(bool showConfirmation = true)
public DialogResult DownloadFFmpeg(bool runInstallerInBackground = true)
{
string url;
if (NativeMethods.Is64Bit())
{
url = "http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-latest-win64-static.7z";
}
else
{
url = "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-latest-win32-static.7z";
}
using (DownloaderForm form = new DownloaderForm(url, "ffmpeg.7z"))
using (DownloaderForm form = new DownloaderForm(FFmpegDownloadLink, "ffmpeg.7z"))
{
form.Proxy = ProxyInfo.Current.GetWebProxy();
form.InstallType = InstallType.Event;
form.RunInstallerInBackground = runInstallerInBackground;
form.InstallRequested += form_InstallRequested;
form.ShowDialog();
return form.ShowDialog();
}
}
public static string FFmpegDownloadLink
{
get
{
if (NativeMethods.Is64Bit())
{
return "http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-latest-win64-static.7z";
}
else
{
return "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-latest-win32-static.7z";
}
}
}
@ -178,7 +183,7 @@ private void form_InstallRequested(string filePath)
}
}
private bool ExtractFFmpeg(string zipPath, string extractPath)
public static bool ExtractFFmpeg(string zipPath, string extractPath)
{
try
{

View file

@ -421,7 +421,7 @@ private void InitializeComponent()
this.tsmiScreenRecorder.Image = global::ShareX.Properties.Resources.camcorder_image;
this.tsmiScreenRecorder.Name = "tsmiScreenRecorder";
this.tsmiScreenRecorder.Size = new System.Drawing.Size(181, 22);
this.tsmiScreenRecorder.Text = "Screencast";
this.tsmiScreenRecorder.Text = "Screen recording";
this.tsmiScreenRecorder.Click += new System.EventHandler(this.tsmiScreenRecorder_Click);
//
// tsmiAutoCapture
@ -1436,7 +1436,7 @@ private void InitializeComponent()
this.tsmiTrayScreenRecorder.Image = global::ShareX.Properties.Resources.camcorder_image;
this.tsmiTrayScreenRecorder.Name = "tsmiTrayScreenRecorder";
this.tsmiTrayScreenRecorder.Size = new System.Drawing.Size(184, 22);
this.tsmiTrayScreenRecorder.Text = "Screen Recorder";
this.tsmiTrayScreenRecorder.Text = "Screen recording";
this.tsmiTrayScreenRecorder.Click += new System.EventHandler(this.tsmiScreenRecorder_Click);
//
// tsmiTrayAutoCapture

View file

@ -106,7 +106,10 @@ public async void StartRecording(TaskSettings TaskSettings)
{
using (FFmpegCLIOptionsForm form = new FFmpegCLIOptionsForm())
{
form.DownloadFFmpeg();
if (form.DownloadFFmpeg(false) == System.Windows.Forms.DialogResult.Cancel)
{
return;
}
}
}
}