using System; using System.IO; using System.Linq; using System.Threading; using Launcher.Next.Application; using Launcher.Next.Autodesk; namespace Launcher.Next.App; public partial class MainWindow : System.Windows.Window { private sealed record LauncherProduct(string Id,string Name,string? Executable,string Diagnostic); private readonly LocalParityLaunchProfile? localProfile; private readonly LocalParityLaunchService localService=new(); private readonly LegacyConfigurationAdapter adapter=new(); private LauncherProduct? selected; private string? projectPath; private string? manualRosterPath; public MainWindow() { InitializeComponent(); WireSourceVerifiedSelection(); Initialize(); } internal MainWindow(LocalParityLaunchProfile profile) { localProfile=profile; InitializeComponent(); WireSourceVerifiedSelection(); Initialize(); } private void WireSourceVerifiedSelection() { SelectProjectButton.Click -= SelectProject_Click; SelectProjectButton.Click += SelectProjectFile_Click; AutomaticMode.Checked -= LoadMode_Changed; ListMode.Checked -= LoadMode_Changed; AutomaticMode.Checked += LoadModeChanged; ListMode.Checked += LoadModeChanged; } private void Initialize() { var plant=new PlantProductDiscovery(new WindowsRegistryReader()).DiscoverPlant3D(2026); var navisworks=Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),"Autodesk","Navisworks Manage 2026","Roamer.exe"); Products.ItemsSource=new[]{new LauncherProduct("navisworks","Navisworks Manage 2026",File.Exists(navisworks)?navisworks:null,File.Exists(navisworks)?"Найден":"Navisworks Manage 2026 не найден"),new LauncherProduct("pnid","Plant P&ID 2026",plant?.ExecutablePath,plant is null?"Plant P&ID 2026 не найден":"Используется установленный Plant 3D 2026 runtime"),new LauncherProduct("plant3d","Plant 3D 2026",plant?.ExecutablePath,plant is null?"Plant 3D 2026 не найден":"Найден")}; Version.Text="Версия: "+typeof(MainWindow).Assembly.GetName().Version; Status.Text="Выберите программное обеспечение."; if(localProfile is not null) { Products.SelectedIndex=2; Status.Text="Выберите controlled non-production папку проекта."; } } private void Products_SelectionChanged(object sender,System.Windows.Controls.SelectionChangedEventArgs e) { selected=Products.SelectedItem as LauncherProduct; projectPath=null; ProjectPath.Text=selected is null?"Выберите программное обеспечение":"Папка проекта не выбрана"; SelectProjectButton.IsEnabled=selected?.Executable is not null; StartButton.IsEnabled=false; Plugins.ItemsSource=null; Plugins.IsEnabled=false; ProductStatus.Text=selected?.Diagnostic??""; Status.Text=selected?.Executable is null?selected?.Diagnostic??"Выберите программное обеспечение":"Выберите папку проекта."; } private void SelectProject_Click(object sender,System.Windows.RoutedEventArgs e) { if(selected is null)return; var dialog=new Microsoft.Win32.OpenFolderDialog { Title="Выберите папку проекта" }; if(dialog.ShowDialog()!=true)return; var path=Path.GetFullPath(dialog.FolderName); if(!Directory.Exists(path)){Status.Text="Выбранная папка недоступна.";return;} if(selected.Id is "plant3d" or "pnid" && !File.Exists(Path.Combine(path,"Project.xml"))){Status.Text="Выбранная папка не является проектом Plant 3D.";return;} projectPath=path; ProjectPath.Text=path; ResolvePlugins(); } private void SelectProjectFile_Click(object sender, System.Windows.RoutedEventArgs e) { if (selected is null) return; var product = LegacyProductSelections.For(selected.Id); var dialog = new Microsoft.Win32.OpenFileDialog { Title = "Select project", Filter = product.Filter, CheckFileExists = true, Multiselect = false }; if (dialog.ShowDialog() != true) return; try { projectPath = LegacyProductSelections.ValidateSelectedFile(product, dialog.FileName); manualRosterPath = null; ProjectPath.Text = Path.GetFileName(projectPath); ResolvePluginsSourceVerified(); } catch (Exception ex) { Status.Text = UserMessage(ex.Message); } } private void LoadModeChanged(object sender, System.Windows.RoutedEventArgs e) { if (projectPath is null || selected is null) return; if (ListMode.IsChecked == true) { var dialog = new Microsoft.Win32.OpenFileDialog { Title = "Select download_list.xml", Filter = "download_list.xml (*.xml)|*.xml|All files (*.*)|*.*", CheckFileExists = true, Multiselect = false }; if (dialog.ShowDialog() != true) { AutomaticMode.IsChecked = true; return; } manualRosterPath = dialog.FileName; } else manualRosterPath = null; ResolvePluginsSourceVerified(); } private void LoadMode_Changed(object sender,System.Windows.RoutedEventArgs e) { if(projectPath is not null)ResolvePlugins(); } private void ResolvePluginsSourceVerified() { if (selected is null || projectPath is null) return; if (localProfile is not null && selected.Id == "plant3d") { ResolvePlugins(); return; } try { var product = LegacyProductSelections.For(selected.Id); var plan = LegacyProductSelections.ReadRoster(product, projectPath, manualRosterPath, adapter); Plugins.ItemsSource = plan.OrderedIds; Plugins.IsEnabled = false; PluginStatus.Text = $"List source: {plan.Source}."; StartButton.IsEnabled = false; Status.Text = plan.UnmappedIds.Count == 0 ? "Packages for the selected plugins are not mapped to 2026 packages." : $"Packages for {product.DisplayName} are not yet available for 2026: {string.Join(", ", plan.UnmappedIds)}"; } catch (Exception ex) { Plugins.ItemsSource = null; Plugins.IsEnabled = false; StartButton.IsEnabled = false; Status.Text = ex.Message == "LEGACY_DOWNLOAD_LIST_NOT_FOUND" ? "Для выбранного проекта не найден список плагинов" : UserMessage(ex.Message); } } private void ResolvePlugins() { if(selected is null||projectPath is null)return; if(localProfile is not null && selected.Id=="plant3d") { var settings=adapter.ParseSettings(File.ReadAllText(localProfile.SettingsPath)); var pattern=settings.Patterns.Single(x=>x.Name==localProfile.PatternName); Plugins.ItemsSource=pattern.Plugins; Plugins.IsEnabled=ListMode.IsChecked==true; foreach(var item in Plugins.Items)Plugins.SelectedItems.Add(item); PluginStatus.Text=AutomaticMode.IsChecked==true?"Плагины определены автоматически для выбранного проекта.":"Выберите допустимый список плагинов."; StartButton.IsEnabled=true; Status.Text="Готово к запуску."; return; } PluginStatus.Text="Для выбранного продукта нет approved local mapping пакетов."; Plugins.ItemsSource=null; Plugins.IsEnabled=false; StartButton.IsEnabled=false; Status.Text="Источник пакета недоступен для выбранного продукта."; } private async void Start_Click(object sender,System.Windows.RoutedEventArgs e) { if(localProfile is null||selected?.Id!="plant3d"||projectPath is null){Status.Text="Не удалось определить список плагинов.";return;} try { StartButton.IsEnabled=false; Status.Text="Подготовка плагинов…"; var prepared=await localService.PrepareAsync(localProfile,CancellationToken.None); Status.Text="Запуск Autodesk…"; var result=await localService.LaunchAsync(prepared,CancellationToken.None); Status.Text=result.TerminalState=="Succeeded"?$"Autodesk запущен (PID {result.ProcessId}).":"Не удалось подтвердить загрузку пакета; диагностика сохранена."; StartButton.IsEnabled=true; } catch(Exception ex){Status.Text="Ошибка: "+UserMessage(ex.Message);StartButton.IsEnabled=true;} } private static string UserMessage(string code)=>code.Contains("NOT_FOUND",StringComparison.Ordinal)?"Не найден Plant 3D 2026":code.Contains("MANIFEST",StringComparison.Ordinal)?"Пакет повреждён":code.Contains("ACTIVATION",StringComparison.Ordinal)?"Не удалось активировать пакет":"Не удалось запустить Autodesk"; private void Help_Click(object sender,System.Windows.RoutedEventArgs e)=>System.Windows.MessageBox.Show("Выберите ПО, затем папку проекта. В автоматическом режиме Launcher сам подготовит допустимые пакеты и запустит Autodesk.","Справка"); private void Diagnostics_Click(object sender,System.Windows.RoutedEventArgs e)=>System.Windows.MessageBox.Show($"{selected?.Diagnostic}\n{ProjectPath.Text}\n{Status.Text}","Диагностика Launcher Next"); }