using Avalonia; using Avalonia.Controls; using Avalonia.Headless; using Avalonia.Markup.Xaml.Styling; using Avalonia.Themes.Fluent; using Avalonia.Threading; using Avalonia.VisualTree; using OpenCvSharp; using Prism.Dialogs; using SopHelper.Engine.Sop; using SopHelper.Engine.Recipes; using SopHelper.VVMs.RecipeEditor; using Window = Avalonia.Controls.Window; internal static class Program { [STAThread] public static void Main() { var root = Path.Combine(Path.GetTempPath(), "region-video-capture-" + Guid.NewGuid().ToString("N")); var previousRoot = Environment.GetEnvironmentVariable("SOPHELPER_WORKSPACE_ROOT"); Environment.SetEnvironmentVariable("SOPHELPER_WORKSPACE_ROOT", root); try { AppBuilder.Configure().UseSkia().UseHeadless(new AvaloniaHeadlessPlatformOptions { UseHeadlessDrawing = false }).SetupWithoutStarting(); Application.Current!.Styles.Add(new FluentTheme()); Application.Current.Styles.Add(new StyleInclude(new Uri("avares://SopHelper.Avalonia/")) { Source = new Uri("avares://SopHelper.Avalonia/Themes/Styles.axaml") }); CheckRegionVideoCapture(root); } finally { Environment.SetEnvironmentVariable("SOPHELPER_WORKSPACE_ROOT", previousRoot); if (Directory.Exists(root)) Directory.Delete(root, true); } } private static void CheckRegionVideoCapture(string root) { var store = new RecipeWorkspace(root); var config = new SopConfig(); config.Sop.Name = "区域视频取图"; config.Sop.Parts = []; var vm = new RecipeEditorViewModel(); vm.OnDialogOpened(new DialogParameters { { "directory", store.RecipesDirectory }, { "config", config }, { "new", true } }); vm.CaptureStandardVideoImageCommand.Execute(); Check(vm.PreviewStatus.Contains("先保存配方"), "Unsaved recipe explains how to enable standard video capture"); vm.SaveCommand.Execute(); var editor = new RecipeEditor { DataContext = vm }; var window = new Window { Content = editor, Width = 1040, Height = 760 }; window.Show(); window.UpdateLayout(); editor.GetVisualDescendants().OfType().Single().SelectedIndex = 1; window.UpdateLayout(); Dispatcher.UIThread.RunJobs(); var button = editor.GetVisualDescendants().OfType