Added Updater Project
This commit is contained in:
commit
a1d7487548
96
TeamsNetphoneLinkUpdater/Program.cs
Normal file
96
TeamsNetphoneLinkUpdater/Program.cs
Normal file
@ -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 <appPath> <tempPath>");
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
TeamsNetphoneLinkUpdater/TeamsNetphoneLinkUpdater.csproj
Normal file
11
TeamsNetphoneLinkUpdater/TeamsNetphoneLinkUpdater.csproj
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<BaseOutputPath>..\build</BaseOutputPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
Reference in New Issue
Block a user