using System.Collections.Generic; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; using InstaSoftOfficeTool.Models; using InstaSoftOfficeTool.Pages; namespace InstaSoftOfficeTool { public partial class MainWindow : Window { private InstallConfig _config = new InstallConfig(); private List _wizardPages; private int _currentPageIndex = -1; private string _currentFlow; // "install", "remove", "license" public MainWindow() { InitializeComponent(); NavigateToWelcome(); } public void NavigateToWelcome() { _currentFlow = null; _currentPageIndex = -1; _config = new InstallConfig(); BtnBack.Visibility = Visibility.Collapsed; BtnNext.Visibility = Visibility.Collapsed; StepIndicator.Children.Clear(); ContentFrame.Navigate(new WelcomePage(this)); } public void StartInstallFlow() { _currentFlow = "install"; _config = new InstallConfig(); _wizardPages = new List { new VersionPage(this, _config), // 0 new EditionPage(this, _config), // 1 new ConfigPage(this, _config), // 2 new ProductKeyPage(this, _config), // 3 new SummaryPage(this, _config), // 4 new PreInstallCheckPage(this), // 5 — remove old Office new ProgressPage(this, _config) // 6 }; _currentPageIndex = 0; ShowCurrentPage(); } public void StartRemoveFlow() { _currentFlow = "remove"; _wizardPages = new List { new RemovePage(this) }; _currentPageIndex = 0; BtnNext.Visibility = Visibility.Collapsed; BtnBack.Visibility = Visibility.Visible; StepIndicator.Children.Clear(); ContentFrame.Navigate(_wizardPages[0]); } public void StartLicenseFlow() { _currentFlow = "license"; _wizardPages = new List { new TroubleshootPage(this) }; _currentPageIndex = 0; BtnNext.Visibility = Visibility.Collapsed; BtnBack.Visibility = Visibility.Visible; StepIndicator.Children.Clear(); ContentFrame.Navigate(_wizardPages[0]); } private void ShowCurrentPage() { if (_currentPageIndex < 0 || _currentPageIndex >= _wizardPages.Count) return; ContentFrame.Navigate(_wizardPages[_currentPageIndex]); UpdateStepIndicator(); UpdateButtons(); } private void UpdateStepIndicator() { StepIndicator.Children.Clear(); if (_currentFlow != "install") return; // Only show dots for install flow (exclude PreInstallCheck + Progress) int totalDots = _wizardPages.Count - 2; for (int i = 0; i < totalDots; i++) { var dot = new Ellipse { Margin = new Thickness(4, 0, 4, 0) }; if (i <= _currentPageIndex) { dot.Width = 10; dot.Height = 10; dot.Fill = (SolidColorBrush)FindResource("AccentBrush"); } else { dot.Width = 8; dot.Height = 8; dot.Fill = (SolidColorBrush)FindResource("BorderBrush"); } StepIndicator.Children.Add(dot); } } private void UpdateButtons() { BtnBack.Visibility = _currentPageIndex > 0 ? Visibility.Visible : Visibility.Collapsed; BtnNext.Visibility = Visibility.Visible; // On SummaryPage = "Tov\u00e1bb" // On PreInstallCheckPage or ProgressPage = hide if (_wizardPages[_currentPageIndex] is PreInstallCheckPage || _wizardPages[_currentPageIndex] is ProgressPage) { BtnNext.Visibility = Visibility.Collapsed; BtnBack.Visibility = Visibility.Collapsed; StepIndicator.Children.Clear(); } else { BtnNext.Content = "Tov\u00e1bb \u2192"; } } private void BtnBack_Click(object sender, RoutedEventArgs e) { // Reset window height in case a page enlarged it Height = 550; if (_currentPageIndex > 0 && _currentFlow == "install") { _currentPageIndex--; ShowCurrentPage(); } else { NavigateToWelcome(); } } private void BtnNext_Click(object sender, RoutedEventArgs e) { if (_currentFlow != "install") return; // Validate current page var currentPage = _wizardPages[_currentPageIndex]; if (currentPage is IWizardPage wizardPage && !wizardPage.Validate()) return; if (_currentPageIndex < _wizardPages.Count - 1) { _currentPageIndex++; // Refresh edition page when version changes if (_currentPageIndex == 1) { _wizardPages[1] = new EditionPage(this, _config); } // Refresh config page when edition changes (MSI/ODT mode may differ) if (_currentPageIndex == 2) { _wizardPages[2] = new ConfigPage(this, _config); } ShowCurrentPage(); } } public void ProceedToInstall() { // Jump to ProgressPage (last page in the wizard) _currentPageIndex = _wizardPages.Count - 1; ShowCurrentPage(); if (_wizardPages[_currentPageIndex] is ProgressPage progressPage) { progressPage.StartInstallation(); } } public void ShowCloseButton() { BtnNext.Content = "Bez\u00e1r\u00e1s"; BtnNext.Visibility = Visibility.Visible; BtnNext.Click -= BtnNext_Click; BtnNext.Click += (s, e) => Close(); } public Task ConfirmAsync(string title, string message, string confirmText = "Igen", string cancelText = "M\u00e9gse", DialogType type = DialogType.Warning) { return Dialog.ShowAsync(title, message, confirmText, cancelText, type); } public Task AskProductKeyAsync() { return KeyDialog.ShowAsync(); } public void ShowBackToHomeButton() { BtnBack.Content = "\u2190 F\u0151oldal"; BtnBack.Visibility = Visibility.Visible; } } public interface IWizardPage { bool Validate(); } }