Exemplo n.º 1
0
        private void Btn_AddExecutable_Click(object sender, EventArgs e)
        {
            ChooseExecutables executableChooser = new ChooseExecutables(Txt_ProgramLocation.Text, Executables);

            if (executableChooser.ShowDialog() == DialogResult.Yes)
            {
                ExecutableData executable = executableChooser.NewExecutable;
                Executables.Add(executable);

                Panel newPanel = new Panel
                {
                    Dock   = DockStyle.Top,
                    Height = 25
                };
                Label shortcutLabel = new Label
                {
                    Text         = executable.ShortcutName,
                    TextAlign    = ContentAlignment.MiddleLeft,
                    Dock         = DockStyle.Left,
                    Width        = 175,
                    AutoEllipsis = true
                };
                Label pathLabel = new Label
                {
                    Text         = executable.ExecutablePath,
                    TextAlign    = ContentAlignment.MiddleLeft,
                    Dock         = DockStyle.Fill,
                    AutoEllipsis = true
                };
                CheckBox onDesktop = new CheckBox
                {
                    Enabled = false,
                    Checked = executable.OnDesktop,
                    Dock    = DockStyle.Right,
                    Width   = 75
                };
                Button changeButton = new Button
                {
                    Text  = "Change",
                    Name  = Pnl_Executables.Controls.Count.ToString(),
                    Dock  = DockStyle.Right,
                    Width = 100
                };
                changeButton.Click += ChangeButton_Click;

                newPanel.Controls.Add(pathLabel);
                newPanel.Controls.Add(shortcutLabel);
                newPanel.Controls.Add(onDesktop);
                newPanel.Controls.Add(changeButton);

                Pnl_Executables.Controls.Insert(0, newPanel);
            }
            ChangeInstallText();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Displays executable data in a box to the right of a screen
        /// </summary>
        /// <param name="executable">The executable to be displayed</param>
        public void DisplayExecutableSettings(ExecutableData executable)
        {
            Location boxLocation  = new Location(40, 4);
            int      height       = 5;
            int      rightPadding = 3;
            List <Tuple <string, string, int> > boxLines = new List <Tuple <string, string, int> >()
            {
                new Tuple <string, string, int>("Executable path: ", executable.ExecutablePath, 1),
                new Tuple <string, string, int>("Shortcut name: ", executable.ShortcutName, height - 1),
                new Tuple <string, string, int>("Create desktop shortcut: ", executable.OnDesktop.ToString(), height)
            };

            Borders borders = new Borders(true)
            {
                TopStyle    = "*",
                LeftStyle   = "-|",
                RightStyle  = "|-",
                BottomStyle = "*"
            };
            Location bottomRightOfBox = new Location(Console.WindowWidth - rightPadding, boxLocation.Y + height +
                                                     borders.TopStyle.Length + borders.BottomStyle.Length + 1);

            FormattedWriteSettings writeSettings = new FormattedWriteSettings
            {
                MaximumWidth        = bottomRightOfBox.X - boxLocation.X,
                InnerPadding        = new Padding(0, borders.LeftStyle.Length + 1, borders.RightStyle.Length + 1, 0),
                ResetCursorPosition = true,
                NewLine             = false
            };

            ConsoleUtils.CreateBox(boxLocation, bottomRightOfBox, borders);
            for (int i = 0; i < boxLines.Count; ++i)
            {
                writeSettings.Location = new Location(boxLocation.X, boxLocation.Y + boxLines[i].Item3);
                if (i < boxLines.Count - 1)
                {
                    writeSettings.MaximumHeight = boxLines[i + 1].Item3 - boxLines[i].Item3;
                }
                else
                {
                    writeSettings.MaximumHeight = height - boxLines[i].Item3 + 1;
                }
                ConsoleUtils.FormattedWrite(boxLines[i].Item1, writeSettings);
                writeSettings.Location.X   += boxLines[i].Item1.Length;
                writeSettings.MaximumWidth -= boxLines[i].Item1.Length;

                ConsoleUtils.FormattedWrite(boxLines[i].Item2, writeSettings);
                writeSettings.MaximumWidth += boxLines[i].Item1.Length;
            }
        }
Exemplo n.º 3
0
 public ChooseExecutables(string programLocation, List <ExecutableData> executables, ExecutableData prevExecutable)
 {
     InitializeComponent();
     ProgramLocation           = programLocation;
     Executables               = executables;
     Btn_AddExecutable.Text    = "Change";
     Btn_RemoveExecutable.Text = "Remove";
     Txt_ShortcutName.Text     = prevExecutable.ShortcutName;
     Txt_ExecutablePath.Text   = prevExecutable.ExecutablePath;
     ChBox_OnDesktop.Checked   = prevExecutable.OnDesktop;
     PrevExecutable            = new ExecutableData(prevExecutable.ShortcutName, prevExecutable.ExecutablePath, prevExecutable.OnDesktop);
     DialogResult              = DialogResult.Cancel;
     ChangingExecutables       = true;
     ExecNameChanged           = true;
 }
Exemplo n.º 4
0
        private void ChangeButton_Click(object sender, EventArgs e)
        {
            Button            changeButton      = (Button)sender;
            int               index             = Convert.ToInt32(changeButton.Name);
            int               panelIndex        = Pnl_Executables.Controls.Count - index - 1;
            ChooseExecutables executableChooser = new ChooseExecutables(Txt_ProgramLocation.Text, Executables, Executables[index]);

            executableChooser.ShowDialog();
            if (executableChooser.DialogResult == DialogResult.Yes)
            {
                ExecutableData executable = executableChooser.NewExecutable;
                Executables[index] = executable;
                Pnl_Executables.Controls[panelIndex].Controls[1].Text = executable.ShortcutName;
                Pnl_Executables.Controls[panelIndex].Controls[0].Text = executable.ExecutablePath;
                ((CheckBox)Pnl_Executables.Controls[panelIndex].Controls[2]).Checked = executable.OnDesktop;
            }
            else if (executableChooser.DialogResult == DialogResult.No)
            {
                Executables.RemoveAt(index);
                Pnl_Executables.Controls.RemoveAt(panelIndex);
            }
        }
Exemplo n.º 5
0
        private void Btn_AddExecutable_Click(object sender, EventArgs e)
        {
            bool execPathTaken = false;
            bool shortcutTaken = false;

            // If changing an executable
            if (ChangingExecutables)
            {
                // Executable path taken
                {
                    List <ExecutableData> sameExecPath = Executables.Where(x => x.ExecutablePath == Txt_ExecutablePath.Text).ToList();
                    if (sameExecPath.Count() > 1)
                    {
                        execPathTaken = true;
                    }
                    else if (sameExecPath.Count() != 0 && sameExecPath[0].ExecutablePath != PrevExecutable.ExecutablePath)
                    {
                        execPathTaken = true;
                    }
                }
                // Shortcut taken
                {
                    List <ExecutableData> sameShortcut = Executables.Where(x => x.ShortcutName == Txt_ShortcutName.Text).ToList();
                    if (sameShortcut.Count() > 1)
                    {
                        shortcutTaken = true;
                    }
                    else if (sameShortcut.Count() != 0 && sameShortcut[0].ShortcutName != PrevExecutable.ShortcutName)
                    {
                        shortcutTaken = true;
                    }
                }
            }
            // If adding an executable
            else
            {
                if (Executables.Where(x => x.ExecutablePath == Txt_ExecutablePath.Text).Count() > 0)
                {
                    execPathTaken = true;
                }
                if (Executables.Where(x => x.ShortcutName == Txt_ShortcutName.Text).Count() > 0)
                {
                    shortcutTaken = true;
                }
            }
            if (!execPathTaken && !shortcutTaken)
            {
                NewExecutable = new ExecutableData(Txt_ShortcutName.Text, Txt_ExecutablePath.Text, ChBox_OnDesktop.Checked);
                DialogResult  = DialogResult.Yes;
                Close();
            }
            // Show message to user that operation failed
            else
            {
                string message = "Executable cannot be " + (ChangingExecutables ? "changed" : "added") + " due to the following restrictions:";
                if (execPathTaken)
                {
                    message += "\n\t- Executable path already used";
                }
                if (shortcutTaken)
                {
                    message += "\n\t- Shortcut name already taken";
                }
                MessageBox.Show(message, "Failed to " + (ChangingExecutables ? "change" : "add"));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Allows the user to modify the executables list
        /// </summary>
        private void ChangeExecutables()
        {
            int menuOption = -1;

            while (menuOption != Executables.Count + 2)
            {
                // Prep Screen for choosing the executable
                ConsoleUtils.PrepNewScreen("Application Installer");
                ConsoleUtils.CreateMenu(Executables.Select(x => x.ShortcutName).ToList().Concat(new string[] { "Add", "Back" }).ToList());
                menuOption = ConsoleUtils.FancyGetInteger("Menu choice: ", minValue: 1, maxValue: Executables.Count + 2, maxCharHeight: 1);
                ConsoleUtils.FormattedWrite();

                // Choose executable or add another one
                if (menuOption != Executables.Count + 2)
                {
                    ExecutableData executable, prevExecutable = new ExecutableData();
                    int            executableIndex = menuOption - 1;
                    bool           changeExisting  = menuOption != Executables.Count + 1;

                    // Create a copy executable to change
                    if (changeExisting)
                    {
                        prevExecutable = Executables[executableIndex];
                        Executables.RemoveAt(executableIndex);
                        executable = new ExecutableData(prevExecutable);
                    }
                    else
                    {
                        executable = new ExecutableData();
                    }
                    menuOption = 0;

                    // Allow the user to change the settings of the copied executable
                    while (menuOption < 4)
                    {
                        List <string> menuItems = new List <string>()
                        {
                            "Executable path", "Shortcut name", "Create desktop shortcut", "Save", "Cancel"
                        };
                        if (changeExisting)
                        {
                            menuItems.Insert(5, "Remove");
                        }

                        ConsoleUtils.PrepNewScreen("Application Installer");
                        DisplayExecutableSettings(executable);
                        ConsoleUtils.CreateMenu(menuItems, "Executable Options:");
                        menuOption = ConsoleUtils.FancyGetInteger("Menu choice: ", minValue: 1, maxValue: menuItems.Count, maxCharHeight: 1);
                        ConsoleUtils.FormattedWrite();

                        if (changeExisting && menuOption > 5)
                        {
                            menuOption++;
                        }

                        switch (menuOption)
                        {
                        // Change Executable path
                        case 1:
                            ConsoleUtils.FormattedWrite("Current Setting: " + executable.ExecutablePath);
                            executable.ExecutablePath = ConsoleUtils.FancyGetInput("Executable path: ");
                            if (executable.ShortcutName == "")
                            {
                                executable.ShortcutName = Path.GetFileNameWithoutExtension(executable.ExecutablePath);
                            }
                            break;

                        // Change Shortcut name
                        case 2:
                            ConsoleUtils.FormattedWrite("Current Setting: " + executable.ShortcutName);
                            executable.ShortcutName = ConsoleUtils.FancyGetInput("Shortcut name: ");
                            break;

                        // Change On desktop
                        case 3:
                            ConsoleUtils.FormattedWrite("Current Setting: " + executable.OnDesktop);
                            string input = ConsoleUtils.FancyGetAllowedInput(AllowedOptions, "Create desktop shortcut: ", "Choice must be y/n", false, preventIncorrectText: true);
                            executable.OnDesktop = YesChoices.Contains(input.ToLower());
                            break;
                        }

                        if (menuOption == 4)
                        {
                            bool shortcutNameTaken   = Executables.Select(x => x.ShortcutName).Contains(executable.ShortcutName);
                            bool executablePathTaken = Executables.Select(x => x.ExecutablePath).Contains(executable.ExecutablePath);
                            if (shortcutNameTaken || executablePathTaken)
                            {
                                if (shortcutNameTaken)
                                {
                                    ConsoleUtils.FormattedWrite("Shortcut name already taken");
                                }
                                if (executablePathTaken)
                                {
                                    ConsoleUtils.FormattedWrite("Executable Path already taken");
                                }
                                ConsoleUtils.FormattedWrite("Press any key to continue...");
                                Console.CursorVisible = false;
                                Console.ReadKey(true);
                                Console.CursorVisible = true;
                            }
                        }
                        else if (menuOption == 6 && changeExisting)
                        {
                            Executables.Insert(executableIndex, prevExecutable);
                        }
                    }
                    // Save settings/Add executable
                    if (menuOption == 4)
                    {
                        if (changeExisting)
                        {
                            Executables[executableIndex] = executable;
                        }
                        else
                        {
                            Executables.Add(executable);
                        }
                    }
                    menuOption = -1;
                }
            }
        }