Files
OfficeTool/Pages/ProgressPage.xaml.cs
hariel1985 12b86e0707 v1.22 — Office 2016 MSI ISO telepítés támogatás
Office 2016 Standard és Professional Plus telepítése ISO letöltéssel
(soft.direct), ISO csatolással és a Microsoft MSI telepítő indításával.
A 2019/2021/2024 verziók továbbra is ODT-vel működnek.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 23:27:14 +02:00

387 sor
13 KiB
C#

using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using InstaSoftOfficeTool.Models;
using InstaSoftOfficeTool.Services;
namespace InstaSoftOfficeTool.Pages
{
public partial class ProgressPage : Page
{
private readonly MainWindow _main;
private readonly InstallConfig _config;
public ProgressPage(MainWindow main, InstallConfig config)
{
InitializeComponent();
_main = main;
_config = config;
}
public async void StartInstallation()
{
try
{
if (_config.IsMsiInstall)
{
await StartMsiInstallation();
}
else
{
await StartOdtInstallation();
}
}
catch (Exception ex)
{
AppendLog("HIBA: " + ex.Message);
ShowDone(false, "Váratlan hiba történt.");
}
}
private async Task StartOdtInstallation()
{
// Step 1: Download ODT
SetStepActive(Step1Icon, Step1Text);
AppendLog("ODT letöltése indul...");
var downloader = new OdtDownloader();
downloader.StatusChanged += msg => Dispatcher.Invoke(() => AppendLog(msg));
bool downloaded = await downloader.DownloadAndExtractAsync();
if (!downloaded)
{
SetStepError(Step1Icon, Step1Text);
ShowDone(false, "Az ODT letöltése sikertelen.");
return;
}
SetStepDone(Step1Icon, Step1Text);
// Step 2: Generate config XML
SetStepActive(Step2Icon, Step2Text);
AppendLog("Konfigurációs XML generálása...");
string xml = OdtXmlGenerator.Generate(_config);
string xmlPath = Path.Combine(downloader.OdtFolder, "configuration.xml");
File.WriteAllText(xmlPath, xml);
AppendLog("XML mentve: " + xmlPath);
SetStepDone(Step2Icon, Step2Text);
// Step 3: Run setup.exe /configure
SetStepActive(Step3Icon, Step3Text);
AppendLog("Office telepítés indítása...");
AppendLog("setup.exe /configure \"" + xmlPath + "\"");
int exitCode = await downloader.RunSetupAsync(xmlPath, msg =>
Dispatcher.Invoke(() => AppendLog(msg)));
if (exitCode == 0)
{
SetStepDone(Step3Icon, Step3Text);
ShowDone(true, "Az Office sikeresen települt!");
}
else
{
SetStepError(Step3Icon, Step3Text);
ShowDone(false, "A telepítés hibakóddal fejeződött be: " + exitCode);
}
}
private async Task StartMsiInstallation()
{
string isoUrl = _config.GetIsoUrl();
if (string.IsNullOrEmpty(isoUrl))
{
ShowDone(false, "Nincs elérhető ISO a kiválasztott architektúrához.");
return;
}
// Update step labels for MSI flow
Dispatcher.Invoke(() =>
{
Step1Text.Text = "Telepítő ISO letöltése...";
Step2Text.Text = "ISO csatolása...";
Step3Text.Text = "Office 2016 telepítése...";
});
var installer = new MsiInstaller();
installer.StatusChanged += msg => Dispatcher.Invoke(() => AppendLog(msg));
installer.DownloadProgress += (received, total) =>
{
Dispatcher.Invoke(() =>
{
long receivedMb = received / 1024 / 1024;
if (total > 0)
{
long totalMb = total / 1024 / 1024;
int percent = (int)(received * 100 / total);
DownloadInfo.Text = receivedMb + " MB / " + totalMb + " MB (" + percent + "%)";
MainProgress.IsIndeterminate = false;
MainProgress.Value = percent;
}
else
{
DownloadInfo.Text = receivedMb + " MB letöltve...";
}
DownloadInfo.Visibility = Visibility.Visible;
});
};
// Step 1: Download ISO
SetStepActive(Step1Icon, Step1Text);
AppendLog("ISO letöltése indul...");
bool downloaded = await installer.DownloadIsoAsync(isoUrl);
if (!downloaded)
{
SetStepError(Step1Icon, Step1Text);
ShowDone(false, "Az ISO letöltése sikertelen.");
return;
}
SetStepDone(Step1Icon, Step1Text);
// Hide download progress, reset progress bar
Dispatcher.Invoke(() =>
{
DownloadInfo.Visibility = Visibility.Collapsed;
MainProgress.IsIndeterminate = true;
});
// Step 2: Mount ISO
SetStepActive(Step2Icon, Step2Text);
bool mounted = await installer.MountIsoAsync();
if (!mounted)
{
SetStepError(Step2Icon, Step2Text);
ShowDone(false, "Az ISO csatolása sikertelen.");
return;
}
SetStepDone(Step2Icon, Step2Text);
// Step 3: Run setup.exe
SetStepActive(Step3Icon, Step3Text);
int exitCode = await installer.RunSetupAsync(msg =>
Dispatcher.Invoke(() => AppendLog(msg)));
// Dismount ISO regardless of result
await installer.DismountIsoAsync();
if (exitCode == 0)
{
SetStepDone(Step3Icon, Step3Text);
// Apply product key if provided
if (!string.IsNullOrEmpty(_config.ProductKey))
{
AppendLog("Termékkulcs telepítése...");
var lm = new LicenseManager();
if (lm.FindOspp())
{
string inpResult = await lm.InstallKeyAsync(_config.ProductKey);
AppendLog(inpResult);
AppendLog("Aktiválás...");
string actResult = await lm.ActivateAsync();
AppendLog(actResult);
}
else
{
AppendLog("Az ospp.vbs nem található — a kulcsot később a Licenc-kezelésben adhatja meg.");
}
}
ShowDone(true, "Az Office 2016 sikeresen települt!");
}
else
{
SetStepError(Step3Icon, Step3Text);
ShowDone(false, "A telepítés hibakóddal fejeződött be: " + exitCode);
}
}
private void AppendLog(string text)
{
LogText.Text += DateTime.Now.ToString("HH:mm:ss") + " " + text + "\n";
LogText.ScrollToEnd();
}
private void SetStepActive(TextBlock icon, TextBlock text)
{
Dispatcher.Invoke(() =>
{
icon.Text = "\uE72A";
icon.Foreground = (Brush)FindResource("AccentBrush");
text.Foreground = (Brush)FindResource("TextPrimaryBrush");
text.FontWeight = FontWeights.SemiBold;
});
}
private void SetStepDone(TextBlock icon, TextBlock text)
{
Dispatcher.Invoke(() =>
{
icon.Text = "\uE73E";
icon.Foreground = (Brush)FindResource("SuccessBrush");
text.Foreground = (Brush)FindResource("SuccessBrush");
text.FontWeight = FontWeights.Normal;
});
}
private void SetStepError(TextBlock icon, TextBlock text)
{
Dispatcher.Invoke(() =>
{
icon.Text = "\uE711";
icon.Foreground = (Brush)FindResource("ErrorBrush");
text.Foreground = (Brush)FindResource("ErrorBrush");
text.FontWeight = FontWeights.Normal;
});
}
private void ShowDone(bool success, string message)
{
Dispatcher.Invoke(() =>
{
MainProgress.IsIndeterminate = false;
MainProgress.Value = 100;
TitleText.Text = success ? "Telep\u00edt\u00e9s befejezve" : "Telep\u00edt\u00e9s sikertelen";
DoneIcon.Text = success ? "\uE73E" : "\uE711";
DoneIcon.Foreground = success
? (Brush)FindResource("SuccessBrush")
: (Brush)FindResource("ErrorBrush");
DoneText.Text = message;
DoneText.Foreground = DoneIcon.Foreground;
DonePanel.Visibility = Visibility.Visible;
if (success)
{
// Show activate card if no product key was provided
if (string.IsNullOrEmpty(_config.ProductKey))
{
ActivateCard.Visibility = Visibility.Visible;
}
// Show launch buttons
BuildLaunchButtons();
LaunchCard.Visibility = Visibility.Visible;
}
_main.ShowCloseButton();
});
}
private void BuildLaunchButtons()
{
LaunchButtons.Children.Clear();
var apps = new[]
{
("Word", "WINWORD.EXE"),
("Excel", "EXCEL.EXE"),
("PowerPoint", "POWERPNT.EXE"),
("Outlook", "OUTLOOK.EXE"),
};
foreach (var (name, exe) in apps)
{
// Skip if excluded
if (_config.ExcludedApps.Contains(name == "Word" ? "Word" :
name == "Excel" ? "Excel" :
name == "PowerPoint" ? "PowerPoint" :
name == "Outlook" ? "Outlook" : ""))
continue;
var btn = new Button
{
Content = name,
Style = (Style)FindResource("SecondaryButton"),
Padding = new Thickness(18, 8, 18, 8),
FontSize = 13,
Margin = new Thickness(0, 0, 8, 0),
Tag = exe
};
btn.Click += LaunchApp_Click;
LaunchButtons.Children.Add(btn);
}
}
private void LaunchApp_Click(object sender, RoutedEventArgs e)
{
var btn = (Button)sender;
var exe = (string)btn.Tag;
try
{
// Try common Office paths
var paths = new[]
{
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
"Microsoft Office", "root", "Office16", exe),
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
"Microsoft Office", "root", "Office16", exe),
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
"Microsoft Office", "Office16", exe),
};
foreach (var path in paths)
{
if (File.Exists(path))
{
Process.Start(path);
return;
}
}
// Fallback: let Windows find it
Process.Start(exe);
}
catch
{
AppendLog("Nem siker\u00fclt elind\u00edtani: " + exe);
}
}
private async void BtnActivateNow_Click(object sender, RoutedEventArgs e)
{
string key = await _main.AskProductKeyAsync();
if (string.IsNullOrEmpty(key)) return;
BtnActivateNow.IsEnabled = false;
BtnActivateNow.Content = "Aktiv\u00e1l\u00e1s...";
var lm = new LicenseManager();
if (!lm.FindOspp())
{
AppendLog("Az ospp.vbs nem tal\u00e1lhat\u00f3.");
BtnActivateNow.IsEnabled = true;
BtnActivateNow.Content = "Aktiv\u00e1l\u00e1s";
return;
}
AppendLog("Term\u00e9kkulcs telep\u00edt\u00e9se: " + key);
string inpResult = await lm.InstallKeyAsync(key);
AppendLog(inpResult);
AppendLog("Aktiv\u00e1l\u00e1s...");
string actResult = await lm.ActivateAsync();
AppendLog(actResult);
if (actResult.Contains("successful") || actResult.Contains("sikeres"))
{
BtnActivateNow.Content = "Aktiv\u00e1lva \u2713";
AppendLog("Az Office sikeresen aktiv\u00e1lva!");
}
else
{
BtnActivateNow.IsEnabled = true;
BtnActivateNow.Content = "Aktiv\u00e1l\u00e1s";
AppendLog("Az aktiv\u00e1l\u00e1s eredm\u00e9ny\u00e9t ellen\u0151rizze a kimenetben.");
}
}
}
}