using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Globalization; using System.Text; using System.Windows.Forms; using System.IO; namespace sharpreleaser { public partial class MainWindow : Form { private Project project = null; public MainWindow(string[] args) { InitializeComponent(); toolStrip2.Visible = true; project = new Project(); SetProject(project); if (args.Length > 0) { Read(args[0]); } } private void openProject_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog(this) == DialogResult.OK) { Read(openFileDialog.FileName); } } private void saveProject_Click(object sender, EventArgs e) { if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { project = GetProject(); project.Write(saveFileDialog.FileName); } } private Project GetProject() { Project project = new Project(); project.Name = txtName.Text; project.Version = txtVersion.Text; project.FileName = txtFileName.Text; project.SourceFolder = txtSourceFolder.Text; project.DestinationFolder = txtDestinationFolder.Text; project.Commands.Clear(); foreach (Command command in commandsListBox.Items) { project.Commands.Add(command); } return project; } private void SetProject(Project project) { txtName.Text = project.Name; txtVersion.Text = project.Version; txtFileName.Text = project.FileName; txtSourceFolder.Text = project.SourceFolder; txtDestinationFolder.Text = project.DestinationFolder; commandsListBox.DataSource = project.Commands; } private void addCommand_Click(object sender, EventArgs e) { project.Commands.Add(new Command(Command.CommandType.DOS, commandText.Text)); commandsListBox.DataSource = null; commandsListBox.DataSource = project.Commands; } private void deleteCommand_Click(object sender, EventArgs e) { if (commandsListBox.SelectedItem != null) { int selectedIndex = commandsListBox.SelectedIndex; project.Commands.RemoveAt(selectedIndex); commandsListBox.DataSource = null; commandsListBox.DataSource = project.Commands; } } private void run_Click(object sender, EventArgs e) { log.Clear(); log.Text += "Starting..." + Environment.NewLine + Environment.NewLine; foreach (Command command in commandsListBox.Items) { log.Text += project.ParseVariables(command.ToString()) + Environment.NewLine; command.Execute(project); if (!string.IsNullOrEmpty(command.Error)) { log.Text += command.Error + Environment.NewLine; } if (!string.IsNullOrEmpty(command.Output)) { log.Text += command.Output + Environment.NewLine; } log.Text += "-------------------------------------------------------------" + Environment.NewLine; if (!string.IsNullOrEmpty(command.Error) && command.OnError == Command.FlowActions.Break) { break; } } log.Text += Environment.NewLine + "Completed..." + Environment.NewLine; } private void moveUpCommand_Click(object sender, EventArgs e) { if (commandsListBox.SelectedItem != null && commandsListBox.SelectedIndex > 0) { int selectedIndex = commandsListBox.SelectedIndex; Command command = project.Commands[selectedIndex]; project.Commands.RemoveAt(selectedIndex); project.Commands.Insert(selectedIndex - 1, command); commandsListBox.DataSource = null; commandsListBox.DataSource = project.Commands; commandsListBox.SelectedIndex = selectedIndex - 1; } } private void moveDownCommand_Click(object sender, EventArgs e) { if (commandsListBox.SelectedItem != null && commandsListBox.SelectedIndex < commandsListBox.Items.Count - 1) { int selectedIndex = commandsListBox.SelectedIndex; Command command = project.Commands[selectedIndex]; project.Commands.RemoveAt(selectedIndex); project.Commands.Insert(selectedIndex + 1, command); commandsListBox.DataSource = null; commandsListBox.DataSource = project.Commands; commandsListBox.SelectedIndex = selectedIndex + 1; } } private void sourceFolderButton_Click(object sender, EventArgs e) { if (folderDialog.ShowDialog(this) == DialogResult.OK) { txtSourceFolder.Text = folderDialog.SelectedPath; } } private void destinationFolderButton_Click(object sender, EventArgs e) { if (folderDialog.ShowDialog(this) == DialogResult.OK) { txtDestinationFolder.Text = folderDialog.SelectedPath; } } private void commandsListBox_SelectedIndexChanged(object sender, EventArgs e) { if (commandsListBox.SelectedItem != null) { commandText.Text = ((Command)commandsListBox.SelectedItem).CommandText; } else { commandText.Text = string.Empty; } } public void Read(string FileName) { project = Project.Read(FileName); SetProject(project); } private void editCommand_Click(object sender, EventArgs e) { if (commandsListBox.SelectedItem != null) { int selectedIndex = commandsListBox.SelectedIndex; Command command = project.Commands[selectedIndex]; command.CommandText = commandText.Text; commandsListBox.DataSource = null; commandsListBox.DataSource = project.Commands; } } } }