Beispiel #1
0
        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;
        }
        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 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)
 {
 }