Files
OfficeTool/Pages/TroubleshootPage.xaml.cs
hariel1985 f41b821d24 v1.08 — Custom Fluent confirmation dialog, replace all MessageBox
- New ConfirmDialog overlay with dark backdrop, rounded card, shadow
- Warning/Question/Error icon types with accent colors
- Replaced all MessageBox.Show calls (RemovePage, PreInstallCheck, Troubleshoot)
- Click outside dialog = cancel

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

267 sor
9.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using InstaSoftOfficeTool.Services;
namespace InstaSoftOfficeTool.Pages
{
public partial class TroubleshootPage : Page
{
private readonly MainWindow _main;
private readonly LicenseManager _licenseManager = new LicenseManager();
private List<LicenseEntry> _entries = new List<LicenseEntry>();
public TroubleshootPage(MainWindow main)
{
InitializeComponent();
_main = main;
Loaded += async (s, e) => await RefreshStatus();
}
private async System.Threading.Tasks.Task RefreshStatus()
{
OutputText.Text = "";
OsppPathText.Text = "";
KeyCardsPanel.Children.Clear();
BtnRemoveAll.IsEnabled = false;
BtnRemoveAll.Visibility = Visibility.Collapsed;
BtnRefresh.IsEnabled = false;
// Loading indicator
var loadingText = new TextBlock
{
Text = "Keres\u00e9s folyamatban...",
FontSize = 13,
Foreground = (Brush)FindResource("TextSecondaryBrush"),
Margin = new Thickness(0, 8, 0, 8)
};
KeyCardsPanel.Children.Add(loadingText);
bool found = _licenseManager.FindOspp();
if (!found)
{
KeyCardsPanel.Children.Clear();
var errorCard = new Border
{
Background = (Brush)FindResource("CardBrush"),
BorderBrush = (Brush)FindResource("BorderBrush"),
BorderThickness = new Thickness(1),
CornerRadius = new CornerRadius(8),
Padding = new Thickness(16, 14, 16, 14),
Margin = new Thickness(0, 0, 0, 6)
};
var errorPanel = new StackPanel();
errorPanel.Children.Add(new TextBlock
{
Text = "Az ospp.vbs nem tal\u00e1lhat\u00f3",
FontSize = 14, FontWeight = FontWeights.SemiBold,
Foreground = (Brush)FindResource("ErrorBrush")
});
errorPanel.Children.Add(new TextBlock
{
Text = "Nincs telep\u00edtett Microsoft Office, vagy nem a szok\u00e1sos helyre lett telep\u00edtve.",
FontSize = 12, Foreground = (Brush)FindResource("TextSecondaryBrush"),
TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 4, 0, 0)
});
errorCard.Child = errorPanel;
KeyCardsPanel.Children.Add(errorCard);
BtnRefresh.IsEnabled = true;
return;
}
OsppPathText.Text = "ospp.vbs helye: " + _licenseManager.OsppPath;
try
{
string status = await _licenseManager.GetStatusAsync();
OutputText.Text = status;
_entries = _licenseManager.ParseLicenseEntries(status);
BuildKeyCards();
}
catch (Exception ex)
{
KeyCardsPanel.Children.Clear();
OutputText.Text = "Hiba a lek\u00e9rdez\u00e9s sor\u00e1n: " + ex.Message;
}
BtnRefresh.IsEnabled = true;
}
private void BuildKeyCards()
{
KeyCardsPanel.Children.Clear();
if (_entries.Count == 0)
{
var noKeyCard = new Border
{
Background = (Brush)FindResource("CardBrush"),
BorderBrush = (Brush)FindResource("BorderBrush"),
BorderThickness = new Thickness(1),
CornerRadius = new CornerRadius(8),
Padding = new Thickness(16, 14, 16, 14)
};
noKeyCard.Child = new TextBlock
{
Text = "Nincs telep\u00edtett term\u00e9kkulcs.",
FontSize = 13,
Foreground = (Brush)FindResource("TextSecondaryBrush")
};
KeyCardsPanel.Children.Add(noKeyCard);
return;
}
if (_entries.Count > 1)
{
BtnRemoveAll.Visibility = Visibility.Visible;
BtnRemoveAll.IsEnabled = true;
}
foreach (var entry in _entries)
{
KeyCardsPanel.Children.Add(CreateKeyCard(entry));
}
}
private Border CreateKeyCard(LicenseEntry entry)
{
var grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
var infoPanel = new StackPanel { VerticalAlignment = VerticalAlignment.Center };
infoPanel.Children.Add(new TextBlock
{
Text = string.IsNullOrEmpty(entry.LicenseName) ? "Ismeretlen licenc" : entry.LicenseName,
FontSize = 13, FontWeight = FontWeights.SemiBold,
TextTrimming = TextTrimming.CharacterEllipsis
});
var statusLine = !string.IsNullOrEmpty(entry.ErrorDescription)
? entry.ErrorDescription
: (!string.IsNullOrEmpty(entry.Status) ? entry.Status : entry.Description);
infoPanel.Children.Add(new TextBlock
{
Text = statusLine,
FontSize = 11, Foreground = (Brush)FindResource("TextSecondaryBrush"),
TextTrimming = TextTrimming.CharacterEllipsis
});
infoPanel.Children.Add(new TextBlock
{
Text = "Kulcs: *****-" + entry.Last5,
FontSize = 11, FontFamily = new FontFamily("Consolas"),
Foreground = (Brush)FindResource("TextSecondaryBrush"),
Margin = new Thickness(0, 2, 0, 0)
});
Grid.SetColumn(infoPanel, 0);
grid.Children.Add(infoPanel);
var removeBtn = new Button
{
Content = "Elt\u00e1vol\u00edt\u00e1s",
Style = (Style)FindResource("SecondaryButton"),
Padding = new Thickness(14, 6, 14, 6),
FontSize = 12,
VerticalAlignment = VerticalAlignment.Center,
Tag = entry.Last5
};
removeBtn.Click += BtnRemoveSingle_Click;
Grid.SetColumn(removeBtn, 1);
grid.Children.Add(removeBtn);
return new Border
{
Background = (Brush)FindResource("CardBrush"),
BorderBrush = (Brush)FindResource("BorderBrush"),
BorderThickness = new Thickness(1),
CornerRadius = new CornerRadius(8),
Padding = new Thickness(16, 10, 16, 10),
Margin = new Thickness(0, 0, 0, 6),
Child = grid
};
}
private async void BtnRemoveSingle_Click(object sender, RoutedEventArgs e)
{
var btn = (Button)sender;
var last5 = (string)btn.Tag;
bool confirmed = await _main.ConfirmAsync(
"Kulcs elt\u00e1vol\u00edt\u00e1sa",
"Biztosan el szeretn\u00e9 t\u00e1vol\u00edtani a *****-" + last5 + " kulcsot?",
"Elt\u00e1vol\u00edt\u00e1s", "M\u00e9gse", DialogType.Question);
if (!confirmed) return;
btn.IsEnabled = false;
btn.Content = "...";
try
{
await _licenseManager.RemoveKeyAsync(last5);
await RefreshStatus();
}
catch (Exception ex)
{
OutputText.Text += "\nHiba: " + ex.Message;
btn.IsEnabled = true;
btn.Content = "Elt\u00e1vol\u00edt\u00e1s";
}
}
private async void BtnRefresh_Click(object sender, RoutedEventArgs e)
{
await RefreshStatus();
}
private async void BtnRemoveAll_Click(object sender, RoutedEventArgs e)
{
bool confirmed = await _main.ConfirmAsync(
"\u00d6sszes kulcs elt\u00e1vol\u00edt\u00e1sa",
"Biztosan el szeretn\u00e9 t\u00e1vol\u00edtani az \u00f6sszes telep\u00edtett term\u00e9kkulcsot (" + _entries.Count + " db)?\n\n" +
"Ez nem t\u00f6r\u00f6l adatot, csak az aktiv\u00e1ci\u00f3s \u00e1llapotot \u00e1ll\u00edtja vissza.",
"\u00d6sszes elt\u00e1vol\u00edt\u00e1sa", "M\u00e9gse");
if (!confirmed) return;
BtnRemoveAll.IsEnabled = false;
BtnRefresh.IsEnabled = false;
try
{
await _licenseManager.RemoveAllKeysAsync();
await RefreshStatus();
}
catch (Exception ex)
{
OutputText.Text += "\nHiba: " + ex.Message;
}
BtnRefresh.IsEnabled = true;
}
private void DetailsExpander_Expanded(object sender, RoutedEventArgs e)
{
// Grow window to fit details
var window = Window.GetWindow(this);
if (window != null && window.Height < 680)
window.Height = 680;
}
private void DetailsExpander_Collapsed(object sender, RoutedEventArgs e)
{
var window = Window.GetWindow(this);
if (window != null)
window.Height = 550;
}
}
}