SettingsDialog.xaml.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Settings Dialog
  2. //
  3. // Douglas Thrift
  4. //
  5. // SettingsDialog.xaml.cs
  6. /* Copyright 2014 Douglas Thrift
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. using System.Collections.Generic;
  21. using System.Diagnostics;
  22. using System.Linq;
  23. using System.Reflection;
  24. using System.Windows;
  25. using System.Windows.Controls;
  26. using Microsoft.Win32;
  27. public partial class SettingsDialog : Window
  28. {
  29. public SettingsDialog(IList<Handler> handlers)
  30. {
  31. InitializeComponent();
  32. IEnumerable<string> options = new string[0];
  33. using (RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Default), key = baseKey.OpenSubKey(@"ssh\shell\open\command"))
  34. if (key != null)
  35. {
  36. string command = (string)key.GetValue(null);
  37. if (!string.IsNullOrWhiteSpace(command))
  38. {
  39. var args = Shell32.CommandLineToArgv(command);
  40. options = args.Skip(1).TakeWhile(arg => arg != "%1");
  41. }
  42. }
  43. foreach (Handler handler in handlers)
  44. SettingsPanel.Children.Add(new HandlerSettingsBox(handler, options));
  45. }
  46. private void OkButton_Click(object sender, RoutedEventArgs e)
  47. {
  48. Apply();
  49. DialogResult = true;
  50. }
  51. private void ApplyButton_Click(object sender, RoutedEventArgs e)
  52. {
  53. Apply();
  54. }
  55. private void Apply()
  56. {
  57. string program = Assembly.GetEntryAssembly().Location;
  58. string[] arguments = { "/openssh", "/bash" };
  59. Debug.WriteLine("\"{0}\" {1} \"%1\"", program, string.Join(" ", arguments));
  60. }
  61. }