-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
85 lines (69 loc) · 2.52 KB
/
Program.cs
File metadata and controls
85 lines (69 loc) · 2.52 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using DTInstaller.Utils;
using DTInstaller.Commands;
using static DTInstaller.Utils.Logger;
using static DTInstaller.Utils.Constants;
namespace DTInstaller
{
static class Program
{
private static readonly Dictionary<string, ICommand> _commands = new()
{
[UpdateInstaller.CommandDetails.alias] = new UpdateInstaller(),
[ScriptReinstaller.CommandDetails.alias] = new ScriptReinstaller(),
};
private static void LogAvailableCommands()
{
Log(LogVariant.Information, "Available list of commands:");
foreach (var command in _commands.Values)
{
var (name, purpose, alias) = command.CommandDetailsInstance;
LogDefault($"{name} -> {alias} : {purpose}");
}
LogDefault("Quit -> q : quit the installer");
}
static async Task Main()
{
if (OS == OperatingSystems.Windows) ConsoleQuickEdit.Disable();
LogAvailableCommands();
Log(LogVariant.Information, Texts.updatesCheckMessage);
var (isNewUpdateAvailable, didError) = await UpdatesManager.CheckForUpdates();
if (didError)
{
PromptToClose();
return;
}
if (isNewUpdateAvailable)
Log(LogVariant.Information, Texts.newUpdatesMessage);
else
Log(LogVariant.Success, Texts.upToDateMessage);
await InitConsoleCommandsListener();
}
/**
* <summary>
* Creates an infinite loop that reads commands from the user until a quit command is executed.
* </summary>
*/
private static async Task InitConsoleCommandsListener()
{
string command;
while (true)
{
command = Console.ReadLine();
if (command == "q") return;
ICommand ReceivedCommand;
bool doesCommandExist = _commands.TryGetValue(command, out ReceivedCommand);
if (!doesCommandExist)
{
Log(LogVariant.Warning, Texts.invalidCommandMessage);
continue;
}
bool hasCommandExecuted = await ReceivedCommand.Execute();
if (!hasCommandExecuted)
Log(LogVariant.Error, Texts.errorExecutingCommandMessage);
}
}
}
}