WingMan – Diff between revs 36 and 37

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 36 Rev 37
Line 4... Line 4...
4 using System.ComponentModel; 4 using System.ComponentModel;
5 using System.Drawing; 5 using System.Drawing;
6 using System.IO; 6 using System.IO;
7 using System.Linq; 7 using System.Linq;
8 using System.Net; 8 using System.Net;
-   9 using System.Reflection;
9 using System.Threading; 10 using System.Threading;
10 using System.Threading.Tasks; 11 using System.Threading.Tasks;
11 using System.Windows.Forms; 12 using System.Windows.Forms;
12 using Gma.System.MouseKeyHook; 13 using Gma.System.MouseKeyHook;
-   14 using Microsoft.Win32;
13 using MQTTnet.Extensions.ManagedClient; 15 using MQTTnet.Extensions.ManagedClient;
14 using MQTTnet.Server; 16 using MQTTnet.Server;
15 using WingMan.AutoCompletion; 17 using WingMan.AutoCompletion;
16 using WingMan.Bindings; 18 using WingMan.Bindings;
17 using WingMan.Communication; 19 using WingMan.Communication;
Line 140... Line 142...
140   142  
141 private static Point TabControlClickStartPosition { get; set; } 143 private static Point TabControlClickStartPosition { get; set; }
142 private static TabControl DetachedTabControl { get; set; } 144 private static TabControl DetachedTabControl { get; set; }
Line -... Line 145...
-   145 private static Form DetachedForm { get; set; }
-   146  
-   147 /// <inheritdoc />
-   148 /// <summary>
-   149 /// Clean up any resources being used.
-   150 /// </summary>
-   151 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
-   152 protected override void Dispose(bool disposing)
-   153 {
-   154 FormCancellationTokenSource?.Dispose();
-   155 FormCancellationTokenSource = null;
-   156  
-   157 if (disposing && components != null)
-   158 {
-   159 components.Dispose();
-   160 components = null;
-   161 }
-   162  
-   163 base.Dispose(disposing);
143 private static Form DetachedForm { get; set; } 164 }
144   165  
145 private void RemoteBindingsComboBoxSourceOnListChanged(object sender, ListChangedEventArgs e) 166 private void RemoteBindingsComboBoxSourceOnListChanged(object sender, ListChangedEventArgs e)
146 { 167 {
Line 191... Line 212...
191 { 212 {
192 ActivityTextBox.AppendText( 213 ActivityTextBox.AppendText(
193 $"{Strings.Failed_saving_autocomplete_source} : {args.Name} : {args.Exception.Message}{Environment.NewLine}"); 214 $"{Strings.Failed_saving_autocomplete_source} : {args.Name} : {args.Exception.Message}{Environment.NewLine}");
194 } 215 }
Line 195... Line -...
195   -  
196 /// <inheritdoc /> -  
197 /// <summary> -  
198 /// Clean up any resources being used. -  
199 /// </summary> -  
200 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> -  
201 protected override void Dispose(bool disposing) -  
202 { -  
203 FormCancellationTokenSource?.Dispose(); -  
204 FormCancellationTokenSource = null; -  
205   -  
206 if (disposing && components != null) -  
207 { -  
208 components.Dispose(); -  
209 components = null; -  
210 } -  
211   -  
212 base.Dispose(disposing); -  
213 } -  
214   216  
215 private void OnMouseKeyBindingExecuting(object sender, KeyBindingExecutingEventArgs args) 217 private void OnMouseKeyBindingExecuting(object sender, KeyBindingExecutingEventArgs args)
216 { 218 {
217 ActivityTextBox.AppendText( 219 ActivityTextBox.AppendText(
218 $"{Strings.Executing_binding_from_remote_client} : {args.Nick} : {args.Name}{Environment.NewLine}"); 220 $"{Strings.Executing_binding_from_remote_client} : {args.Nick} : {args.Name}{Environment.NewLine}");
Line 649... Line 651...
649 UpdateRemoteBindingsListBox(); 651 UpdateRemoteBindingsListBox();
650 } 652 }
Line 651... Line 653...
651   653  
652 private async void WingManFormOnLoad(object sender, EventArgs e) 654 private async void WingManFormOnLoad(object sender, EventArgs e)
-   655 {
-   656 using (var key = Registry.CurrentUser.OpenSubKey
-   657 ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
-   658 {
-   659 switch (key.GetValue(Name) == null)
-   660 {
-   661 case true:
-   662 windowsStartupCheckBox.Checked = false;
-   663 break;
-   664 default:
-   665 windowsStartupCheckBox.Checked = true;
-   666 break;
-   667 }
-   668 }
653 { 669  
-   670 await LoadLocalKeyBindings();
-   671  
-   672 await LoadRemoteKeyBindings();
Line 654... Line 673...
654 await LoadLocalMouseKeyBindings(); 673 }
-   674  
655   675 private void WingManFormOnClosing(object sender, FormClosingEventArgs e)
Line 656... Line 676...
656 await LoadRemoteMouseKeyBindings(); 676 {
657 } 677 }
658   678  
Line 857... Line 877...
857 { 877 {
858 tabControl1.TabPages.Insert(DetachedTabControl.SelectedTab.TabIndex, DetachedTabControl.SelectedTab); 878 tabControl1.TabPages.Insert(DetachedTabControl.SelectedTab.TabIndex, DetachedTabControl.SelectedTab);
859 DetachedForm.FormClosing -= DetachedFormOnFormClosing; 879 DetachedForm.FormClosing -= DetachedFormOnFormClosing;
860 } 880 }
Line -... Line 881...
-   881  
-   882 private void LocalBindingsLoadButtonClicked(object sender, EventArgs e)
-   883 {
-   884 loadLocalBindingsDialog.ShowDialog();
-   885 }
-   886  
-   887 private void LocalBindingsSaveButtonClicked(object sender, EventArgs e)
-   888 {
-   889 saveLocalBindingsDialog.ShowDialog();
-   890 }
-   891  
-   892 private async void SaveLocalBindingsDialogOk(object sender, CancelEventArgs e)
-   893 {
-   894 using (var localBindingsStream = saveLocalBindingsDialog.OpenFile())
-   895 {
-   896 using (var memoryStream = new MemoryStream())
-   897 {
-   898 LocalKeyBindings.XmlSerializer.Serialize(memoryStream, LocalKeyBindings);
-   899  
-   900 memoryStream.Position = 0L;
-   901  
-   902 await memoryStream.CopyToAsync(localBindingsStream);
-   903 }
-   904 }
-   905 }
-   906  
-   907 private async void LoadLocalBindingsDialogOk(object sender, CancelEventArgs e)
-   908 {
-   909 using (var localBindingsStream = loadLocalBindingsDialog.OpenFile())
-   910 {
-   911 var loadedBindings = (LocalKeyBindings) LocalKeyBindings.XmlSerializer.Deserialize(localBindingsStream);
-   912  
-   913 LocalKeyBindings.Bindings.Clear();
-   914  
-   915 foreach (var binding in loadedBindings.Bindings)
-   916 LocalKeyBindings.Bindings.Add(binding);
-   917  
-   918 LocalCheckedListBoxBindingSource.ResetBindings(false);
-   919 }
-   920  
-   921 await SaveLocalMouseKeyBindings();
-   922 }
-   923  
-   924 private void SettingsWindowsStartupCheckboxCheckedChanged(object sender, EventArgs e)
-   925 {
-   926 try
-   927 {
-   928 switch (((CheckBox) sender).Checked)
-   929 {
-   930 case true:
-   931 using (var key = Registry.CurrentUser.OpenSubKey
-   932 ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
-   933 {
-   934 key.SetValue(Name, Assembly.GetEntryAssembly().Location);
-   935 }
-   936  
-   937 break;
-   938 default:
-   939 using (var key = Registry.CurrentUser.OpenSubKey
-   940 ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
-   941 {
-   942 key.DeleteValue(Name, false);
-   943 }
-   944  
-   945 break;
-   946 }
-   947  
-   948 ActivityTextBox.AppendText(
-   949 $"{Strings.Application_Windows_startup_changed}{Environment.NewLine}");
-   950 }
-   951 catch
-   952 {
-   953 ActivityTextBox.AppendText(
-   954 $"{Strings.Could_not_change_Windows_startup}{Environment.NewLine}");
-   955 }
-   956 }
861   957  
Line 862... Line 958...
862 #region Saving and loading 958 #region Saving and loading
863   959  
864 private async Task SaveLocalMouseKeyBindings() 960 private async Task SaveLocalMouseKeyBindings()
Line 882... Line 978...
882 ActivityTextBox.AppendText( 978 ActivityTextBox.AppendText(
883 $"{Strings.Failed_saving_local_bindings}{Environment.NewLine}"); 979 $"{Strings.Failed_saving_local_bindings}{Environment.NewLine}");
884 } 980 }
885 } 981 }
Line 886... Line 982...
886   982  
887 private async Task LoadLocalMouseKeyBindings() 983 private async Task LoadLocalKeyBindings()
888 { 984 {
889 try 985 try
890 { 986 {
891 using (var fileStream = new FileStream("LocalKeyBindings.xml", FileMode.Open)) 987 using (var fileStream = new FileStream("LocalKeyBindings.xml", FileMode.Open))
Line 900... Line 996...
900 (LocalKeyBindings) LocalKeyBindings.XmlSerializer.Deserialize(memoryStream); 996 (LocalKeyBindings) LocalKeyBindings.XmlSerializer.Deserialize(memoryStream);
Line 901... Line 997...
901   997  
902 foreach (var binding in loadedBindings.Bindings) 998 foreach (var binding in loadedBindings.Bindings)
Line 903... Line -...
903 LocalKeyBindings.Bindings.Add(binding); -  
904   999 LocalKeyBindings.Bindings.Add(binding);
905   1000  
906 LocalCheckedListBoxBindingSource.ResetBindings(false); 1001 LocalCheckedListBoxBindingSource.ResetBindings(false);
907 } 1002 }
908 } 1003 }
Line 935... Line 1030...
935 ActivityTextBox.AppendText( 1030 ActivityTextBox.AppendText(
936 $"{Strings.Failed_saving_remote_bindings}{Environment.NewLine}"); 1031 $"{Strings.Failed_saving_remote_bindings}{Environment.NewLine}");
937 } 1032 }
938 } 1033 }
Line 939... Line 1034...
939   1034  
940 private async Task LoadRemoteMouseKeyBindings() 1035 private async Task LoadRemoteKeyBindings()
941 { 1036 {
942 try 1037 try
943 { 1038 {
944 using (var fileStream = new FileStream("RemoteKeyBindings.xml", FileMode.Open)) 1039 using (var fileStream = new FileStream("RemoteKeyBindings.xml", FileMode.Open))