96 lines
3.1 KiB
C#
96 lines
3.1 KiB
C#
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();
|
|
}
|
|
}
|
|
}
|
|
} |