Ejemplo n.º 1
0
        private bool SaveSettings()
        {
            string       configPath;
            DialogResult retVal;

            retVal = MessageBox.Show("Save secure port settings?", "Are you sure?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
            if (retVal == DialogResult.Yes)
            {
                if (!ValidateSettings())
                {
                    return(false);
                }
                if (txtConfigPath.Text.ToUpper() == "DEFAULT")
                {
                    //   string progFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
                    //   string pathFromReg = portPath[cboTroyPort.Text.ToString()];
                    //   configPath = portPath + @"\TROY Group\Port Monitor\" + pathFromReg + @"\Config\";
                    txtConfigPath.Text = "default";
                }
                else
                {
                    if (!txtConfigPath.Text.EndsWith("\\"))
                    {
                        txtConfigPath.Text += "\\";
                    }
                    configPath = txtConfigPath.Text;
                }

                TroySecurePort tsp = new TroySecurePort();
                tsp.ConfigurationPath = txtConfigPath.Text.ToString();
                tsp.PortMonitorName   = cboTroyPort.Text.ToString();
                tsp.PortName          = txtNewPortName.Text.ToString();
                tpmsc_local.PortList.Add(tsp);

                //Save data capture
                XmlSerializer xser     = new XmlSerializer(typeof(TroyPortMonitorServiceConfiguration));
                string        filename = baseFilePath + "TroyPMServiceConfiguration.xml";
                TextWriter    writer   = new StreamWriter(filename);
                xser.Serialize(writer, tpmsc_local);
                writer.Close();

                MessageBox.Show("New secure port was added.");

                InitForm();
                btnApply.Enabled = false;

                return(true);
            }
            else if (retVal == DialogResult.Cancel)
            {
                cboTroyPort.Text  = "";
                txtPrintPath.Text = "";
                return(false);
            }
            else
            {
                MessageBox.Show("New secure port was not added.");
                return(true);
            }
        }
Ejemplo n.º 2
0
        private void btnAddMultiple_Click(object sender, EventArgs e)
        {
            if ((cboPortType.Enabled) && (cboPortType.Text == ""))
            {
                MessageBox.Show("Please select a Port Type.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                if (MessageBox.Show("Are you sure you want to add SecurePorts to the system?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    XDocument xDoc = XDocument.Load(filePath + "TroyPMServiceConfiguration.xml");

                    Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.Registry.LocalMachine;
                    Microsoft.Win32.RegistryKey pmKey       = registryKey.OpenSubKey
                                                                  ("System\\CurrentControlSet\\Control\\Print\\Monitors\\TroySecurePortMonitor\\Ports", true);

                    //string progFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);

                    string newPortName;
                    for (int cntr = currentPortNumber; cntr < currentPortNumber + numericUpDown1.Value; cntr++)
                    {
                        newPortName = "TROYPORT" + cntr + ":";
                        string newFilePath;

                        //newFilePath = progFiles + @"\TROY Group\Port Monitor\PrintPort" + cntr + @"\";
                        newFilePath = baseFilePath + @"PrintPort" + cntr + @"\";
                        DirectoryInfo dirInfo = new DirectoryInfo(newFilePath);
                        if (!dirInfo.Exists)
                        {
                            dirInfo.Create();
                        }

                        DirectoryInfo configDir = new DirectoryInfo(newFilePath + "\\Config\\");
                        if (!configDir.Exists)
                        {
                            configDir.Create();
                            //DirectoryInfo filesCopy = new DirectoryInfo(progFiles + @"\TROY Group\Port Monitor\Configuration\");
                            DirectoryInfo filesCopy;
                            if (cboPortType.Text != "")
                            {
                                filesCopy = new DirectoryInfo(baseFilePath + @"Configuration\" + cboPortType.Text + @"\");
                            }
                            else
                            {
                                filesCopy = new DirectoryInfo(baseFilePath + @"Configuration\");
                            }

                            foreach (FileInfo fInfo in filesCopy.GetFiles())
                            {
                                fInfo.CopyTo(configDir.FullName + fInfo.Name, true);
                            }
                        }

                        DirectoryInfo dataDir = new DirectoryInfo(newFilePath + "\\Data\\");
                        if (!dataDir.Exists)
                        {
                            dataDir.Create();
                            DirectoryInfo filesCopy;
                            if (cboPortType.Text != "")
                            {
                                filesCopy = new DirectoryInfo(baseFilePath + @"Data\" + cboPortType.Text + @"\");
                            }
                            else
                            {
                                filesCopy = new DirectoryInfo(baseFilePath + @"Data\");
                            }
                            if (UsingSoftwarePantograph)
                            {
                                //DirectoryInfo dataCopy = new DirectoryInfo(progFiles + @"\TROY Group\Port Monitor\Data\");
                                DirectoryInfo dataCopy = new DirectoryInfo(baseFilePath + @"Data\");
                                foreach (FileInfo fInfo in filesCopy.GetFiles())
                                {
                                    fInfo.CopyTo(dataDir.FullName + fInfo.Name, true);
                                }
                            }
                        }


                        pmKey.SetValue(newPortName, newFilePath);

                        TroySecurePort tsp = new TroySecurePort();
                        tsp.ConfigurationPath = "default";
                        tsp.PortMonitorName   = "TROYPORT" + cntr + ":";
                        tsp.PortName          = "Troy Secure Port " + cntr;
                        if (chkIncludeTypeInName.Checked)
                        {
                            if (cboPortType.Text != "")
                            {
                                tsp.PortName = tsp.PortName + " (" + cboPortType.Text + ")";
                            }
                        }
                        tpmsc_local.PortList.Add(tsp);
                    }
                    pmKey.Close();

                    //Save data capture
                    XmlSerializer xser     = new XmlSerializer(typeof(TroyPortMonitorServiceConfiguration));
                    string        filename = baseFilePath + "TroyPMServiceConfiguration.xml";
                    TextWriter    writer   = new StreamWriter(filename);
                    xser.Serialize(writer, tpmsc_local);
                    writer.Close();
                    if (MessageBox.Show("The changes will not take effect until the Print Spooler is restarted.  Would you like to restart the Print Spooler now?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        if (PrintSpoolerName != "")
                        {
                            System.ServiceProcess.ServiceController myService = new System.ServiceProcess.ServiceController(PrintSpoolerName);
                            if (myService.Status == System.ServiceProcess.ServiceControllerStatus.Running)
                            {
                                myService.Stop();
                            }
                            System.Threading.Thread.Sleep(1000);
                            myService.Start();
                        }
                        MessageBox.Show("New SecurePorts were added to the system.", "SecurePorts Added", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("The Print Spooler was not restarted.  Please restart the services in order to enable the changes made.", "Restart Needed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    InitForm();
                }
                else
                {
                    MessageBox.Show("New SecurePorts were not added.", "SecurePorts Not Added", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }