forked from dreadnought-friends/support-tool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SupportToolWindow.xaml.cs
258 lines (217 loc) · 9.59 KB
/
SupportToolWindow.xaml.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
using SupportTool.AppVersion;
using SupportTool.Command;
using SupportTool.Dreadnought;
using SupportTool.Logger;
using SupportTool.Ping;
using SupportTool.Tool;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Security.Principal;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Navigation;
namespace SupportTool
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class SupportToolWindow : Window
{
private static readonly short PingDelay = 1000;
private Config config;
private VersionChecker versionChecker;
private FileAggregator fileAggregator;
private CommandContainer commandContainer;
private ToolContainer toolContainer;
private BackgroundWorker CommandWorker = new BackgroundWorker();
private BackgroundWorker PingWorker = new BackgroundWorker();
private TextBoxLogger textBoxLogger;
private Runner runner;
private PingStorage pingStorage = new PingStorage("172.86.100.9", 240, (byte) (PingDelay / 1000));
public SupportToolWindow()
{
InitializeComponent();
Version versionInfo = Assembly.GetExecutingAssembly().GetName().Version;
string version = String.Format("{0}.{1}.{2}", versionInfo.Major, versionInfo.Minor, versionInfo.Build);
Title = String.Format("{0} - {1}", Title, version);
CommandWorker.WorkerReportsProgress = true;
CommandWorker.WorkerSupportsCancellation = true;
CommandWorker.DoWork += new DoWorkEventHandler(StartAggregateData);
CommandWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(FinishAggregateData);
CommandWorker.ProgressChanged += new ProgressChangedEventHandler(ReportAggregateData);
PingWorker.WorkerReportsProgress = true;
PingWorker.WorkerSupportsCancellation = true;
PingWorker.DoWork += new DoWorkEventHandler(StartPing);
PingWorker.ProgressChanged += new ProgressChangedEventHandler(ReportPing);
string home = Environment.GetEnvironmentVariable("userprofile");
bool isElevated;
using (WindowsIdentity identity = WindowsIdentity.GetCurrent())
{
WindowsPrincipal principal = new WindowsPrincipal(identity);
isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator);
}
config = new Config(
version,
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"DreadGame\Saved\Logs"),
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"DreadGame\Saved\Config\WindowsNoEditor"),
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
"DN_Support.zip",
"https://raw.githubusercontent.com/dreadnought-friends/tool-versions/master/versions.xml",
isElevated
);
#if DEBUG
config.ShowLogTimes = true;
#endif
InMemoryLogger inMemoryLogger = new InMemoryLogger();
textBoxLogger = new TextBoxLogger(config, inMemoryLogger, ExecutionOutput);
versionChecker = new VersionChecker(config);
BackgroundReportLogger backgroundReportLogger = new BackgroundReportLogger(config, inMemoryLogger, CommandWorker);
fileAggregator = new FileAggregator(Path.Combine(Path.GetTempPath() + "DN_Support"));
runner = new Runner(config, fileAggregator, backgroundReportLogger);
commandContainer = new CommandContainer(config, ConfigurationOptions);
commandContainer.Add(new TempDirectoryPreparation());
commandContainer.Add(new HostDeveloper());
commandContainer.Add(new CustomerSupportReadme());
commandContainer.Add(new DxDiag());
commandContainer.Add(new MsInfo());
commandContainer.Add(new Connection(pingStorage));
commandContainer.Add(new DreadnoughtLogs());
commandContainer.Add(new DreadnoughtSettings());
commandContainer.Add(new DreadnoughtCrashDumps());
commandContainer.Add(new AggregatedFileCollector());
commandContainer.Add(new Archiver());
toolContainer = new ToolContainer(config, ToolsMenuItem);
toolContainer.RegisterTool(new Tool.KeyboardSettings.ToolData(config, textBoxLogger));
toolContainer.RegisterTool(new Tool.ChangeInstallationDirectory.ToolData(textBoxLogger));
toolContainer.RegisterTool(new Tool.PingExport.ToolData(pingStorage, config, textBoxLogger));
updateLatestInfo();
RunPings();
}
private void updateLatestInfo()
{
DownloadNewVersionText.Text = "";
textBoxLogger.Clear();
try
{
VersionInfo info = versionChecker.getLatestVersionInfo();
textBoxLogger.Log(info.MotdTitle);
textBoxLogger.Log(info.MotdBody);
if (!info.IsUpToDate)
{
DownloadNewVersionLink.NavigateUri = new Uri(info.Url);
DownloadNewVersionText.Text = String.Format("Version {0} is available!", info.Version);
}
}
catch (Exception e)
{
textBoxLogger.Log(String.Format("Unable to check for a new version: {0}", e.Message));
}
}
private async Task RunPings()
{
while (true)
{
if (!PingWorker.IsBusy)
{
PingWorker.RunWorkerAsync();
}
await Task.Delay(PingDelay);
}
}
private void StartPing(object sender, DoWorkEventArgs e)
{
PingWorker.ReportProgress(1, pingStorage.Ping());
}
private void ReportPing(object sender, ProgressChangedEventArgs e)
{
var pingResult = (PingResult)e.UserState;
if (pingResult.Successful)
{
DisplayPing.Header = String.Format("Ping: {0}ms", pingResult.AveragePing);
return;
}
DisplayPing.Header = "Ping: Unknown";
}
private void StartAggregateData(object sender, DoWorkEventArgs e)
{
runner.Run(commandContainer.Commands);
}
private void FinishAggregateData(object sender, RunWorkerCompletedEventArgs e)
{
StartAggregation.IsEnabled = true;
commandContainer.Enable();
}
private void ReportAggregateData(object sender, ProgressChangedEventArgs e)
{
ExecutionOutput.AppendText(e.UserState.ToString() + Environment.NewLine);
ExecutionOutput.ScrollToEnd();
}
private void StartAggregation_Click(object sender, RoutedEventArgs e)
{
textBoxLogger.Clear();
commandContainer.Disable();
StartAggregation.IsEnabled = false;
CommandWorker.RunWorkerAsync();
}
private void OpenAggregatedFiles_Click(object sender, RoutedEventArgs e)
{
if (!Directory.Exists(fileAggregator.TempDir))
{
textBoxLogger.Log("No aggregated files found to show");
return;
}
Process.Start(fileAggregator.TempDir);
}
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
}
private void OpenDreadnoughtInstallationDirectory_Click(object sender, RoutedEventArgs e)
{
if (null == config.DnInstallationDirectory)
{
textBoxLogger.Log("Could not reliably find the Dreadnought installation directory (Hint: try Tools > Change Installation Directory)");
return;
}
var process = Process.Start(new ProcessStartInfo()
{
FileName = config.DnInstallationDirectory,
UseShellExecute = true,
Verb = "Open"
});
}
private void OpenDocumentation_Click(object sender, RoutedEventArgs e)
{
Process.Start(new ProcessStartInfo("https://github.com/dreadnought-friends/support-tool/wiki"));
}
private void ShowMessageOfTheDay_Click(object sender, RoutedEventArgs e)
{
updateLatestInfo();
}
private void RunDreadnoughtDebugLauncher_Click(object sender, RoutedEventArgs e)
{
FileInfo launcherExecutable = new FileInfo(Path.Combine(config.DnInstallationDirectory, "DreadnoughtLauncher.exe"));
if (!launcherExecutable.Exists)
{
textBoxLogger.Log("Could not reliably find the Dreadnought installation directory (Hint: try Tools > Change Installation Directory)");
return;
}
Process process = DebugLauncher.CreateProcess(launcherExecutable.FullName);
try
{
process.Start();
}
catch (Win32Exception ex)
{
if (ex.NativeErrorCode == 1223) // operation cancelled by user
{
textBoxLogger.Log("Starting the debug launcher requires administrative permissions.");
return;
}
}
}
}
}