Files
OfficeTool/MainWindow.xaml.cs
hariel1985 0e4253ba37 v1.10 — Activation with key dialog, auto-refresh, Access restriction, fixes
- Product key dialog: Fluent overlay with 5-field input + paste support
- Activate button on each license card asks for key first (/inpkey + /act)
- Auto-refresh lists after removal/activation on all pages
- Access checkbox disabled for Standard and Home & Business editions
- MSI uninstall: only accept {GUID} product codes (fix msiexec help popup)
- Window height properly resets when Details expander is collapsed

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 08:38:08 +02:00

222 sor
6.9 KiB
C#

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<Page> _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<Page>
{
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<Page>
{
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<Page>
{
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.Visible;
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)
{
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);
}
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<bool> 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<string> AskProductKeyAsync()
{
return KeyDialog.ShowAsync();
}
public void ShowBackToHomeButton()
{
BtnBack.Content = "\u2190 F\u0151oldal";
BtnBack.Visibility = Visibility.Visible;
}
}
public interface IWizardPage
{
bool Validate();
}
}