/// <summary> /// Update the information section with current installation status /// </summary> /// <param name="info"></param> void InstallationInformationChanged(InstallationCompletionInfo info) { int mode = 0; ProgressBar target = null; switch (info.StepName) { case "Initialization": target = CheckingBar; break; case "Extraction": target = ExtractBar; break; case "Font Creation": target = FontBar; break; case "3D Model Creation": target = ModelBar; break; case "Finalization": target = FinalBar; break; case "Patching": target = PatchingBar; break; } if (target == null) { target = InformationProgressBar; //just in case } Dispatcher.Invoke(delegate { if (info.StandardOutput != null) { #if DEBUG PushError(info.StandardOutput, Brushes.Gray); #endif Log.AppendLine(info.StandardOutput); StandardOutput.AppendLine(info.StandardOutput); } InstallationGrid.Visibility = Visibility.Visible; TaskNameBlock.Text = info.StepName; TimeBlock.Text = info.ElapsedTime.ToString(); DescBlock.Text = info.CurrentTask; target.Maximum = InformationProgressBar.Maximum = 1.0; target.Value = InformationProgressBar.Value = info.PercentComplete; InformationBarText.Text = (int)(info.PercentComplete * 100) + "%"; }); }
private void GetBlenderPlugin() { string blender = BlenderPath.Text; Task.Run(async() => { DataReceivedEventHandler action = (object s, DataReceivedEventArgs e) => SafePushError(e.Data, Brushes.Gray); //download plugin string path = Path.Combine(Environment.CurrentDirectory, "plugin.zip"); if (!File.Exists(path)) { using (var client = new WebClient()) { //progress changed client.DownloadProgressChanged += async(object sender, DownloadProgressChangedEventArgs e) => { var args = new InstallationCompletionInfo() { StepName = "3D Model Creation", CurrentTask = $"Downloading ({e.BytesReceived / e.TotalBytesToReceive} bytes)", PercentComplete = e.ProgressPercentage / 100.0 }; InstallationInformationChanged(args); }; await client.DownloadFileTaskAsync( new Uri("https://github.com/joric/io_scene_b3d/releases/download/1.0/io_scene_b3d.zip"), "plugin.zip"); } } string pluginPath = Path.Combine(Environment.CurrentDirectory, "InstallPlugin.py"); PythonParameterEditor.ReplaceParameter(pluginPath, "filepath=", 0, path.Replace('\\', '/')); ProcessStartInfo startInfo = new ProcessStartInfo(blender, $"-b -P {pluginPath}") { CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true }; var info = Process.Start(startInfo); try { info.BeginOutputReadLine(); info.OutputDataReceived += action; } catch (Exception e) { SafePushError(e.Message); } Dispatcher.Invoke(delegate { InstallationInformationChanged(new InstallationCompletionInfo() { StepName = "3D Model Creation", CurrentTask = $"Installing Blender Addon...", PercentComplete = 0.0 }); WaitForUserCompletion(); MsgOKButton.IsEnabled = false; MsgOKButton.Content = "Blender is open"; }); info.WaitForExit(); try { info.CancelOutputRead(); info.OutputDataReceived -= action; } catch (Exception e) { PushError(e.Message); } Dispatcher.Invoke(delegate { InstallationInformationChanged(new InstallationCompletionInfo() { StepName = "3D Model Creation", CurrentTask = $"Installing Blender Addon...", PercentComplete = 1.0 }); if (info.ExitCode == 0) { MsgTitle.Text = "Good to Go!"; MsgOKButton.IsEnabled = true; MsgOKButton.Content = "All set"; } else { MsgTitle.Text = "Blender had an error"; MsgOKButton.IsEnabled = false; MsgOKButton.Content = "Try again later"; } }); }).ContinueWith((Task task) => { if (task.IsFaulted) { SafePushError(task.Exception.Flatten().InnerException.Message); Installation?.TogglePause(); } }); }