Skip to content

Commit

Permalink
Disable options when upscale task is in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
PeteJobi committed May 30, 2023
1 parent e6e2c55 commit 956ac2d
Show file tree
Hide file tree
Showing 4 changed files with 2,248 additions and 24 deletions.
28 changes: 15 additions & 13 deletions Upscaler/MainForm.Designer.cs

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

23 changes: 15 additions & 8 deletions Upscaler/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ private void SelectFile_Click(object sender, EventArgs e)
openFileDialog.Filter = "Image and Video Files|*.jpg;*.jpeg;*.png;*.mkv;*.mp4";
openFileDialog.Multiselect = true;
if (openFileDialog.ShowDialog() != DialogResult.OK) return;
fileDialogPanel.Hide();
selectLabel.Hide();
fileNameLabel.Show();
PrepareUI();
fileNameLabel.Text = Path.GetFileName(openFileDialog.FileName);
if (openFileDialog.FileNames.Length > 1)
fileNameLabel.Text += $" and {openFileDialog.FileNames.Length - 1} others";
Expand All @@ -51,9 +49,7 @@ 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;
fileDialogPanel.Hide();
selectLabel.Hide();
fileNameLabel.Show();
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)
Expand All @@ -64,6 +60,15 @@ private void SelectFolderButton_Click(object sender, EventArgs e)
ProcessFiles(filePaths);
}

void PrepareUI()
{
fileDialogPanel.Hide();
selectLabel.Hide();
fileNameLabel.Show();
mediaTypePanel.Enabled = false;
animeScaleLevelPanel.Enabled = false;
}

void ProcessFiles(string[] fileNames)
{
Size = new Size(Size.Width, 380);
Expand Down Expand Up @@ -195,7 +200,7 @@ void IncrementBreakMergeProgress(TimeSpan currentTime, TimeSpan totalDuration, i
{
Invoke(() =>
{
progressLabel.Text = $"{Math.Round(currentTime / totalDuration * 100, 2)} %";
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";
int breakMergeProgressMaxForOverall = (int)((double)progressMax / (totalFilesCount * breakMergeSegmentFactor));
currentActionProgressBar.Value = (isMerging ? (progressMax - breakMergeProgressMax) : 0) + (int)(currentTime / totalDuration * breakMergeProgressMax);
Expand Down Expand Up @@ -235,6 +240,8 @@ private void Reset(object? sender, EventArgs e)
fileNameLabel.Hide();
overallProgressBar.Value = 0;
currentActionProgressBar.Value = 0;
mediaTypePanel.Enabled = true;
animeScaleLevelPanel.Enabled = true;
}

private async void CancelButton_Click(object? sender, EventArgs e)
Expand All @@ -243,11 +250,11 @@ private async void CancelButton_Click(object? sender, EventArgs e)
hasBeenKilled = true;
cancelButton.Click -= CancelButton_Click;
Reset(sender, e);
hasBeenKilled = false;
currentProcess = null;
await Task.Delay(1000);
Directory.Delete(frameFolders.InputFolder, true);
Directory.Delete(frameFolders.OutputFolder, true);
hasBeenKilled = false;
frameFolders = null;
}

Expand Down
Loading

0 comments on commit 956ac2d

Please sign in to comment.