/// <summary> /// Constructor; loads the history data and gets the icons for each protocol. /// </summary> /// <param name="applicationForm">Main application for for this window.</param> public HistoryWindow(MainForm applicationForm) { _applicationForm = applicationForm; InitializeComponent(); _historyListView.ListViewItemSorter = new HistoryComparer(_connections); // Get the icon for each protocol foreach (IProtocol protocol in ConnectionFactory.GetProtocols()) { Icon icon = new Icon(protocol.ProtocolIcon, 16, 16); historyImageList.Images.Add(icon); _connectionTypeIcons[protocol.ConnectionType] = historyImageList.Images.Count - 1; } // Load the history data if (File.Exists(_historyFileName)) { XmlSerializer historySerializer = new XmlSerializer(typeof (List<HistoricalConnection>)); List<HistoricalConnection> historicalConnections = null; using (XmlReader historyReader = new XmlTextReader(_historyFileName)) historicalConnections = (List<HistoricalConnection>) historySerializer.Deserialize(historyReader); foreach (HistoricalConnection historyEntry in historicalConnections) AddToHistory(historyEntry); } }
/// <summary> /// Constructor; initializes the bookmarks tree view by cloning the current folder structure from <see cref="MainForm.Bookmarks"/>. /// </summary> /// <param name="applicationForm">Main application form associated with this window.</param> public SaveConnectionWindow(MainForm applicationForm) { InitializeComponent(); bookmarksTreeView.Nodes.Add((TreeNode) applicationForm.Bookmarks.FoldersTreeView.Nodes[0].Clone()); bookmarksTreeView.SelectedNode = bookmarksTreeView.Nodes[0]; }
static void Main() { string[] arguments = Environment.GetCommandLineArgs(); string openHistory = arguments.FirstOrDefault((string s) => s.StartsWith("/openHistory:")); Guid historyGuid = Guid.Empty; if (openHistory != null) { historyGuid = new Guid(openHistory.Substring(openHistory.IndexOf(":") + 1)); List<Process> existingProcesses = new List<Process>(Process.GetProcessesByName("EasyConnect")); if (existingProcesses.Count == 0) existingProcesses.AddRange(Process.GetProcessesByName("EasyConnect.vshost")); if (existingProcesses.Count > 1) { IpcChannel ipcChannel = new IpcChannel("EasyConnectClient"); ChannelServices.RegisterChannel(ipcChannel, false); HistoryMethods historyMethods = (HistoryMethods)Activator.GetObject(typeof(HistoryMethods), "ipc://EasyConnect/HistoryMethods"); historyMethods.OpenToHistoryGuid(historyGuid); return; } } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainForm mainForm = new MainForm() { OpenToHistory = historyGuid }; if (!mainForm.Closing) Application.Run(mainForm); }
private static void Main() { string[] arguments = Environment.GetCommandLineArgs(); string openHistory = arguments.FirstOrDefault((string s) => s.StartsWith("/openHistory:")); string openBookmarks = arguments.FirstOrDefault((string s) => s.StartsWith("/openBookmarks:")); Guid historyGuid = Guid.Empty; Guid[] bookmarkGuids = null; // If a history GUID was passed in on the command line if (openHistory != null) { historyGuid = new Guid(openHistory.Substring(openHistory.IndexOf(":", StringComparison.Ordinal) + 1)); List<Process> existingProcesses = new List<Process>(Process.GetProcessesByName("EasyConnect")); if (existingProcesses.Count == 0) existingProcesses.AddRange(Process.GetProcessesByName("EasyConnect.vshost")); // If a process is already open, call the method in its IPC channel to tell it to open the given history entry and then exit this process if (existingProcesses.Count > 1) { IpcChannel ipcChannel = new IpcChannel("EasyConnectClient"); ChannelServices.RegisterChannel(ipcChannel, false); HistoryMethods historyMethods = (HistoryMethods) Activator.GetObject(typeof (HistoryMethods), "ipc://EasyConnect/HistoryMethods"); historyMethods.OpenToHistoryGuid(historyGuid); return; } } // If the user is trying to open bookmarks via the command line else if (openBookmarks != null) { string bookmarks = openBookmarks.Substring(openBookmarks.IndexOf(":", StringComparison.Ordinal) + 1); bookmarkGuids = (from bookmark in bookmarks.Split(',') where !String.IsNullOrEmpty(bookmark) select new Guid(bookmark)).ToArray(); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainForm mainForm = new MainForm(bookmarkGuids) { OpenToHistory = historyGuid }; TitleBarTabsApplicationContext applicationContext = new TitleBarTabsApplicationContext(); applicationContext.Start(mainForm); Application.Run(applicationContext); }
public Favorites(MainForm.ConnectionDelegate connectionDelegate, SecureString password) { _connectionDelegate = connectionDelegate; _password = password; if (File.Exists(_favoritesFileName)) { XmlDocument favorites = new XmlDocument(); favorites.Load(_favoritesFileName); _rootFolder.Favorites.Clear(); _rootFolder.ChildFolders.Clear(); InitializeTreeView(favorites.SelectSingleNode("/favorites"), _rootFolder); } }
public HistoryWindow(MainForm.ConnectionDelegate connectionDelegate, Favorites favoritesWindow, SecureString password) { _connectionDelegate = connectionDelegate; _favoritesWindow = favoritesWindow; _password = password; InitializeComponent(); if (File.Exists(_historyFileName)) { XmlDocument history = new XmlDocument(); history.Load(_historyFileName); foreach (XmlNode node in history.SelectNodes("/history/connection")) { HistoricalConnection historyEntry = new HistoricalConnection(node, _password); TreeNode newTreeNode = new TreeNode((String.IsNullOrEmpty(historyEntry.Name) ? historyEntry.Host : historyEntry.Name), 2, 2); if (historyEntry.LastConnection.DayOfYear == DateTime.Now.DayOfYear && historyEntry.LastConnection.Year == DateTime.Now.Year) AddTreeNode(historyTreeView.Nodes[0].Nodes[0].Nodes, newTreeNode); else if (historyEntry.LastConnection.DayOfYear == DateTime.Now.DayOfYear - 1 && historyEntry.LastConnection.Year == DateTime.Now.Year) AddTreeNode(historyTreeView.Nodes[0].Nodes[1].Nodes, newTreeNode); else if (historyEntry.LastConnection.DayOfYear >= DateTime.Now.DayOfYear - (int)DateTime.Now.DayOfWeek && historyEntry.LastConnection.Year == DateTime.Now.Year) AddTreeNode(historyTreeView.Nodes[0].Nodes[2].Nodes, newTreeNode); else if (historyEntry.LastConnection.Month == DateTime.Now.Month && historyEntry.LastConnection.Year == DateTime.Now.Year) AddTreeNode(historyTreeView.Nodes[0].Nodes[3].Nodes, newTreeNode); else if (historyEntry.LastConnection.Year == DateTime.Now.Year) AddTreeNode(historyTreeView.Nodes[0].Nodes[4].Nodes, newTreeNode); else continue; _connections[newTreeNode] = historyEntry; } } }
public MainForm() { InitializeComponent(); if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect")) { MessageBox.Show("Since this is the first time that you have run this application,\nyou will be asked to enter an access password. This password will\nbe used to protect any passwords that you associate with your\nconnections.", "Create password", MessageBoxButtons.OK, MessageBoxIcon.Information); Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect"); } while (_favorites == null || _history == null) { PasswordWindow passwordWindow = new PasswordWindow(); passwordWindow.ShowDialog(); _password = passwordWindow.Password; _password.MakeReadOnly(); try { _favorites = new Favorites(Connect, _password); _history = new HistoryWindow(Connect, _favorites, _password); } catch (CryptographicException) { DialogResult result = MessageBox.Show("Password is incorrect.", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); if (result != DialogResult.OK) { Closing = true; return; } } } _favorites.Password = _password; _history.Password = _password; ChannelServices.RegisterChannel(_ipcChannel, false); RemotingConfiguration.RegisterWellKnownServiceType(typeof(HistoryMethods), "HistoryMethods", WellKnownObjectMode.SingleCall); TabSelected += MainForm_TabSelected; TabDeselecting += MainForm_TabDeselecting; ActiveInstance = this; ConnectToHistoryMethod = ConnectToHistory; TabRenderer = new ChromeTabRenderer(this); Tabs.Add(new TitleBarTab(this) { Content = new RDCWindow(_password) }); SelectedTabIndex = 0; }
/// <summary> /// Handler method that's called when the form is shown; sets the state of <see cref="_autoHideCheckbox"/>. /// </summary> /// <param name="sender">Object from which this event originated.</param> /// <param name="e">Arguments associated with this event.</param> private void GlobalOptionsWindow_Shown(object sender, EventArgs e) { _parentTabs = Parent.TopLevelControl as MainForm; _autoHideCheckbox.Checked = _parentTabs.Options.AutoHideToolbar; List<ListItem> items = new List<ListItem> { new ListItem { Text = "Password", Value = "Rijndael" }, new ListItem { Text = "RSA Key Container", Value = "Rsa" } }; _encryptionTypeDropdown.Items.AddRange(items.Cast<object>().ToArray()); // ReSharper disable PossibleInvalidOperationException _encryptionTypeDropdown.SelectedItem = items.First(i => i.Value == _parentTabs.Options.EncryptionType.Value.ToString("G")); // ReSharper restore PossibleInvalidOperationException }
/// <summary> /// Initializes the UI, loads the bookmark and history data, and sets up the IPC remoting channel and low-level keyboard hook. /// </summary> protected void Init() { AeroPeekEnabled = false; bool convertingToRsa = false; // If the user hasn't formally selected an encryption type (either they're starting the application for the first time or are running a legacy // version that explicitly used Rijndael), ask them if they want to use RSA if (Options.EncryptionType == null) { string messageBoxText = @"Do you want to use an RSA key container to encrypt your passwords? The RSA encryption mode uses cryptographic keys associated with your Windows user account to encrypt sensitive data without having to enter an encryption password every time you start this application. However, your bookmarks file will be tied uniquely to this user account and you will be unable to share them between multiple users."; if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect")) messageBoxText += @" The alternative is to derive an encryption key from a password that you will need to enter every time that this application starts."; else messageBoxText += @" Since you've already encrypted your data with a password once, you would need to enter it one more time to decrypt it before RSA can be used."; Options.EncryptionType = MessageBox.Show(messageBoxText, "Use RSA?", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes ? EncryptionType.Rsa : EncryptionType.Rijndael; // Since they want to use RSA but already have connection data encrypted with Rijndael, we'll have to capture that password so that we can // decrypt it using Rijndael and then re-encrypt it using the RSA keypair convertingToRsa = Options.EncryptionType == EncryptionType.Rsa && Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect"); } // If this is the first time that the user is running the application, pop up and information box informing them that they're going to enter a // password used to encrypt sensitive connection details if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect")) { if (Options.EncryptionType == EncryptionType.Rijndael) MessageBox.Show(Resources.FirstRunPasswordText, Resources.FirstRunPasswordTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect"); } if (Options.EncryptionType != null) Options.Save(); bool encryptionTypeSet = false; while (Bookmarks == null || _history == null) { // Get the user's encryption password via the password dialog if (!encryptionTypeSet && (Options.EncryptionType == EncryptionType.Rijndael || convertingToRsa)) { PasswordWindow passwordWindow = new PasswordWindow(); passwordWindow.ShowDialog(); ConnectionFactory.SetEncryptionType(EncryptionType.Rijndael, passwordWindow.Password); } else ConnectionFactory.SetEncryptionType(Options.EncryptionType.Value); // Create the bookmark and history windows which will try to use the password to decrypt sensitive connection details; if it's unable to, an // exception will be thrown that wraps a CryptographicException instance try { _bookmarks = new BookmarksWindow(this); _history = new HistoryWindow(this); ConnectionFactory.GetDefaultProtocol(); encryptionTypeSet = true; } catch (Exception e) { if ((Options.EncryptionType == EncryptionType.Rijndael || convertingToRsa) && !ContainsCryptographicException(e)) throw; // Tell the user that their password is incorrect and, if they click OK, repeat the process DialogResult result = MessageBox.Show( Resources.IncorrectPasswordText, Resources.ErrorTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Error); if (result != DialogResult.OK) { IsClosing = true; return; } } } // If we're converting over to RSA, we've already loaded and decrypted the sensitive data using if (convertingToRsa) SetEncryptionType(Options.EncryptionType.Value, null); // Create a remoting channel used to tell this window to open historical connections when entries in the jump list are clicked if (_ipcChannel == null) { _ipcChannel = new IpcServerChannel("EasyConnect"); ChannelServices.RegisterChannel(_ipcChannel, false); RemotingConfiguration.RegisterWellKnownServiceType(typeof (HistoryMethods), "HistoryMethods", WellKnownObjectMode.SingleCall); } // Wire up the tab event handlers TabClicked += MainForm_TabClicked; ActiveInstance = this; ConnectToHistoryMethod = ConnectToHistory; TabRenderer = new ChromeTabRenderer(this); // Get the low-level keyboard hook that will be used to process shortcut keys using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { _hookproc = KeyboardHookCallback; _hookId = User32.SetWindowsHookEx(WH.WH_KEYBOARD_LL, _hookproc, Kernel32.GetModuleHandle(curModule.ModuleName), 0); } }
public ConnectionWindow(Favorites favorites, RDCConnection connection, MainForm.ConnectionDelegate connectionDelegate, SecureString password) { InitializeComponent(); _connection = connection; _favorites = favorites; _connectionDelegate = connectionDelegate; _password = password; keyboardDropdown.SelectedIndex = 1; rdcImage.Parent = gradientBackground; rdcLabel1.Parent = gradientBackground; rdcLabel2.Parent = gradientBackground; DEVMODE devMode = new DEVMODE(); int modeNumber = 0; while (DisplayHelper.EnumDisplaySettings(null, modeNumber, ref devMode) > 0) { if (!_resolutions.Exists((DEVMODE d) => d.dmPelsWidth == devMode.dmPelsWidth && d.dmPelsHeight == devMode.dmPelsHeight)) _resolutions.Add(devMode); modeNumber++; } resolutionTrackBar.Maximum = _resolutions.Count; resolutionTrackBar.Value = _resolutions.Count; if (connection != null) { hostBox.Text = connection.Host; usernameTextBox.Text = connection.Username; passwordTextBox.SecureText = (connection.Password == null ? new SecureString() : connection.Password.Copy()); keyboardDropdown.SelectedIndex = (int)connection.KeyboardMode; printersCheckBox.Checked = connection.ConnectPrinters; clipboardCheckBox.Checked = connection.ConnectClipboard; drivesCheckBox.Checked = connection.ConnectDrives; desktopBackgroundCheckBox.Checked = connection.DesktopBackground; fontSmoothingCheckBox.Checked = connection.FontSmoothing; desktopCompositionCheckBox.Checked = connection.DesktopComposition; windowContentsCheckBox.Checked = connection.WindowContentsWhileDragging; animationCheckBox.Checked = connection.Animations; visualStylesCheckBox.Checked = connection.VisualStyles; bitmapCachingCheckBox.Checked = connection.PersistentBitmapCaching; if (connection.AudioMode == AudioMode.Remotely) playRemotelyRadioButton.Checked = true; else if (connection.AudioMode == AudioMode.None) dontPlayRadioButton.Checked = true; int resolutionIndex = _resolutions.FindIndex((DEVMODE d) => d.dmPelsWidth == connection.DesktopWidth && d.dmPelsHeight == connection.DesktopHeight); if (resolutionIndex != -1) resolutionTrackBar.Value = resolutionIndex; switch (connection.ColorDepth) { case 15: colorDepthDropdown.SelectedIndex = 0; break; case 16: colorDepthDropdown.SelectedIndex = 1; break; case 24: colorDepthDropdown.SelectedIndex = 2; break; case 32: colorDepthDropdown.SelectedIndex = 3; break; } } }
public ConnectionWindow(Favorites favorites, MainForm.ConnectionDelegate connectionDelegate, SecureString password) : this(favorites, new RDCConnection(password), connectionDelegate, password) { }
/// <summary> /// Handler method that's called when the "Open bookmark in new window..." menu item in the context menu that appears when the user right-clicks on a /// bookmark item in <see cref="_bookmarksListView"/>. /// </summary> /// <param name="sender">Object from which this event originated.</param> /// <param name="e">Arguments associated with this event.</param> private void _openBookmarkNewWindowMenuItem_Click(object sender, EventArgs e) { MainForm mainForm = new MainForm( new List<IConnection> { _listViewConnections[_bookmarksListView.SelectedItems[0]] }); ParentTabs.ApplicationContext.OpenWindow(mainForm); mainForm.Show(); }
/// <summary> /// Handler method that's called when the "Open all in new window..." menu item in the context menu that appears when the user right-clicks on a /// folder in <see cref="_bookmarksFoldersTreeView"/>. Batches up the <see cref="IConnection.Guid"/>s of all of the bookmarks in the selected folder /// and its descendants and creates a new <see cref="MainForm"/> instance with them. /// </summary> /// <param name="sender">Object from which this event originated.</param> /// <param name="e">Arguments associated with this event.</param> private void _folderOpenAllNewWindowMenuItem_Click(object sender, EventArgs e) { // Look recursively into this folder and its descendants to get all of the bookmarks List<IConnection> bookmarks = new List<IConnection>(); FindAllBookmarks(_contextMenuItem as BookmarksFolder, bookmarks); if (bookmarks.Count > 0) { MainForm mainForm = new MainForm(bookmarks); ParentTabs.ApplicationContext.OpenWindow(mainForm); mainForm.Show(); } }
/// <summary> /// Constructor; deserializes the bookmarks folder structure, adds the various folder nodes to <see cref="_bookmarksFoldersTreeView"/>, and gets the /// icons for each protocol. /// </summary> /// <param name="applicationForm">Main application instance.</param> public BookmarksWindow(MainForm applicationForm) { InitializeComponent(); _applicationForm = applicationForm; _bookmarksFoldersTreeView.Sorted = true; _bookmarksListView.ListViewItemSorter = new BookmarksListViewComparer(); if (File.Exists(BookmarksFileName)) { // Deserialize the bookmarks folder structure from BookmarksFileName; BookmarksFolder.ReadXml() will call itself recursively to deserialize // child folders, so all we have to do is start the deserialization process from the root folder XmlSerializer bookmarksSerializer = new XmlSerializer(typeof (BookmarksFolder)); using (XmlReader bookmarksReader = new XmlTextReader(BookmarksFileName)) _rootFolder = (BookmarksFolder) bookmarksSerializer.Deserialize(bookmarksReader); } // Set the handler methods for changing the bookmarks or child folders; these are responsible for updating the tree view and list view UI when // items are added or removed from the bookmarks or child folders collections _rootFolder.Bookmarks.CollectionModified += Bookmarks_CollectionModified; _rootFolder.ChildFolders.CollectionModified += ChildFolders_CollectionModified; _folderTreeNodes[_bookmarksFoldersTreeView.Nodes[0]] = _rootFolder; // Call Bookmarks_CollectionModified and ChildFolders_CollectionModified recursively through the folder structure to "simulate" bookmarks and // folders being added to the collection so that the initial UI state for the tree view can be created InitializeTreeView(_rootFolder); _bookmarksFoldersTreeView.Nodes[0].Expand(); foreach (IProtocol protocol in ConnectionFactory.GetProtocols()) { // Get the icon for each protocol type and add an entry for it to the "Add bookmark" menu item Icon icon = new Icon(protocol.ProtocolIcon, 16, 16); _listViewImageList.Images.Add(icon); _connectionTypeIcons[protocol.ConnectionType] = _listViewImageList.Images.Count - 1; IProtocol currentProtocol = protocol; ToolStripMenuItem protocolMenuItem = new ToolStripMenuItem( protocol.ProtocolTitle, null, (sender, args) => _addBookmarkMenuItem_Click(currentProtocol)); _addBookmarkMenuItem.DropDownItems.Add(protocolMenuItem); } }
/// <summary> /// Constructor; initializes <see cref="_applicationForm"/>. /// </summary> /// <param name="applicationForm">Main application form instance associated with this window.</param> public OptionsWindow(MainForm applicationForm) { _applicationForm = applicationForm; InitializeComponent(); }