Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
165 lines (151 loc) · 7.37 KB
/
Copy pathProgram.cs
File metadata and controls
165 lines (151 loc) · 7.37 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
156
157
158
159
160
161
162
163
164
165
using System;
using System.Collections.Generic;
using System.Threading;
namespace TCPTunnel
{
internal class Program
{
public static readonly Menu menu = new Menu();
static void Main(string[] args)
{
if (args.Length == 1 && args[0] == BluetoothPolicy.HelperArgument)
{
Environment.ExitCode = BluetoothPolicy.RunElevatedHelper();
return;
}
Console.OutputEncoding = System.Text.Encoding.UTF8;
ConsoleGraphic.DisableQuickEdit();
ConsoleGraphic.EnableVirtualTerminalOutput();
if (ImageViewer.TryRun(args))
return;
Lang.ApplyArguments(args);
if (Array.Exists(args, argument => argument == "-third-party-notices"))
{
var assembly = typeof(Program).Assembly;
foreach (string resource in assembly.GetManifestResourceNames())
{
if (!resource.StartsWith("TCPTunnel.NativeCrypto.", StringComparison.Ordinal)) continue;
using var reader = new System.IO.StreamReader(assembly.GetManifestResourceStream(resource));
Console.WriteLine(resource); Console.WriteLine(reader.ReadToEnd());
}
return;
}
if (Array.Exists(args, argument => argument == "-e2e-test"))
{
bool secureSuccess = TCPTunnel.Cryptography.SecureBoundaryTests.SecureWireBoundsSelfTest().GetAwaiter().GetResult() &&
ImageViewer.PrivateViewerPipeSelfTest().GetAwaiter().GetResult() &&
TCPTunnel.Cryptography.SecureBoundaryTests.SecureProfileAndHubLifecycleSelfTest().GetAwaiter().GetResult() &&
TCPTunnel.Cryptography.SecureIntegrationTests.SecureTcpSelfTest().GetAwaiter().GetResult() && TCPTunnel.Cryptography.SecureIntegrationTests.SecureBluetoothTransportSelfTest().GetAwaiter().GetResult() &&
TCPTunnel.Cryptography.SecureIntegrationTests.SecureMixedTransportSelfTest().GetAwaiter().GetResult();
Console.WriteLine(secureSuccess ? "TCPTunnel E2E test: OK" : "TCPTunnel E2E test: FAILED");
Environment.ExitCode = secureSuccess ? 0 : 1; return;
}
if (Array.Exists(args, argument => String.Equals(argument, "-stress-test", StringComparison.OrdinalIgnoreCase)))
{
bool stressSuccess = StabilityTests.Run();
Console.WriteLine(stressSuccess ? "TCPTunnel stress test: OK" : "TCPTunnel stress test: FAILED");
Environment.ExitCode = stressSuccess ? 0 : 1;
return;
}
if (Array.Exists(args, argument => String.Equals(argument, "-self-test", StringComparison.OrdinalIgnoreCase)))
{
bool success = SnakeProtocol.RunSelfTest() &&
ApplicationSettings.RunSelfTest() &&
LegacyEventProtocol.RunSelfTest() &&
Lang.RunSelfTest() &&
SystemMessageProtocol.RunSelfTest() &&
NetworkAddressResolver.RunSelfTest() &&
ImageProtocol.RunSelfTest() &&
ImageAnimationProtocol.RunSelfTest() &&
ImageInput.RunSelfTest() &&
ImageCodec.RunAnimationSelfTest() &&
ImageRenderer.RunSelfTest() &&
ImageRenderer.RunAnimationSelfTest() &&
ImageViewer.RunSelfTest() &&
ImageViewer.RunAnimationSelfTest() &&
ConsoleTitleAnimator.RunSelfTest() &&
HubBeaconCodec.RunSelfTest() &&
HubOptionRegistry.RunSelfTest() &&
UserInterface.RunCommandSelfTest();
Console.WriteLine(Lang.Get(success ? TextId.SelfTestOk : TextId.SelfTestFailed));
Environment.ExitCode = success ? 0 : 1;
Console.Out.Flush();
Thread.Sleep(TimeSpan.FromSeconds(10));
return;
}
ApplicationSettings.Initialize();
Run(args);
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
private static void Run(string[] args)
{
AppDomain.CurrentDomain.ProcessExit += delegate
{
ConsoleTitleAnimator.Stop();
WindowsTerminalTheme.TryClearBackground(out _);
ConsoleWindowState.StopTracking();
ApplicationSettings.CaptureAndSave();
ServerInterface.StopServer();
};
Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs eventArgs)
{
eventArgs.Cancel = true;
ServerInterface.StopServer();
Environment.Exit(0);
};
menu.main(new List<string>(args));
}
public static void bye()
{
ConsoleGraphic.WriteContentLine(String.Empty);
Program.matrix(Lang.Get(TextId.Goodbye));
Console.ReadKey();
ServerInterface.StopServer();
Environment.Exit(0);
}
public static void matrix(string text, int sleep = 20, ConsoleColor color = ConsoleColor.White, bool shift = true)
{
if (String.IsNullOrEmpty(text))
return;
lock (ConsoleGraphic.borderAnimationLock)
{
int left = shift ? Console.CursorLeft + 1 : Console.CursorLeft;
if (left >= Console.BufferWidth)
left = ConsoleGraphic.Enabled ? 1 : 0;
Console.SetCursorPosition(left, Console.CursorTop);
Console.ForegroundColor = color;
foreach (char symbol in text)
{
Thread.Sleep(sleep / 2);
if (symbol == '\r')
continue;
if (symbol == '\n')
{
Console.WriteLine();
if (ConsoleGraphic.Enabled && Console.CursorLeft == 0)
Console.SetCursorPosition(1, Console.CursorTop);
continue;
}
if (ConsoleGraphic.Enabled && shift && Console.CursorLeft >= Console.WindowWidth - 1)
Console.SetCursorPosition(1, Console.CursorTop + 1);
Console.Write(symbol);
Thread.Sleep(sleep / 2);
}
Console.ResetColor();
}
}
public static void bufferClear()
{
int currentTop = Console.CursorTop;
int left = ConsoleGraphic.Enabled ? 1 : 0;
int minimumTop = ConsoleGraphic.Enabled ? 1 : 0;
int targetTop = Math.Max(minimumTop, currentTop - 1);
int width = ConsoleGraphic.Enabled
? Math.Max(0, Console.WindowWidth - 2)
: Console.BufferWidth;
Console.SetCursorPosition(left, targetTop);
Console.Write(new string(' ', width));
Console.SetCursorPosition(left, targetTop);
}
}
}