From 93f70afbae643042caef769bfc5804822d93743f Mon Sep 17 00:00:00 2001 From: JKamue Date: Fri, 23 Aug 2024 15:44:17 +0200 Subject: [PATCH] feat: Vor Start des Programmes nach Updates schauen --- Program.cs | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/Program.cs b/Program.cs index 05c26f9..e5629dd 100644 --- a/Program.cs +++ b/Program.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using coIT.Lexoffice.GdiExport; namespace coIT.Toolkit.Lexoffice.GdiExport @@ -10,10 +11,50 @@ internal static class Program [STAThread] static void Main() { + var updatesWurdenGefundenUndWerdenDurchgeführt = UpdaterAktualisiertAnwendung(); + // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new MainForm()); + if (!updatesWurdenGefundenUndWerdenDurchgeführt) + { + ApplicationConfiguration.Initialize(); + Application.Run(new MainForm()); + } + } + + public static bool UpdaterAktualisiertAnwendung() + { + var updaterPfad = ErwarteterPfadFürUpdater(); + if (File.Exists(updaterPfad)) + { + Process process = Process.Start(updaterPfad); + process.WaitForExit(); + var code = process.ExitCode; + process.Close(); + + // Updater exit code 0 bedeutet, dass Updates gefunden wurden + // https://www.advancedinstaller.com/user-guide/updater.html#section370 + var updateGefundenExitCode = 0; + return code == updateGefundenExitCode; + } + return false; + } + + public static string ErwarteterPfadFürUpdater() + { +#if DEBUG + var appdataOrdner = Environment.GetFolderPath( + Environment.SpecialFolder.ApplicationData + ); + return Path.Combine( + appdataOrdner, + "co-IT.eu GmbH", + "Lexoffice Gdi Export", + "updater.exe" + ); +#else + return Path.Combine(Application.StartupPath, "..", "updater.exe"); +#endif } } }