using System; using System.IO; using System.Net; using System.Threading.Tasks; namespace InstaSoftOfficeTool.Services { public class OdtDownloader { private const string OdtDownloadUrl = "https://go.microsoft.com/fwlink/p/?LinkID=626065"; public event Action StatusChanged; public event Action ProgressChanged; public string OdtFolder { get; private set; } public string SetupExePath { get; private set; } public OdtDownloader() { OdtFolder = Path.Combine(Path.GetTempPath(), "InstaSoftODT"); } public async Task DownloadAndExtractAsync() { try { Directory.CreateDirectory(OdtFolder); var odtExePath = Path.Combine(OdtFolder, "officedeploymenttool.exe"); SetupExePath = Path.Combine(OdtFolder, "setup.exe"); if (File.Exists(SetupExePath)) { StatusChanged?.Invoke("Az ODT setup.exe m\u00e1r el\u00e9rhet\u0151, let\u00f6lt\u00e9s kihagyva."); return true; } StatusChanged?.Invoke("Office Deployment Tool let\u00f6lt\u00e9se..."); using (var client = new WebClient()) { client.DownloadProgressChanged += (s, e) => { ProgressChanged?.Invoke(e.ProgressPercentage); }; await client.DownloadFileTaskAsync(new Uri(OdtDownloadUrl), odtExePath); } StatusChanged?.Invoke("ODT kicsomagol\u00e1sa..."); var runner = new ProcessRunner(); var exitCode = await runner.RunAsync(odtExePath, "/extract:\"" + OdtFolder + "\" /quiet"); if (exitCode != 0) { StatusChanged?.Invoke("Hiba: Az ODT kicsomagol\u00e1sa sikertelen (k\u00f3d: " + exitCode + ")"); return false; } if (!File.Exists(SetupExePath)) { StatusChanged?.Invoke("Hiba: A setup.exe nem tal\u00e1lhat\u00f3 a kicsomagol\u00e1s ut\u00e1n."); return false; } StatusChanged?.Invoke("ODT sikeresen let\u00f6ltve \u00e9s kicsomagolva."); return true; } catch (Exception ex) { StatusChanged?.Invoke("Hiba a let\u00f6lt\u00e9s sor\u00e1n: " + ex.Message); return false; } } public async Task RunSetupAsync(string configXmlPath, Action outputCallback) { var runner = new ProcessRunner(); runner.OutputReceived += line => outputCallback?.Invoke(line); StatusChanged?.Invoke("Office telep\u00edt\u00e9s ind\u00edt\u00e1sa..."); return await runner.RunAsync(SetupExePath, "/configure \"" + configXmlPath + "\""); } public async Task RunRemoveAsync(string configXmlPath, Action outputCallback) { var runner = new ProcessRunner(); runner.OutputReceived += line => outputCallback?.Invoke(line); StatusChanged?.Invoke("Office elt\u00e1vol\u00edt\u00e1s ind\u00edt\u00e1sa..."); return await runner.RunAsync(SetupExePath, "/configure \"" + configXmlPath + "\""); } } }