private static void RunInstaller(DownloadAndInstallProcess process) { var state = new OperationProgress { CurrentProgress = 0, MaxProgress = 0, IsIndeterminate = true, ActionName = "Installing MSysGit...", }; if (process.Monitor != null) { process.Monitor.Report(state); } try { process.InstallerProcess = new Process() { StartInfo = new ProcessStartInfo() { FileName = process.InstallerFileName, Arguments = @"/verysilent", }, EnableRaisingEvents = true, }; process.InstallerProcess.Exited += process.OnInstallerProcessExited; process.InstallerProcess.Start(); } catch (Exception exc) { process.Exception = exc; process.Dispose(); } }
public Task DownloadAndInstallAsync(IProgress <OperationProgress> progress) { return(Task.Factory.StartNew( () => { progress?.Report(new OperationProgress("Initializing...")); using (var evt = new ManualResetEvent(false)) { var process = new DownloadAndInstallProcess(evt) { Monitor = progress, WebRequest = WebRequest.Create(DownloadUrl), }; progress?.Report(new OperationProgress("Connecting to MSysGit download server...")); process.WebRequest.BeginGetResponse(OnGotResponse, process); evt.WaitOne(); if (process.Exception != null) { throw process.Exception; } if (process.InstallerExitCode != 0) { throw new ApplicationException("Installer returned exit code " + process.InstallerExitCode); } } }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default)); }
private static void UpdateDownloadProgress(DownloadAndInstallProcess process, int downloadedBytes) { process.DownloadedBytes += downloadedBytes; if (process.Monitor != null && process.WebResponse.ContentLength > 0 && process.DownloadedBytes <= process.WebResponse.ContentLength) { var state = new OperationProgress { CurrentProgress = (int)process.DownloadedBytes, MaxProgress = (int)process.WebResponse.ContentLength, IsIndeterminate = false, ActionName = "Downloading MSysGit...", }; process.Monitor.Report(state); } }
private static bool EnsureOutputFileStreamExists(DownloadAndInstallProcess process) { if (process.InstallerFileStream == null) { try { process.InstallerFileName = Path.Combine( Path.GetTempPath(), "msysgit-installer.exe"); process.InstallerFileStream = new FileStream( process.InstallerFileName, FileMode.Create, FileAccess.Write, FileShare.None); } catch (Exception exc) { process.Exception = exc; process.Dispose(); return(false); } } return(true); }
private static void UpdateDownloadProgress(DownloadAndInstallProcess process, int downloadedBytes) { process.DownloadedBytes += downloadedBytes; if(process.Monitor != null && process.WebResponse.ContentLength > 0 && process.DownloadedBytes <= process.WebResponse.ContentLength) { var state = new OperationProgress { CurrentProgress = (int)process.DownloadedBytes, MaxProgress = (int)process.WebResponse.ContentLength, IsIndeterminate = false, ActionName = "Downloading MSysGit...", }; process.Monitor.Report(state); } }
private static void RunInstaller(DownloadAndInstallProcess process) { var state = new OperationProgress { CurrentProgress = 0, MaxProgress = 0, IsIndeterminate = true, ActionName = "Installing MSysGit...", }; if(process.Monitor != null) { process.Monitor.Report(state); } try { process.InstallerProcess = new Process() { StartInfo = new ProcessStartInfo() { FileName = process.InstallerFileName, Arguments = @"/verysilent", }, EnableRaisingEvents = true, }; process.InstallerProcess.Exited += process.OnInstallerProcessExited; process.InstallerProcess.Start(); } catch(Exception exc) { process.Exception = exc; process.Dispose(); } }
private static bool EnsureOutputFileStreamExists(DownloadAndInstallProcess process) { if(process.InstallerFileStream == null) { try { process.InstallerFileName = Path.Combine( Path.GetTempPath(), "msysgit-installer.exe"); process.InstallerFileStream = new FileStream( process.InstallerFileName, FileMode.Create, FileAccess.Write, FileShare.None); } catch(Exception exc) { process.Exception = exc; process.Dispose(); return false; } } return true; }
public Task DownloadAndInstallAsync(IProgress<OperationProgress> progress) { return Task.Factory.StartNew( () => { if(progress != null) { progress.Report(new OperationProgress("Initializing...")); } using(var evt = new ManualResetEvent(false)) { var process = new DownloadAndInstallProcess(evt) { Monitor = progress, WebRequest = WebRequest.Create(DownloadUrl), }; if(progress != null) { progress.Report(new OperationProgress("Connecting to MSysGit download server...")); } process.WebRequest.BeginGetResponse(OnGotResponse, process); evt.WaitOne(); if(process.Exception != null) { throw process.Exception; } if(process.InstallerExitCode != 0) { throw new ApplicationException("Installer returned exit code " + process.InstallerExitCode); } } }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default); }