From a1d74875485470e69a6cbe0ef07764fc5002f379 Mon Sep 17 00:00:00 2001 From: krjan02 Date: Fri, 21 Mar 2025 23:34:50 +0100 Subject: [PATCH] Added Updater Project --- TeamsNetphoneLinkUpdater/Program.cs | 96 +++++++++++++++++++ .../TeamsNetphoneLinkUpdater.csproj | 11 +++ 2 files changed, 107 insertions(+) create mode 100644 TeamsNetphoneLinkUpdater/Program.cs create mode 100644 TeamsNetphoneLinkUpdater/TeamsNetphoneLinkUpdater.csproj diff --git a/TeamsNetphoneLinkUpdater/Program.cs b/TeamsNetphoneLinkUpdater/Program.cs new file mode 100644 index 0000000..cd89624 --- /dev/null +++ b/TeamsNetphoneLinkUpdater/Program.cs @@ -0,0 +1,96 @@ +using System.Diagnostics; +using System.Threading; + +namespace TeamsNetphoneLink.Updater +{ + class Program + { + private static void DeleteOldFiles(string appPath) + { + foreach (string file in Directory.GetFiles(appPath)) + { + if (Path.GetFileName(file) != "TeamsNetphoneLinkUpdater.exe" && Path.GetFileName(file) != "TeamsNetphoneLinkUpdater.dll") + { + Console.WriteLine("Deleting file {0}", Path.GetFileName(file)); + File.Delete(file); + } + } + + foreach (string dir in Directory.GetDirectories(appPath)) + { + Directory.Delete(dir, true); + Console.WriteLine("Deleting directory {0}", dir); + } + } + + private static void CopyNewFiles(string tempPath, string appPath) + { + foreach (string file in Directory.GetFiles(tempPath)) + { + if (Path.GetFileName(file) != "TeamsNetphoneLinkUpdater.exe" && Path.GetFileName(file) != "TeamsNetphoneLinkUpdater.dll") + { + string destFile = Path.Combine(appPath, Path.GetFileName(file)); + Console.WriteLine("Copy file {0}", Path.GetFileName(file)); + File.Copy(file, destFile, true); + } + } + } + + private static void LaunchMainApp(string appPath) + { + Process.Start(new ProcessStartInfo + { + FileName = Path.Combine(appPath, "TeamsNetphoneLinkWPF.exe"), + WorkingDirectory = appPath + }); + } + + static void Main(string[] args) + { + if (args.Length < 2) + { + Console.WriteLine("Usage: TeamsNetphoneLinkUpdater "); + Console.WriteLine($"Error during update: Args not satisfied!"); + Console.WriteLine("args.Length {0}", args.Length); + for (int i = 0; i < args.Length; i++) { + Console.WriteLine(" args{0} --> {1}", i, args[i]); + } + Console.ReadLine(); + + return; + } + + string appPath = args[0]; + string tempPath = args[1]; + + Console.WriteLine("Wait for Application exit..."); + while (Process.GetProcessesByName("TeamsNetphoneLinkWPF").Length != 0) + Thread.Sleep(200); + + try + { + // Step 1: Delete old files + DeleteOldFiles(appPath); + + // Step 2: Copy new files + CopyNewFiles(tempPath, appPath); + + // Step 3: Launch the main app + LaunchMainApp(appPath); + + // Step 4: Clean up + Directory.Delete(tempPath, true); + + Console.WriteLine("Update done"); + + Console.WriteLine("Exit in 10s"); + Thread.Sleep(1000*10); + } + catch (Exception ex) + { + Console.WriteLine($"Error during update: {ex.Message}"); + Console.ReadLine(); + } + } + } +} \ No newline at end of file diff --git a/TeamsNetphoneLinkUpdater/TeamsNetphoneLinkUpdater.csproj b/TeamsNetphoneLinkUpdater/TeamsNetphoneLinkUpdater.csproj new file mode 100644 index 0000000..031143d --- /dev/null +++ b/TeamsNetphoneLinkUpdater/TeamsNetphoneLinkUpdater.csproj @@ -0,0 +1,11 @@ + + + + Exe + net8.0-windows + enable + enable + ..\build + + +