- Version cards show technical info (Version 16.0 · LTSC · OS support) - 64-bit option labeled as "(ajánlott)" - Full product key paste distributes across all 5 input fields Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
138 sor
4.4 KiB
C#
138 sor
4.4 KiB
C#
using System.Text.RegularExpressions;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using InstaSoftOfficeTool.Models;
|
|
|
|
namespace InstaSoftOfficeTool.Pages
|
|
{
|
|
public partial class ProductKeyPage : Page, IWizardPage
|
|
{
|
|
private readonly MainWindow _main;
|
|
private readonly InstallConfig _config;
|
|
private readonly TextBox[] _keyBoxes;
|
|
private bool _suppressAutoTab;
|
|
|
|
public ProductKeyPage(MainWindow main, InstallConfig config)
|
|
{
|
|
InitializeComponent();
|
|
_main = main;
|
|
_config = config;
|
|
_keyBoxes = new[] { Key1, Key2, Key3, Key4, Key5 };
|
|
|
|
if (!string.IsNullOrEmpty(_config.ProductKey))
|
|
{
|
|
var parts = _config.ProductKey.Split('-');
|
|
for (int i = 0; i < parts.Length && i < 5; i++)
|
|
{
|
|
_keyBoxes[i].Text = parts[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
private void KeyBox_TextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
if (_suppressAutoTab) return;
|
|
|
|
var tb = (TextBox)sender;
|
|
var raw = tb.Text;
|
|
|
|
// Detect full key paste (contains dash or longer than 5 chars with alphanumerics)
|
|
var allAlphaNum = Regex.Replace(raw, "[^A-Za-z0-9]", "");
|
|
if (allAlphaNum.Length > 5 && tb == _keyBoxes[0])
|
|
{
|
|
// Full key pasted — distribute across all boxes
|
|
_suppressAutoTab = true;
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
int start = i * 5;
|
|
if (start < allAlphaNum.Length)
|
|
{
|
|
int len = System.Math.Min(5, allAlphaNum.Length - start);
|
|
_keyBoxes[i].Text = allAlphaNum.Substring(start, len).ToUpper();
|
|
}
|
|
}
|
|
_suppressAutoTab = false;
|
|
_keyBoxes[4].Focus();
|
|
_keyBoxes[4].CaretIndex = _keyBoxes[4].Text.Length;
|
|
ValidationMessage.Visibility = Visibility.Collapsed;
|
|
return;
|
|
}
|
|
|
|
// Clean non-alphanumeric chars
|
|
var cleaned = Regex.Replace(raw, "[^A-Za-z0-9]", "");
|
|
if (cleaned != raw)
|
|
{
|
|
_suppressAutoTab = true;
|
|
tb.Text = cleaned;
|
|
tb.CaretIndex = cleaned.Length;
|
|
_suppressAutoTab = false;
|
|
}
|
|
|
|
// Auto-tab to next box when 5 chars entered
|
|
if (tb.Text.Length == 5)
|
|
{
|
|
for (int i = 0; i < _keyBoxes.Length - 1; i++)
|
|
{
|
|
if (_keyBoxes[i] == tb)
|
|
{
|
|
_keyBoxes[i + 1].Focus();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
ValidationMessage.Visibility = Visibility.Collapsed;
|
|
}
|
|
|
|
private void CbSkipKey_Changed(object sender, RoutedEventArgs e)
|
|
{
|
|
bool skip = CbSkipKey.IsChecked == true;
|
|
foreach (var box in _keyBoxes)
|
|
{
|
|
box.IsEnabled = !skip;
|
|
if (skip) box.Text = "";
|
|
}
|
|
ValidationMessage.Visibility = Visibility.Collapsed;
|
|
}
|
|
|
|
public bool Validate()
|
|
{
|
|
if (CbSkipKey.IsChecked == true)
|
|
{
|
|
_config.ProductKey = null;
|
|
return true;
|
|
}
|
|
|
|
bool allEmpty = true;
|
|
foreach (var box in _keyBoxes)
|
|
{
|
|
if (!string.IsNullOrEmpty(box.Text))
|
|
{
|
|
allEmpty = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (allEmpty)
|
|
{
|
|
_config.ProductKey = null;
|
|
return true;
|
|
}
|
|
|
|
foreach (var box in _keyBoxes)
|
|
{
|
|
if (box.Text.Length != 5 || !Regex.IsMatch(box.Text, "^[A-Za-z0-9]{5}$"))
|
|
{
|
|
ValidationMessage.Text = "A term\u00e9kkulcsnak 5 x 5 alfanumerikus karakterb\u0151l kell \u00e1llnia.";
|
|
ValidationMessage.Visibility = Visibility.Visible;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
_config.ProductKey = string.Join("-",
|
|
Key1.Text, Key2.Text, Key3.Text, Key4.Text, Key5.Text).ToUpper();
|
|
return true;
|
|
}
|
|
}
|
|
}
|