-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
43 lines (37 loc) · 1.44 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
namespace OTAUpdate;
class Program
{
static async Task Main(string[] args)
{
string upgradeFileName = "upgrade.bin";
string serviceNameInRegistry = "my-service";
string existingServiceFileNameWindows = "my-service.exe";
string existingServiceFileNameUnix = "my-service";
string existingServiceFileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? existingServiceFileNameWindows : existingServiceFileNameUnix;
OTAUpdateHandler.CreateUpgrader( upgradeFileName, existingServiceFileName, serviceNameInRegistry);
while (true)
{
Console.WriteLine("Checking for updates...");
// Check if the upgrade file exists
if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, upgradeFileName)))
{
Console.WriteLine("Update found! Restarting the application...");
try{
OTAUpdateHandler.PerformUpgrade();
Environment.Exit(0);
}
catch (Exception ex)
{
Console.WriteLine($"Update failed: {ex.Message}");
}
}
// Delay before checking again
await Task.Delay(10000); // Wait for 10 seconds
}
}
}