Exemplo n.º 1
0
        private void SetupWin_Load(object sender, EventArgs e)
        {
            string account = _server.GetUser();

            if (account == "SYSTEM")
            {
                lblMappedDrives.Text  = "If you want to use network drives, you need to run the service with a local machine account and not a local system account.\n\nTo do so, open the services panel, right click on the Amleto server service, and choose \"Properties\". In the second tab specify a username and a password, and restart the service.";
                listMapDrives.Visible = false;
                btnAddDrive.Visible   = false;
                btnDelDrive.Visible   = false;
            }
            else
            {
                // Build a list of available drives
                for (char letter = 'D'; letter <= 'Z'; letter++)
                {
                    _availableDrives.Add("" + letter + ":\\");
                }
                List <string> usedDrives = _server.DriveList();

                foreach (MapDrive mapDrive in MappedDrives)
                {
                    int idx = usedDrives.FindIndex(delegate(string x) { return(x.StartsWith(mapDrive.Drive)); });
                    if (idx != -1)
                    {
                        usedDrives.RemoveAt(idx);
                    }
                }

                foreach (string s in usedDrives)
                {
                    string d = s.Substring(0, 3);
                    try
                    {
                        _availableDrives.RemoveAt(_availableDrives.IndexOf(d));
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, "Error removing used drives");
                    }
                }

                // Build map drives list
                foreach (MapDrive mapDrive in MappedDrives)
                {
                    DataGridViewRow          row          = new DataGridViewRow();
                    DataGridViewComboBoxCell letterSelect = new DataGridViewComboBoxCell();

                    /*for (char letter = 'E'; letter <= 'Z'; letter++)
                     *  letterSelect.Items.Add("" + letter + ":\\");*/
                    foreach (string s in _availableDrives)
                    {
                        letterSelect.Items.Add(s);
                    }
                    letterSelect.Value = mapDrive.Drive;
                    row.Cells.Add(letterSelect);

                    DataGridViewCell cell = new DataGridViewTextBoxCell();
                    cell.Value = mapDrive.Share;
                    row.Cells.Add(cell);

                    cell       = new DataGridViewTextBoxCell();
                    cell.Value = mapDrive.Username;
                    row.Cells.Add(cell);

                    cell       = new DataGridViewTextBoxCell();
                    cell.Value = mapDrive.Password;
                    row.Cells.Add(cell);

                    listMapDrives.Rows.Add(row);
                }
            }

            checkAutoPort.Checked     = AutoPort;
            textPort.Text             = "" + Port;
            textLogFile.Text          = LogFile;
            textMailFrom.Text         = EmailFrom;
            textSMTPServer.Text       = SmtpServer;
            textSTMPUser.Text         = SmtpUsername;
            textSMTPPassword.Text     = SmtpPassword;
            offerWebInterface.Checked = OfferWeb;
            webPort.Text            = "" + OfferWebPort;
            cbEnableLogging.Checked = LogEnabled;
            renderBlock.Text        = RenderBlocks.ToString();

            // If log file name is empty, generate a default log path
            if (textLogFile.Text == "")
            {
                string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Amleto");
                textLogFile.Text = Path.Combine(path, "AmletoServer.log");
            }

            DisplayConfigs();
        }