-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
78 lines (61 loc) · 2.7 KB
/
Program.cs
File metadata and controls
78 lines (61 loc) · 2.7 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
using System.Text.Json;
using TemperatureLibrary.Data;
using System.Reflection;
using TemperatureLibrary.LibsAPI;
namespace TemperatureLibrary
{
public class Programm {
public static string name = "Temperature Library";
public static string location = Assembly.GetExecutingAssembly().Location;
private static string configPath = "config.json";
private static ConsoleHider consoleHider = new();
private static StartupManagerWindows startupManagerWindows = new();
private static TemperatureLibrary temperatureLibrary = new();
private static string defaultProtocol = "http://";
private static int defaultPort = 8100;
private static string defaultApi = "/api/v2/temperature";
public static void Main(String[] args)
{
if (!File.Exists(configPath))
{
Console.WriteLine("Type token");
var token = Console.ReadLine();
Console.WriteLine("Type server address or type enter to skip");
var address = Console.ReadLine();
Console.WriteLine("Type server port or type enter to skip");
var port = Console.ReadLine();
if (port.Length != 0)
defaultPort = int.Parse(port);
if (address.Length == 0)
address = defaultProtocol + "localhost" + ":" + defaultPort + defaultApi;
else
{
bool hasProtocol = address.StartsWith(defaultProtocol) || address.StartsWith("https://");
bool hasPort = address.Contains(':');
bool hasUrl = address.EndsWith(defaultApi);
if (!hasProtocol)
address = defaultProtocol + address;
if (!hasPort)
address = address + ":" + defaultPort;
if (!hasUrl)
address = address + defaultApi;
}
using var streamWriter = new StreamWriter(configPath, true);
streamWriter.Write(
JsonSerializer.Serialize(
new ConfigData(
address,
token,
5 * 1000
)
)
);
}
if (!args.ToList().Contains("-nohide"))
consoleHider.HideWindow();
startupManagerWindows.Startup = startupManagerWindows.IsAvailable;
var configData = JsonSerializer.Deserialize<ConfigData>(File.ReadAllText(configPath));
temperatureLibrary.Launch(configData);
}
}
}