Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
155 lines (134 loc) · 4.61 KB
/
Copy pathProgram.cs
File metadata and controls
155 lines (134 loc) · 4.61 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System;
using System.Diagnostics;
using System.Linq;
using SimStarter.Core;
#nullable enable
namespace SimStarter
{
internal static class Program
{
private static ProfilesConfig _config = null!;
private static void Main()
{
Console.Title = "Sim Starter (CLI)";
_config = ProfilesStore.LoadOrCreate();
while (true)
{
ShowMainMenu();
var input = ReadNonEmpty("Choice");
switch (input.ToLowerInvariant())
{
case "q":
return;
case "s":
StartStarter();
break;
case "r":
_config = ProfilesStore.LoadOrCreate();
break;
case "o":
OpenConfigInEditor();
break;
default:
Console.WriteLine("Unknown command.");
break;
}
}
}
private static void ShowMainMenu()
{
Console.WriteLine();
Console.WriteLine("=== Sim Starter ===");
Console.WriteLine("Profiles file: " + ProfilesStore.GetConfigPath());
Console.WriteLine();
if (_config.Starters.Count == 0)
{
Console.WriteLine("No starters configured yet. Use the WPF app to set them up.");
}
else
{
Console.WriteLine("Starters:");
for (var i = 0; i < _config.Starters.Count; i++)
{
Console.WriteLine($" {i + 1}. {_config.Starters[i].Name}");
}
}
Console.WriteLine();
Console.WriteLine("Commands:");
Console.WriteLine(" s - Start a starter profile");
Console.WriteLine(" r - Reload profiles.json");
Console.WriteLine(" o - Open profiles.json in editor");
Console.WriteLine(" q - Quit");
}
// --- Starter operations ------------------------------------------------
private static void StartStarter()
{
if (_config.Starters.Count == 0)
{
Console.WriteLine("No starters to start. Use the WPF app to configure.");
return;
}
Console.WriteLine();
Console.WriteLine("--- Start starter ---");
for (var i = 0; i < _config.Starters.Count; i++)
{
Console.WriteLine($" {i + 1}. {_config.Starters[i].Name}");
}
var str = ReadNonEmpty("Starter number (or 'b' to cancel)");
if (str.Equals("b", StringComparison.OrdinalIgnoreCase))
{
return;
}
if (!int.TryParse(str, out var index))
{
Console.WriteLine("Invalid number.");
return;
}
index -= 1;
if (index < 0 || index >= _config.Starters.Count)
{
Console.WriteLine("Invalid index.");
return;
}
var starter = _config.Starters[index];
if (string.IsNullOrWhiteSpace(starter.SimId))
{
Console.WriteLine("Starter has no sim configured.");
return;
}
StarterRunner.RunStarter(_config, starter);
Console.WriteLine("Press any key to return to menu...");
Console.ReadKey(intercept: true);
}
// --- Utilities ---------------------------------------------------------
private static string ReadNonEmpty(string label)
{
while (true)
{
Console.Write(label + ": ");
var s = Console.ReadLine();
if (!string.IsNullOrWhiteSpace(s))
return s.Trim();
Console.WriteLine("Value cannot be empty.");
}
}
private static void OpenConfigInEditor()
{
var path = ProfilesStore.GetConfigPath();
try
{
Console.WriteLine("Opening config: " + path);
var psi = new ProcessStartInfo
{
FileName = path,
UseShellExecute = true
};
Process.Start(psi);
}
catch (Exception ex)
{
Console.WriteLine("Failed to open config: " + ex.Message);
}
}
}
}