Winify – Diff between revs 48 and 49

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 48 Rev 49
1 using System; 1 using System;
2 using System.Collections.Concurrent; 2 using System.Collections.Concurrent;
3 using System.ComponentModel; 3 using System.ComponentModel;
4 using System.Drawing; 4 using System.Drawing;
5 using System.IO; 5 using System.IO;
6 using System.Net; 6 using System.Net;
7 using System.Reflection; 7 using System.Reflection;
8 using System.Text; 8 using System.Text;
9 using System.Threading; 9 using System.Threading;
10 using System.Threading.Tasks; 10 using System.Threading.Tasks;
11 using System.Windows.Forms; 11 using System.Windows.Forms;
12 using NetSparkleUpdater; 12 using NetSparkleUpdater;
13 using NetSparkleUpdater.Enums; 13 using NetSparkleUpdater.Enums;
14 using NetSparkleUpdater.SignatureVerifiers; 14 using NetSparkleUpdater.SignatureVerifiers;
15 using NetSparkleUpdater.UI.WinForms; 15 using NetSparkleUpdater.UI.WinForms;
16 using Serilog; 16 using Serilog;
17 using Servers; 17 using Servers;
18 using Toasts; 18 using Toasts;
19 using Winify.Gotify; 19 using Winify.Gotify;
20 using Winify.Settings; 20 using Winify.Settings;
21 using Winify.Utilities; 21 using Winify.Utilities;
22 using Winify.Utilities.Serialization; 22 using Winify.Utilities.Serialization;
23   23  
24 namespace Winify 24 namespace Winify
25 { 25 {
26 public partial class MainForm : Form 26 public partial class MainForm : Form
27 { 27 {
28 private void LogViewToolStripMenuItem_Click(object sender, EventArgs e) 28 private void LogViewToolStripMenuItem_Click(object sender, EventArgs e)
29 { 29 {
30 if (_logViewForm != null) return; 30 if (_logViewForm != null) return;
31   31  
32 _logViewForm = new LogViewForm(this, _memorySink, _cancellationToken); 32 _logViewForm = new LogViewForm(this, _memorySink, _cancellationToken);
33 _logViewForm.Closing += LogViewForm_Closing; 33 _logViewForm.Closing += LogViewForm_Closing;
34 _logViewForm.Show(); 34 _logViewForm.Show();
35 } 35 }
36   36  
37 private void LogViewForm_Closing(object sender, CancelEventArgs e) 37 private void LogViewForm_Closing(object sender, CancelEventArgs e)
38 { 38 {
39 if (_logViewForm == null) return; 39 if (_logViewForm == null) return;
40   40  
41 _logViewForm.Closing -= LogViewForm_Closing; 41 _logViewForm.Closing -= LogViewForm_Closing;
42 _logViewForm.Close(); 42 _logViewForm.Close();
43 _logViewForm = null; 43 _logViewForm = null;
44 } 44 }
45   45  
46 #region Public Enums, Properties and Fields 46 #region Public Enums, Properties and Fields
47   47  
48 public Configuration.Configuration Configuration { get; set; } 48 public Configuration.Configuration Configuration { get; set; }
49   49  
50 public ScheduledContinuation ChangedConfigurationContinuation { get; set; } 50 public ScheduledContinuation ChangedConfigurationContinuation { get; set; }
51   51  
52 public bool MemorySinkEnabled { get; set; } 52 public bool MemorySinkEnabled { get; set; }
53   53  
54 #endregion 54 #endregion
55   55  
56 #region Private Delegates, Events, Enums, Properties, Indexers and Fields 56 #region Private Delegates, Events, Enums, Properties, Indexers and Fields
57   57  
58 private AboutForm _aboutForm; 58 private AboutForm _aboutForm;
59   59  
60 private ConcurrentBag<GotifyConnection> _gotifyConnections; 60 private ConcurrentBag<GotifyConnection> _gotifyConnections;
61   61  
62 private SettingsForm _settingsForm; 62 private SettingsForm _settingsForm;
63   63  
64 private readonly SparkleUpdater _sparkle; 64 private readonly SparkleUpdater _sparkle;
65   65  
66 private readonly CancellationTokenSource _cancellationTokenSource; 66 private readonly CancellationTokenSource _cancellationTokenSource;
67   67  
68 private readonly CancellationToken _cancellationToken; 68 private readonly CancellationToken _cancellationToken;
69   69  
70 private LogViewForm _logViewForm; 70 private LogViewForm _logViewForm;
71   71  
72 private readonly LogMemorySink _memorySink; 72 private readonly LogMemorySink _memorySink;
73   73  
74 #endregion 74 #endregion
75   75  
76 #region Constructors, Destructors and Finalizers 76 #region Constructors, Destructors and Finalizers
77   77  
78 public MainForm() 78 public MainForm()
79 { 79 {
80 _cancellationTokenSource = new CancellationTokenSource(); 80 _cancellationTokenSource = new CancellationTokenSource();
81 _cancellationToken = _cancellationTokenSource.Token; 81 _cancellationToken = _cancellationTokenSource.Token;
82   82  
83 ChangedConfigurationContinuation = new ScheduledContinuation(); 83 ChangedConfigurationContinuation = new ScheduledContinuation();
84 } 84 }
85   85  
86 public MainForm(Mutex mutex) : this() 86 public MainForm(Mutex mutex) : this()
87 { 87 {
88 InitializeComponent(); 88 InitializeComponent();
89   89  
90 _memorySink = new LogMemorySink(); 90 _memorySink = new LogMemorySink();
91 Log.Logger = new LoggerConfiguration() 91 Log.Logger = new LoggerConfiguration()
92 .MinimumLevel.Debug() 92 .MinimumLevel.Debug()
93 .WriteTo.Conditional(condition => MemorySinkEnabled, configureSink => configureSink.Sink(_memorySink)) 93 .WriteTo.Conditional(condition => MemorySinkEnabled, configureSink => configureSink.Sink(_memorySink))
94 .WriteTo.File(Path.Combine(Constants.UserApplicationDirectory, "Logs", $"{Constants.AssemblyName}.log"), 94 .WriteTo.File(Path.Combine(Constants.UserApplicationDirectory, "Logs", $"{Constants.AssemblyName}.log"),
95 rollingInterval: RollingInterval.Day) 95 rollingInterval: RollingInterval.Day)
96 .CreateLogger(); 96 .CreateLogger();
97   97  
98 // Start application update. 98 // Start application update.
99 var manifestModuleName = Assembly.GetEntryAssembly().ManifestModule.FullyQualifiedName; 99 var manifestModuleName = Assembly.GetEntryAssembly().ManifestModule.FullyQualifiedName;
100 var icon = Icon.ExtractAssociatedIcon(manifestModuleName); 100 var icon = Icon.ExtractAssociatedIcon(manifestModuleName);
101   101  
102 _sparkle = new SparkleUpdater("https://winify.grimore.org/update/appcast.xml", 102 _sparkle = new SparkleUpdater("https://winify.grimore.org/update/appcast.xml",
103 new Ed25519Checker(SecurityMode.Strict, "LonrgxVjSF0GnY4hzwlRJnLkaxnDn2ikdmOifILzLJY=")) 103 new Ed25519Checker(SecurityMode.Strict, "LonrgxVjSF0GnY4hzwlRJnLkaxnDn2ikdmOifILzLJY="))
104 { 104 {
105 UIFactory = new UIFactory(icon), 105 UIFactory = new UIFactory(icon),
106 RelaunchAfterUpdate = true, 106 RelaunchAfterUpdate = true,
107 SecurityProtocolType = SecurityProtocolType.Tls12 107 SecurityProtocolType = SecurityProtocolType.Tls12
108 }; 108 };
109 _sparkle.StartLoop(true, true); 109 _sparkle.StartLoop(true, true);
110 } 110 }
111   111  
112 /// <summary> 112 /// <summary>
113 /// Clean up any resources being used. 113 /// Clean up any resources being used.
114 /// </summary> 114 /// </summary>
115 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 115 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
116 protected override void Dispose(bool disposing) 116 protected override void Dispose(bool disposing)
117 { 117 {
118 if (disposing && components != null) components.Dispose(); 118 if (disposing && components != null) components.Dispose();
119   119  
120 base.Dispose(disposing); 120 base.Dispose(disposing);
121 } 121 }
122   122  
123 #endregion 123 #endregion
124   124  
125 #region Event Handlers 125 #region Event Handlers
126   126  
127 private async void MainForm_Load(object sender, EventArgs e) 127 private async void MainForm_Load(object sender, EventArgs e)
128 { 128 {
129 Configuration = await LoadConfiguration(); 129 Configuration = await LoadConfiguration();
130   130  
131 var servers = await LoadServers(); 131 var servers = await LoadServers();
132 _gotifyConnections = new ConcurrentBag<GotifyConnection>(); 132 _gotifyConnections = new ConcurrentBag<GotifyConnection>();
133 foreach (var server in servers.Server) 133 foreach (var server in servers.Server)
134 { 134 {
135 var gotifyConnection = new GotifyConnection(server, Configuration); 135 var gotifyConnection = new GotifyConnection(server, Configuration);
136 gotifyConnection.GotifyNotification += GotifyConnection_GotifyNotification; 136 gotifyConnection.GotifyNotification += GotifyConnection_GotifyNotification;
137 gotifyConnection.Start(); 137 gotifyConnection.Start();
138 _gotifyConnections.Add(gotifyConnection); 138 _gotifyConnections.Add(gotifyConnection);
139 } 139 }
140 } 140 }
141   141  
142 private async void SettingsToolStripMenuItem_Click(object sender, EventArgs e) 142 private async void SettingsToolStripMenuItem_Click(object sender, EventArgs e)
143 { 143 {
144 if (_settingsForm == null) 144 if (_settingsForm == null)
145 { 145 {
146 var servers = await LoadServers(); 146 var servers = await LoadServers();
147 var announcements = await LoadAnnouncements(); 147 var announcements = await LoadAnnouncements();
148   148  
149 _settingsForm = new SettingsForm(this, servers, announcements, _cancellationToken); 149 _settingsForm = new SettingsForm(this, servers, announcements, _cancellationToken);
150 _settingsForm.Save += SettingsForm_Save; 150 _settingsForm.Save += SettingsForm_Save;
151 _settingsForm.Closing += SettingsForm_Closing; 151 _settingsForm.Closing += SettingsForm_Closing;
152 _settingsForm.Show(); 152 _settingsForm.Show();
153 } 153 }
154 } 154 }
155   155  
156 private async void SettingsForm_Save(object sender, SettingsSavedEventArgs e) 156 private async void SettingsForm_Save(object sender, SettingsSavedEventArgs e)
157 { 157 {
158 // Save the servers. 158 // Save the servers.
159 await Task.WhenAll(SaveServers(e.Servers), SaveAnnouncements(e.Announcements)); 159 await Task.WhenAll(SaveServers(e.Servers), SaveAnnouncements(e.Announcements));
160   160  
161 // Update connections to gotify servers. 161 // Update connections to gotify servers.
162 while (_gotifyConnections.TryTake(out var gotifyConnection)) 162 while (_gotifyConnections.TryTake(out var gotifyConnection))
163 { 163 {
164 gotifyConnection.GotifyNotification -= GotifyConnection_GotifyNotification; 164 gotifyConnection.GotifyNotification -= GotifyConnection_GotifyNotification;
165 gotifyConnection.Stop(); 165 gotifyConnection.Stop();
166 gotifyConnection.Dispose(); 166 gotifyConnection.Dispose();
167 gotifyConnection = null; 167 gotifyConnection = null;
168 } 168 }
169   169  
170 foreach (var server in e.Servers.Server) 170 foreach (var server in e.Servers.Server)
171 { 171 {
172 var gotifyConnection = new GotifyConnection(server, Configuration); 172 var gotifyConnection = new GotifyConnection(server, Configuration);
173 gotifyConnection.GotifyNotification += GotifyConnection_GotifyNotification; 173 gotifyConnection.GotifyNotification += GotifyConnection_GotifyNotification;
174 gotifyConnection.Start(); 174 gotifyConnection.Start();
175 _gotifyConnections.Add(gotifyConnection); 175 _gotifyConnections.Add(gotifyConnection);
176 } 176 }
177 } 177 }
178   178  
179 private async void GotifyConnection_GotifyNotification(object sender, GotifyNotificationEventArgs e) 179 private async void GotifyConnection_GotifyNotification(object sender, GotifyNotificationEventArgs e)
180 { 180 {
181 var announcements = await LoadAnnouncements(); 181 var announcements = await LoadAnnouncements();
182   182  
183 foreach (var announcement in announcements.Announcement) 183 foreach (var announcement in announcements.Announcement)
184 if (announcement.AppId == e.Notification.AppId) 184 if (announcement.AppId == e.Notification.AppId)
185 { 185 {
186 var configuredNotification = new ToastForm( 186 var configuredNotification = new ToastForm(
187 $"{e.Notification.Title} ({e.Notification.Server.Name}/{e.Notification.AppId})", 187 $"{e.Notification.Title} ({e.Notification.Server.Name}/{e.Notification.AppId})",
188 e.Notification.Message, announcement.LingerTime, e.Image); 188 e.Notification.Message, announcement.LingerTime, e.Image);
189   189  
190 Application.Run(configuredNotification); 190 Application.Run(configuredNotification);
191   191  
192 return; 192 return;
193 } 193 }
194   194  
195 var notification = new ToastForm( 195 var notification = new ToastForm(
196 $"{e.Notification.Title} ({e.Notification.Server.Name}/{e.Notification.AppId})", 196 $"{e.Notification.Title} ({e.Notification.Server.Name}/{e.Notification.AppId})",
197 e.Notification.Message, 5000, e.Image); 197 e.Notification.Message, 5000, e.Image);
198   198  
199 Application.Run(notification); 199 Application.Run(notification);
200 } 200 }
201   201  
202 private void SettingsForm_Closing(object sender, CancelEventArgs e) 202 private void SettingsForm_Closing(object sender, CancelEventArgs e)
203 { 203 {
204 if (_settingsForm == null) return; 204 if (_settingsForm == null) return;
205   205  
206 _settingsForm.Save -= SettingsForm_Save; 206 _settingsForm.Save -= SettingsForm_Save;
207 _settingsForm.Closing -= SettingsForm_Closing; 207 _settingsForm.Closing -= SettingsForm_Closing;
208 _settingsForm.Dispose(); 208 _settingsForm.Dispose();
209 _settingsForm = null; 209 _settingsForm = null;
210 } 210 }
211   211  
212 private void AboutToolStripMenuItem_Click(object sender, EventArgs e) 212 private void AboutToolStripMenuItem_Click(object sender, EventArgs e)
213 { 213 {
214 if (_aboutForm != null) return; 214 if (_aboutForm != null) return;
215   215  
216 _aboutForm = new AboutForm(); 216 _aboutForm = new AboutForm();
217 _aboutForm.Closing += AboutForm_Closing; 217 _aboutForm.Closing += AboutForm_Closing;
218 _aboutForm.Show(); 218 _aboutForm.Show();
219 } 219 }
220   220  
221 private void AboutForm_Closing(object sender, CancelEventArgs e) 221 private void AboutForm_Closing(object sender, CancelEventArgs e)
222 { 222 {
223 if (_aboutForm == null) return; 223 if (_aboutForm == null) return;
224   224  
225 _aboutForm.Closing -= AboutForm_Closing; 225 _aboutForm.Closing -= AboutForm_Closing;
226 _aboutForm.Dispose(); 226 _aboutForm.Dispose();
227 _aboutForm = null; 227 _aboutForm = null;
228 } 228 }
229   229  
230 private void QuitToolStripMenuItem_Click(object sender, EventArgs e) 230 private void QuitToolStripMenuItem_Click(object sender, EventArgs e)
231 { 231 {
232 Close(); 232 Close();
233 } 233 }
234   234  
235 private async void UpdateToolStripMenuItem_Click(object sender, EventArgs e) 235 private async void UpdateToolStripMenuItem_Click(object sender, EventArgs e)
236 { 236 {
237 // Manually check for updates, this will not show a ui 237 // Manually check for updates, this will not show a ui
238 var result = await _sparkle.CheckForUpdatesQuietly(); 238 var result = await _sparkle.CheckForUpdatesQuietly();
239 var updates = result.Updates; 239 var updates = result.Updates;
240 if (result.Status == UpdateStatus.UpdateAvailable) 240 if (result.Status == UpdateStatus.UpdateAvailable)
241 { 241 {
242 // if update(s) are found, then we have to trigger the UI to show it gracefully 242 // if update(s) are found, then we have to trigger the UI to show it gracefully
243 _sparkle.ShowUpdateNeededUI(); 243 _sparkle.ShowUpdateNeededUI();
244 return; 244 return;
245 } 245 }
246   246  
247 MessageBox.Show("No updates available at this time.", "Horizon", MessageBoxButtons.OK, 247 MessageBox.Show("No updates available at this time.", "Winify", MessageBoxButtons.OK,
248 MessageBoxIcon.Asterisk, 248 MessageBoxIcon.Asterisk,
249 MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, false); 249 MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, false);
250 } 250 }
251   251  
252 #endregion 252 #endregion
253   253  
254 #region Public Methods 254 #region Public Methods
255   255  
256 public async Task SaveConfiguration() 256 public async Task SaveConfiguration()
257 { 257 {
258 if (!Directory.Exists(Constants.UserApplicationDirectory)) 258 if (!Directory.Exists(Constants.UserApplicationDirectory))
259 Directory.CreateDirectory(Constants.UserApplicationDirectory); 259 Directory.CreateDirectory(Constants.UserApplicationDirectory);
260   260  
261 switch (await Serialization.Serialize(Configuration, Constants.ConfigurationFile, "Configuration", 261 switch (await Serialization.Serialize(Configuration, Constants.ConfigurationFile, "Configuration",
262 "<!ATTLIST Configuration xmlns:xsi CDATA #IMPLIED xsi:noNamespaceSchemaLocation CDATA #IMPLIED>", 262 "<!ATTLIST Configuration xmlns:xsi CDATA #IMPLIED xsi:noNamespaceSchemaLocation CDATA #IMPLIED>",
263 CancellationToken.None)) 263 CancellationToken.None))
264 { 264 {
265 case SerializationSuccess<Configuration.Configuration> _: 265 case SerializationSuccess<Configuration.Configuration> _:
266 Log.Information("Serialized configuration."); 266 Log.Information("Serialized configuration.");
267 break; 267 break;
268 case SerializationFailure serializationFailure: 268 case SerializationFailure serializationFailure:
269 Log.Warning(serializationFailure.Exception.Message, "Failed to serialize configuration."); 269 Log.Warning(serializationFailure.Exception.Message, "Failed to serialize configuration.");
270 break; 270 break;
271 } 271 }
272 } 272 }
273   273  
274 public static async Task<Configuration.Configuration> LoadConfiguration() 274 public static async Task<Configuration.Configuration> LoadConfiguration()
275 { 275 {
276 if (!Directory.Exists(Constants.UserApplicationDirectory)) 276 if (!Directory.Exists(Constants.UserApplicationDirectory))
277 Directory.CreateDirectory(Constants.UserApplicationDirectory); 277 Directory.CreateDirectory(Constants.UserApplicationDirectory);
278   278  
279 var deserializationResult = 279 var deserializationResult =
280 await Serialization.Deserialize<Configuration.Configuration>(Constants.ConfigurationFile, 280 await Serialization.Deserialize<Configuration.Configuration>(Constants.ConfigurationFile,
281 Constants.ConfigurationNamespace, Constants.ConfigurationXsd, CancellationToken.None); 281 Constants.ConfigurationNamespace, Constants.ConfigurationXsd, CancellationToken.None);
282   282  
283 switch (deserializationResult) 283 switch (deserializationResult)
284 { 284 {
285 case SerializationSuccess<Configuration.Configuration> serializationSuccess: 285 case SerializationSuccess<Configuration.Configuration> serializationSuccess:
286 return serializationSuccess.Result; 286 return serializationSuccess.Result;
287 case SerializationFailure serializationFailure: 287 case SerializationFailure serializationFailure:
288 Log.Warning(serializationFailure.Exception, "Failed to load configuration."); 288 Log.Warning(serializationFailure.Exception, "Failed to load configuration.");
289 return new Configuration.Configuration(); 289 return new Configuration.Configuration();
290 default: 290 default:
291 return new Configuration.Configuration(); 291 return new Configuration.Configuration();
292 } 292 }
293 } 293 }
294   294  
295 #endregion 295 #endregion
296   296  
297 #region Private Methods 297 #region Private Methods
298   298  
299 private static async Task SaveAnnouncements(Announcements.Announcements announcements) 299 private static async Task SaveAnnouncements(Announcements.Announcements announcements)
300 { 300 {
301 switch (await Serialization.Serialize(announcements, Constants.AnnouncementsFile, "Announcements", 301 switch (await Serialization.Serialize(announcements, Constants.AnnouncementsFile, "Announcements",
302 "<!ATTLIST Announcements xmlns:xsi CDATA #IMPLIED xsi:noNamespaceSchemaLocation CDATA #IMPLIED>", 302 "<!ATTLIST Announcements xmlns:xsi CDATA #IMPLIED xsi:noNamespaceSchemaLocation CDATA #IMPLIED>",
303 CancellationToken.None)) 303 CancellationToken.None))
304 { 304 {
305 case SerializationFailure serializationFailure: 305 case SerializationFailure serializationFailure:
306 Log.Warning(serializationFailure.Exception, "Unable to serialize announcements."); 306 Log.Warning(serializationFailure.Exception, "Unable to serialize announcements.");
307 break; 307 break;
308 } 308 }
309 } 309 }
310   310  
311 private static async Task SaveServers(Servers.Servers servers) 311 private static async Task SaveServers(Servers.Servers servers)
312 { 312 {
313 // Encrypt password for all servers. 313 // Encrypt password for all servers.
314 var deviceId = Miscellaneous.GetMachineGuid(); 314 var deviceId = Miscellaneous.GetMachineGuid();
315 var @protected = new Servers.Servers 315 var @protected = new Servers.Servers
316 { 316 {
317 Server = new BindingListWithCollectionChanged<Server>() 317 Server = new BindingListWithCollectionChanged<Server>()
318 }; 318 };
319   319  
320 foreach (var server in servers.Server) 320 foreach (var server in servers.Server)
321 { 321 {
322 var password = Encoding.UTF8.GetBytes(server.Password); 322 var password = Encoding.UTF8.GetBytes(server.Password);
323 var encrypted = await AES.Encrypt(password, deviceId); 323 var encrypted = await AES.Encrypt(password, deviceId);
324 var armored = Convert.ToBase64String(encrypted); 324 var armored = Convert.ToBase64String(encrypted);
325   325  
326 @protected.Server.Add(new Server(server.Name, server.Url, server.Username, armored)); 326 @protected.Server.Add(new Server(server.Name, server.Url, server.Username, armored));
327 } 327 }
328   328  
329 switch (await Serialization.Serialize(@protected, Constants.ServersFile, "Servers", 329 switch (await Serialization.Serialize(@protected, Constants.ServersFile, "Servers",
330 "<!ATTLIST Servers xmlns:xsi CDATA #IMPLIED xsi:noNamespaceSchemaLocation CDATA #IMPLIED>", 330 "<!ATTLIST Servers xmlns:xsi CDATA #IMPLIED xsi:noNamespaceSchemaLocation CDATA #IMPLIED>",
331 CancellationToken.None)) 331 CancellationToken.None))
332 { 332 {
333 case SerializationFailure serializationFailure: 333 case SerializationFailure serializationFailure:
334 Log.Warning(serializationFailure.Exception, "Unable to serialize servers."); 334 Log.Warning(serializationFailure.Exception, "Unable to serialize servers.");
335 break; 335 break;
336 } 336 }
337 } 337 }
338   338  
339 private static async Task<Announcements.Announcements> LoadAnnouncements() 339 private static async Task<Announcements.Announcements> LoadAnnouncements()
340 { 340 {
341 if (!Directory.Exists(Constants.UserApplicationDirectory)) 341 if (!Directory.Exists(Constants.UserApplicationDirectory))
342 Directory.CreateDirectory(Constants.UserApplicationDirectory); 342 Directory.CreateDirectory(Constants.UserApplicationDirectory);
343   343  
344 var deserializationResult = 344 var deserializationResult =
345 await Serialization.Deserialize<Announcements.Announcements>(Constants.AnnouncementsFile, 345 await Serialization.Deserialize<Announcements.Announcements>(Constants.AnnouncementsFile,
346 "urn:winify-announcements-schema", "Announcements.xsd", CancellationToken.None); 346 "urn:winify-announcements-schema", "Announcements.xsd", CancellationToken.None);
347   347  
348 switch (deserializationResult) 348 switch (deserializationResult)
349 { 349 {
350 case SerializationSuccess<Announcements.Announcements> serializationSuccess: 350 case SerializationSuccess<Announcements.Announcements> serializationSuccess:
351 return serializationSuccess.Result; 351 return serializationSuccess.Result;
352 case SerializationFailure serializationFailure: 352 case SerializationFailure serializationFailure:
353 Log.Warning(serializationFailure.Exception, "Unable to load announcements."); 353 Log.Warning(serializationFailure.Exception, "Unable to load announcements.");
354 return new Announcements.Announcements(); 354 return new Announcements.Announcements();
355 default: 355 default:
356 return new Announcements.Announcements(); 356 return new Announcements.Announcements();
357 } 357 }
358 } 358 }
359   359  
360 private static async Task<Servers.Servers> LoadServers() 360 private static async Task<Servers.Servers> LoadServers()
361 { 361 {
362 if (!Directory.Exists(Constants.UserApplicationDirectory)) 362 if (!Directory.Exists(Constants.UserApplicationDirectory))
363 Directory.CreateDirectory(Constants.UserApplicationDirectory); 363 Directory.CreateDirectory(Constants.UserApplicationDirectory);
364   364  
365 var deserializationResult = 365 var deserializationResult =
366 await Serialization.Deserialize<Servers.Servers>(Constants.ServersFile, 366 await Serialization.Deserialize<Servers.Servers>(Constants.ServersFile,
367 "urn:winify-servers-schema", "Servers.xsd", CancellationToken.None); 367 "urn:winify-servers-schema", "Servers.xsd", CancellationToken.None);
368   368  
369 switch (deserializationResult) 369 switch (deserializationResult)
370 { 370 {
371 case SerializationSuccess<Servers.Servers> serializationSuccess: 371 case SerializationSuccess<Servers.Servers> serializationSuccess:
372 // Decrypt password. 372 // Decrypt password.
373 var deviceId = Miscellaneous.GetMachineGuid(); 373 var deviceId = Miscellaneous.GetMachineGuid();
374 var @protected = new Servers.Servers 374 var @protected = new Servers.Servers
375 { 375 {
376 Server = new BindingListWithCollectionChanged<Server>() 376 Server = new BindingListWithCollectionChanged<Server>()
377 }; 377 };
378 foreach (var server in serializationSuccess.Result.Server) 378 foreach (var server in serializationSuccess.Result.Server)
379 { 379 {
380 var unarmored = Convert.FromBase64String(server.Password); 380 var unarmored = Convert.FromBase64String(server.Password);
381 var result = await AES.Decrypt(unarmored, deviceId); 381 var result = await AES.Decrypt(unarmored, deviceId);
382 var decrypted = Encoding.UTF8.GetString(result); 382 var decrypted = Encoding.UTF8.GetString(result);
383   383  
384 @protected.Server.Add(new Server(server.Name, server.Url, server.Username, decrypted)); 384 @protected.Server.Add(new Server(server.Name, server.Url, server.Username, decrypted));
385 } 385 }
386   386  
387 return @protected; 387 return @protected;
388   388  
389 case SerializationFailure serializationFailure: 389 case SerializationFailure serializationFailure:
390 Log.Warning(serializationFailure.Exception, "Unable to load servers."); 390 Log.Warning(serializationFailure.Exception, "Unable to load servers.");
391 return new Servers.Servers(); 391 return new Servers.Servers();
392   392  
393 default: 393 default:
394 return new Servers.Servers(); 394 return new Servers.Servers();
395 } 395 }
396 } 396 }
397   397  
398 #endregion 398 #endregion
399 } 399 }
400 } 400 }
401   401  
402
Generated by GNU Enscript 1.6.5.90.
402
Generated by GNU Enscript 1.6.5.90.
403   403  
404   404  
405   405