public void CreateClientConnection(RemoteAppLib.New.RemoteApp selectedRemoteApp)
        {
            _remoteApp = selectedRemoteApp;
            var rdpSign            = new RDPSign.New.RDPSign();
            var RemoteAppShortName = _remoteApp.Name;

            Text = "Create Client Connection for " + RemoteAppShortName;
            RdpsignErrorLabel.Text = "";
            CertificateComboBox.Items.AddRange(rdpSign.GetCertificateFriendlyName().ToArray());
            SetCcWindowSettings();
            if (string.IsNullOrEmpty(ServerAddress.Text))
            {
                ServerAddress.Text = System.Net.Dns.GetHostName();
            }
            if (string.IsNullOrEmpty(AltServerAddress.Text))
            {
                AltServerAddress.Text = ServerAddress.Text;
            }
            if (ServerPort.Text == "0")
            {
                ServerPort.Text = "3389";
            }
            if (!File.Exists(_remoteApp.IconPath))
            {
                CreateRAWebIcon.Checked = false;
                CreateRAWebIcon.Enabled = false;
            }
            else
            {
                CreateRAWebIcon.Enabled = RDPRadioButton.Checked;
            }

            var wx = new RDP2MSIlib.New.RDP();

            if (!wx.WixInstalled())
            {
                RDPRadioButton.Checked = true;
                MSIRadioButton.Enabled = false;
                MSIRadioButton.Text    = "MSI installer (requires WiX Toolset)";
            }

            if (!File.Exists(rdpSign.GetRdpsignExeLocation()))
            {
                SigningTabPage.Enabled                  = false;
                RdpsignErrorLabel.Text                 += " * Requires rdpsign.exe.";
                SigningTabPage.Tag                      = "noexe";
                CheckBoxSignRDPEnabled.Checked          = false;
                CheckBoxCreateSignedAndUnsigned.Checked = false;
                CertificateComboBox.Text                = "";
            }

            if (_remoteApp.FileTypeAssociations != null)
            {
                FTACountLabel.Text = "Count: " + _remoteApp.FileTypeAssociations.Count;
            }
            RDPRadioButton.Focus();
            HelpSystem.SetupTips(this);
            ShowDialog();
            Forms.RemoteAppMainWindow.ReloadApps();
            //Dispose();
        }
        private void CreateButton_Click(object sender, EventArgs e)
        {
            var MSIPath = string.Empty;

            if (CheckBoxSignRDPEnabled.Checked && string.IsNullOrEmpty(CertificateComboBox.SelectedItem as string))
            {
                MessageBox.Show("You must select a certificate to sign the RDP file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (DisabledFTACheckBox.Checked && _remoteApp.FileTypeAssociations != null)
            {
                _remoteApp.FileTypeAssociations.Clear();
            }
            string RDPPath;

            if (RDPRadioButton.Checked)
            {
                FileSaveRDP.FileName = _remoteApp.Name;
                if (FileSaveRDP.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                RDPPath = FileSaveRDP.FileName;
            }
            else
            {
                FileSaveMSI.FileName = _remoteApp.Name;
                if (FileSaveMSI.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                MSIPath = FileSaveMSI.FileName;
                RDPPath = Environment.GetEnvironmentVariable("TEMP") + @"\" + _remoteApp.Name + ".rdp";
                _       = Environment.GetEnvironmentVariable("TEMP") + @"\" + _remoteApp.Name + ".msi";
            }

            if (UseRDGatewayCheckBox.Checked)
            {
                _ = GatewayAddress.Text;
                _ = AttemptDirectCheckBox.Checked;
            }

            if (RDPRadioButton.Checked)
            {
                CreateRDPFile(RDPPath, _remoteApp);
                // !!!!!!! If it's an RDP file
                if (EditAfterSave.Checked)
                {
                    var CmdLine = RemoteAppFunction.GetSysDir() + @"\notepad.exe";
                    Process.Start(CmdLine, FileSaveRDP.FileName);
                }

                if (CreateRAWebIcon.Checked)
                {
                    var IconFilePath = RDPPath.Substring(0, RDPPath.Length - 4) + ".ico";
                    if (!IconModule.ExtractToIco(_remoteApp.IconPath, _remoteApp.IconIndex, IconFilePath))
                    {
                        MessageBox.Show("Icon could not be created the RemoteApp. RDP file will still be created.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    // Check if there are file type associations before trying to work with the file type association icons
                    if (_remoteApp.FileTypeAssociations != null)
                    {
                        foreach (RemoteAppLib.New.FileTypeAssociation fta in _remoteApp.FileTypeAssociations)
                        {
                            var ProductFileName = RDPPath.Substring(0, RDPPath.Length - 4);
                            ExtractFtIcon(ProductFileName, fta);
                        }
                    }
                }

                Close();
            }
            else
            {
                // !!!!!!!  If it's an MSI
                var RDP = new RDP2MSIlib.New.RDP();
                CreateRDPFile(RDPPath, _remoteApp);
                RDP.RDPFilePath              = RDPPath;
                RDP.ShortcutOnDesktop        = ShortcutDesktopCheckBox.Checked;
                RDP.ShortcutInStart          = ShortcutStartCheckBox.Checked;
                RDP.ShortcutSubfolderInStart = SubfolderRadioButton.Checked;
                RDP.ProductRemoteTag         = ShortcutTagTextBox.Text;
                RDP.PerUser = PerUserRadioButton.Checked;
                var FilesToDelete   = new List <string>();
                var ProductFileName = RDPPath.Substring(0, RDPPath.Length - 4);
                var IconFilePath    = ProductFileName + ".ico";
                FilesToDelete.Add(RDPPath);
                if (!IconModule.ExtractToIco(_remoteApp.IconPath, _remoteApp.IconIndex, IconFilePath))
                {
                    MessageBox.Show("There was an error loading icon:" + Environment.NewLine + _remoteApp.IconPath + "," + _remoteApp.IconIndex + Environment.NewLine + "The MSI will still be created but the main icon will be missing.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    FilesToDelete.Add(IconFilePath);
                }

                if (_remoteApp.FileTypeAssociations != null)
                {
                    foreach (RemoteAppLib.New.FileTypeAssociation fta in _remoteApp.FileTypeAssociations)
                    {
                        ExtractFtIcon(ProductFileName, fta);
                        FilesToDelete.Add(ProductFileName + "." + fta.Extension + ".ico");
                    }

                    RDP.FlatFileTypes = _remoteApp.FileTypeAssociations.GetFlatFileTypes();
                }

                RDP.CreateMSI(MSIPath);
                RemoteAppFunction.DeleteFiles(FilesToDelete);
                Close();
            }
        }