Skip to content

Commit

Permalink
Added drag & drop support.
Browse files Browse the repository at this point in the history
  • Loading branch information
PeteJobi committed May 31, 2023
1 parent 51273e4 commit 9236f7f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Upscaler/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 44 additions & 6 deletions Upscaler/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public partial class MainForm : Form
bool videoSupported;
bool hasBeenKilled;
bool isPaused;
string pathForView;
FrameFolders? frameFolders;
Process? currentProcess;
public MainForm()
Expand All @@ -42,10 +43,11 @@ private void AnimeRadioButton_CheckedChanged(object? sender, EventArgs e)
private void SelectFile_Click(object sender, EventArgs e)
{
openFileDialog.Title = "Select one or multiple images and/or videos";
openFileDialog.Filter = $"Image {(videoSupported ? "and Video " : "")}Files|" + string.Join(";", allowedExts.Select(e => $"*.{e}"));
openFileDialog.Filter = $"Image {(videoSupported ? "and Video " : "")}Files|" + string.Join(";", allowedExts.Select(e => $"*{e}"));
openFileDialog.Multiselect = true;
if (openFileDialog.ShowDialog() != DialogResult.OK) return;
PrepareUI();
pathForView = GetOutputName(openFileDialog.FileName);
fileNameLabel.Text = Path.GetFileName(openFileDialog.FileName);
if (openFileDialog.FileNames.Length > 1)
fileNameLabel.Text += $" and {openFileDialog.FileNames.Length - 1} others";
Expand All @@ -57,14 +59,15 @@ private void SelectFolderButton_Click(object sender, EventArgs e)
folderBrowserDialog.Description = "Select a folder that contains images and/or videos";
folderBrowserDialog.UseDescriptionForTitle = true;
if (folderBrowserDialog.ShowDialog() != DialogResult.OK) return;
PrepareUI();
fileNameLabel.Text = Path.GetFileName(folderBrowserDialog.SelectedPath);
string[] filePaths = Directory.GetFiles(folderBrowserDialog.SelectedPath).Where(p => allowedExts.Contains(Path.GetExtension(p))).ToArray();
if(filePaths.Length == 0)
{
MessageBox.Show("The selected folder does not contain any supported files");
return;
}
PrepareUI();
pathForView = GetOutputName(folderBrowserDialog.SelectedPath);
fileNameLabel.Text = Path.GetFileName(folderBrowserDialog.SelectedPath);
ProcessFiles(filePaths);
}

Expand Down Expand Up @@ -209,7 +212,7 @@ void IncrementBreakMergeProgress(TimeSpan currentTime, TimeSpan totalDuration, i
Invoke(() =>
{
progressLabel.Text = $"{currentTime:hh\\:mm\\:ss}/{totalDuration:hh\\:mm\\:ss}: {Math.Round(currentTime / totalDuration * 100, 2)} %";
currentActionLabel.Text = isMerging ? "Merging frames into video" : "Breaking video into frames";
currentActionLabel.Text = isMerging ? "Merging frames into video..." : "Breaking video into frames...";
int breakMergeProgressMaxForOverall = (int)((double)progressMax / (totalFilesCount * breakMergeSegmentFactor));
currentActionProgressBar.Value = (isMerging ? (progressMax - breakMergeProgressMax) : 0) + (int)(currentTime / totalDuration * breakMergeProgressMax);
overallProgressBar.Value = (int)((double)currentFileIndex / totalFilesCount * progressMax)
Expand All @@ -228,7 +231,9 @@ void AllDone(int fileCount)
cancelButton.Text = "Retry";
cancelButton.Click -= CancelButton_Click;
cancelButton.Click += Reset;
pauseButton.Enabled = false;
pauseButton.Text = "View";
pauseButton.Click -= pauseButton_Click;
pauseButton.Click += ViewFiles;
});
}

Expand All @@ -243,6 +248,8 @@ private void Reset(object? sender, EventArgs e)
pauseButton.Text = "Pause";
cancelButton.Click += CancelButton_Click;
cancelButton.Click -= Reset;
pauseButton.Click += pauseButton_Click;
pauseButton.Click -= ViewFiles;
fileDialogPanel.Show();
selectLabel.Show();
fileNameLabel.Hide();
Expand All @@ -266,7 +273,15 @@ private async void CancelButton_Click(object? sender, EventArgs e)
frameFolders = null;
}

private void pauseButton_Click(object sender, EventArgs e)
private void ViewFiles(object? sender, EventArgs e)
{
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "explorer";
info.Arguments = $"/e, /select, \"{pathForView}\"";
Process.Start(info);
}

private void pauseButton_Click(object? sender, EventArgs e)
{
if (isPaused)
{
Expand Down Expand Up @@ -434,6 +449,29 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
Directory.Delete(frameFolders.OutputFolder, true);
}
}

private void MainForm_DragEnter(object sender, DragEventArgs e)
{
if (!fileDialogPanel.Visible) return;
e.Effect = DragDropEffects.All;
}

private void MainForm_DragDrop(object sender, DragEventArgs e)
{
if (!fileDialogPanel.Visible) return;
string[] files = ((string[])e.Data.GetData(DataFormats.FileDrop, false)).Where(p => allowedExts.Contains(Path.GetExtension(p))).ToArray();
if (files.Length == 0)
{
MessageBox.Show("None of the dropped files are supported");
return;
}
pathForView = GetOutputName(files[0]);
PrepareUI();
fileNameLabel.Text = Path.GetFileName(files[0]);
if (files.Length > 1)
fileNameLabel.Text += $" and {files.Length - 1} others";
ProcessFiles(files);
}
}

record ProcessOutput(string Output, string Error);
Expand Down
2 changes: 1 addition & 1 deletion Upscaler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static void Main()
static void ExceptionHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception)args.ExceptionObject;
//MessageBox.Show($"An error occurred\n\n{e}");
MessageBox.Show($"An error occurred\n\n{e}");
}
}
}

0 comments on commit 9236f7f

Please sign in to comment.