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 OnGotResponse(IAsyncResult ar) { var process = (DownloadAndInstallProcess)ar.AsyncState; var state = new OperationProgress { CurrentProgress = 0, MaxProgress = 0, IsIndeterminate = true, ActionName = "Downloading MSysGit...", }; if(process.Monitor != null) { process.Monitor.Report(state); } process.WebResponse = process.WebRequest.EndGetResponse(ar); process.ResponseStream = process.WebResponse.GetResponseStream(); if(process.WebResponse.ContentLength > 0) { state.IsIndeterminate = false; state.MaxProgress = (int)process.WebResponse.ContentLength; if(process.Monitor != null) { process.Monitor.Report(state); } } process.Buffer = new byte[1024*4]; process.ResponseStream.BeginRead( process.Buffer, 0, process.Buffer.Length, OnResponseStreamRead, process); }
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 void SetProgress(IProgress<OperationProgress> progress, int val, string action) { if(progress != null) { var status = new OperationProgress { ActionName = action, MaxProgress = 8, CurrentProgress = val, }; progress.Report(status); } }