Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions formMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,22 @@ private void btnConvert_Click(object sender, EventArgs e)
}

// Validates if the user input a value for txtOutput
if (txtOutput.Text == "")
if (txtOutput.Text == "" && txtInput.Text != "")
{
verified = false;
MessageBox.Show("An output file needs to be selected", "Verification Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (!txtInput.Text.EndsWith(".webm"))
{
// Keep filename, but change extension to "webm"
txtOutput.Text = txtInput.Text.Substring(0, txtInput.Text.LastIndexOf(".")) + ".webm";
if (!overwriteExistingFileIfExists())
{
verified = false;
}
}
else
{
// Add another extension to avoid overwriting original file.
txtOutput.Text = txtInput.Text + ".webm";
}
}

// Validates if the user input a value for txtTimeStart
Expand Down Expand Up @@ -450,5 +462,29 @@ private void formMain_DragDrop(object sender, DragEventArgs e)

txtInput.Text = files[0];
}

/// <summary>
/// If file with automatically generated filename exists show prompt to make user aware of that and let him decide if he wants to overwrite it.
/// </summary>
/// <returns></returns>
private bool overwriteExistingFileIfExists()
{
FileInfo fi = new FileInfo(txtOutput.Text);
if (fi.Exists)
{
DialogResult dialogResult = MessageBox.Show("Overwrite " + txtOutput.Text + "?", "Output file exists", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.No)
{
saveFileDialog1.FileName = txtOutput.Text;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
txtOutput.Text = saveFileDialog1.FileName;
return true;
}
return false;
}
}
return true;
}
}
}