Files
OfficeTool/Pages/PreInstallCheckPage.xaml.cs
hariel1985 eac8813cc0 v1.09 — Fix ODT download, selective removal, Display Level Full
- Direct CDN download (officecdn.microsoft.com/pr/wsus/setup.exe) instead of broken fwlink redirect
- HttpClient with proper redirect handling, content-type check, file size validation
- Selective C2R removal: each product listed separately, only checked items removed
- OfficeDetector splits ProductReleaseIds into individual entries
- Display Level="Full" for removal (shows Microsoft progress UI)
- Confirmation dialog before removal on all pages

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

165 sor
6.5 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using InstaSoftOfficeTool.Models;
using InstaSoftOfficeTool.Services;
namespace InstaSoftOfficeTool.Pages
{
public partial class PreInstallCheckPage : Page
{
private readonly MainWindow _main;
private List<InstalledOffice> _detected;
public PreInstallCheckPage(MainWindow main)
{
InitializeComponent();
_main = main;
Loaded += (s, e) => DetectOffice();
}
private void DetectOffice()
{
_detected = OfficeDetector.Detect();
OfficeListPanel.Children.Clear();
if (_detected.Count == 0)
{
SubtitleText.Text = "Nincs kor\u00e1bbi Office telep\u00edt\u00e9s a g\u00e9pen.";
NoOfficeCard.Visibility = Visibility.Visible;
BtnRemove.Visibility = Visibility.Collapsed;
LicenseCleanupPanel.Visibility = Visibility.Collapsed;
BtnSkip.Content = "Tov\u00e1bb a telep\u00edt\u00e9shez \u2192";
return;
}
SubtitleText.Text = "A sz\u00e1m\u00edt\u00f3g\u00e9pen tal\u00e1lt Office telep\u00edt\u00e9sek. Az \u00faj Office telep\u00edt\u00e9se el\u0151tt aj\u00e1nlott elt\u00e1vol\u00edtani.";
BtnRemove.Visibility = Visibility.Visible;
LicenseCleanupPanel.Visibility = Visibility.Visible;
foreach (var office in _detected)
{
var cb = new CheckBox
{
Content = office.DisplayName +
(string.IsNullOrEmpty(office.Version) ? "" : " (" + office.Version + ")"),
IsChecked = true,
Style = (Style)FindResource("FluentCheckBox"),
Tag = office,
Margin = new Thickness(0, 4, 0, 4),
FontSize = 14
};
OfficeListPanel.Children.Add(cb);
}
}
private void BtnSkip_Click(object sender, RoutedEventArgs e)
{
_main.ProceedToInstall();
}
private async void BtnRemove_Click(object sender, RoutedEventArgs e)
{
bool confirmed = await _main.ConfirmAsync(
"Office elt\u00e1vol\u00edt\u00e1s",
"Biztosan el szeretn\u00e9 t\u00e1vol\u00edtani a kiv\u00e1lasztott Office telep\u00edt\u00e9seket az \u00faj verzi\u00f3 telep\u00edt\u00e9se el\u0151tt?",
"Elt\u00e1vol\u00edt\u00e1s", "M\u00e9gse");
if (!confirmed) return;
BtnRemove.IsEnabled = false;
BtnSkip.IsEnabled = false;
LogPanel.Visibility = Visibility.Visible;
try
{
var c2rProducts = new System.Collections.Generic.List<string>();
foreach (UIElement child in OfficeListPanel.Children)
{
if (child is CheckBox cb && cb.IsChecked == true)
{
var office = (InstalledOffice)cb.Tag;
if (office.IsClickToRun)
{
c2rProducts.Add(office.ProductCode);
}
else if (!string.IsNullOrEmpty(office.ProductCode))
{
AppendLog("MSI elt\u00e1vol\u00edt\u00e1s: " + office.DisplayName);
var runner = new ProcessRunner();
runner.OutputReceived += msg => Dispatcher.Invoke(() => AppendLog(msg));
int code = await runner.RunAsync("msiexec", "/x " + office.ProductCode + " /qb");
AppendLog("MSI exit code: " + code);
}
}
}
if (c2rProducts.Count > 0)
{
AppendLog("Click-to-Run term\u00e9kek elt\u00e1vol\u00edt\u00e1sa: " + string.Join(", ", c2rProducts));
var downloader = new OdtDownloader();
downloader.StatusChanged += msg => Dispatcher.Invoke(() => AppendLog(msg));
bool ok = await downloader.DownloadAndExtractAsync();
if (!ok)
{
AppendLog("HIBA: Az ODT let\u00f6lt\u00e9se sikertelen.");
BtnRemove.IsEnabled = true;
BtnSkip.IsEnabled = true;
return;
}
string removeXml = OdtXmlGenerator.GenerateRemoveProducts(c2rProducts.ToArray());
string xmlPath = Path.Combine(downloader.OdtFolder, "remove.xml");
File.WriteAllText(xmlPath, removeXml);
AppendLog("Futtat\u00e1s: setup.exe /configure remove.xml");
AppendLog("Ez eltarthat n\u00e9h\u00e1ny percig...");
int exitCode = await downloader.RunRemoveAsync(xmlPath,
msg => Dispatcher.Invoke(() => AppendLog(msg)));
AppendLog("setup.exe exit code: " + exitCode);
AppendLog(exitCode == 0
? "Office sikeresen elt\u00e1vol\u00edtva."
: "FIGYELEM: Az elt\u00e1vol\u00edt\u00e1s nem siker\u00fclt (k\u00f3d: " + exitCode + ")");
}
if (CbCleanLicense.IsChecked == true)
{
AppendLog("Licenc-adatb\u00e1zis tiszt\u00edt\u00e1sa...");
var lm = new LicenseManager();
if (lm.FindOspp())
{
var cleanResult = await lm.RemoveAllKeysAsync();
AppendLog(cleanResult);
}
else
{
AppendLog("Az ospp.vbs nem tal\u00e1lhat\u00f3 \u2014 licenc-tiszt\u00edt\u00e1s kihagyva.");
}
}
AppendLog("K\u00e9sz. Tov\u00e1bbl\u00e9p\u00e9s az \u00faj Office telep\u00edt\u00e9s\u00e9hez...");
}
catch (Exception ex)
{
AppendLog("V\u00e1ratlan hiba: " + ex.Message);
}
await System.Threading.Tasks.Task.Delay(2000);
_main.ProceedToInstall();
}
private void AppendLog(string text)
{
LogText.Text += DateTime.Now.ToString("HH:mm:ss") + " " + text + "\n";
LogText.ScrollToEnd();
}
}
}