Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurochi51 committed Jul 23, 2023
1 parent 279888b commit 87f1f3e
Showing 1 changed file with 9 additions and 28 deletions.
37 changes: 9 additions & 28 deletions AudioConverter/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using FFMpegCore;
using FFMpegCore.Enums;
using System.Text;
using static System.Windows.Forms.DataFormats;
using System.Windows.Forms;

namespace AudioConverter
{
Expand All @@ -12,7 +10,6 @@ public partial class Window : Form
private int totalFiles, counter;
private readonly string[] allOptions = { "AAC", "AC3", "FLAC", "M4A", "M4B", "MP3", "OGG", "WAV" };
private bool isDarkModeEnabled;
List<Task> conversionTasks = new List<Task>();

public Window()
{
Expand All @@ -39,7 +36,7 @@ private void FolderPicker_Click(object sender, EventArgs e)
if (object.ReferenceEquals(sender, sourceButton))
{
sourceBox.Text = folderBrowserDialog.SelectedPath;
if (!string.IsNullOrEmpty(sourceBox.Text))
if (!string.IsNullOrWhiteSpace(sourceBox.Text))
{
totalFiles = Directory.EnumerateFiles(sourceBox.Text, "*", SearchOption.AllDirectories).Count();
counter = 0;
Expand Down Expand Up @@ -79,7 +76,7 @@ private void InputTextBox_DragDrop(object sender, DragEventArgs e)
sourceBox.Text = path;
if (File.Exists(path))
{
if (!string.IsNullOrEmpty(sourceBox.Text))
if (!string.IsNullOrWhiteSpace(sourceBox.Text))
{
totalFiles = 1;
counter = 0;
Expand All @@ -89,7 +86,7 @@ private void InputTextBox_DragDrop(object sender, DragEventArgs e)
}
else if (Directory.Exists(path))
{
if (!string.IsNullOrEmpty(sourceBox.Text))
if (!string.IsNullOrWhiteSpace(sourceBox.Text))
{
totalFiles = Directory.EnumerateFiles(sourceBox.Text, "*", SearchOption.AllDirectories).Count();
counter = 0;
Expand All @@ -110,7 +107,7 @@ private void ConvertButton_Click(object sender, EventArgs e)
if (counter != 0)
{
counter = 0;
if (!string.IsNullOrEmpty(sourceBox.Text))
if (!string.IsNullOrWhiteSpace(sourceBox.Text))
{
Invoke(new Action(() =>
{
Expand All @@ -129,15 +126,15 @@ private void ConvertButton_Click(object sender, EventArgs e)


// Validate input
if (string.IsNullOrEmpty(directory) || !(Directory.Exists(directory) || File.Exists(directory)))
if (string.IsNullOrWhiteSpace(directory) || !(Directory.Exists(directory) || File.Exists(directory)))
{
MessageBox.Show("Please enter a valid source path.", "Invalid Source", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}

if (string.IsNullOrEmpty(output) || !Directory.Exists(output) || Directory.GetFiles(output).Length != 0)
if (string.IsNullOrWhiteSpace(output) || !Directory.Exists(output) || Directory.GetFiles(output).Length != 0)
{
if (!string.IsNullOrEmpty(output) && Directory.GetFiles(output).Length != 0)
if (!string.IsNullOrWhiteSpace(output) && Directory.GetFiles(output).Length != 0)
{
DialogResult result = MessageBox.Show("Output folder isn't empty! Do you wish to continue?", "Invalid Output", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
if (result == DialogResult.Cancel || result == DialogResult.No)
Expand Down Expand Up @@ -267,24 +264,8 @@ private void ConvertAudioFile(string inputFile, string outputFile, string output

private bool IsAudioFile(string filePath)
{
bool found = false;
string extension = Path.GetExtension(filePath).ToLower();
foreach (var type in allOptions)
{
if ($".{type.ToLower()}" == extension)
{
found = true;
break;
}
}
if (found)
{
return true;
}
else
{
return false;
}
string extension = Path.GetExtension(filePath).ToUpper().Replace(".","");
return extension != null && allOptions.Contains(extension);
}

private void UpdateCounterText()
Expand Down

0 comments on commit 87f1f3e

Please sign in to comment.