WIP: main form UI

This commit is contained in:
Ray 2021-10-24 17:16:37 +01:00
parent 7933a5eb75
commit faf4d3937c
2 changed files with 92 additions and 393 deletions

44
MainForm.Designer.cs generated
View File

@ -67,6 +67,8 @@ namespace RandomFileRunner
this.tHorizontalSeparator1 = new RyzStudio.Windows.Forms.THorizontalSeparator();
this.button4 = new RyzStudio.Windows.ThemedForms.TButton();
this.button3 = new RyzStudio.Windows.ThemedForms.TMenuButton();
this.memoBox1 = new RyzStudio.Windows.ThemedForms.TMemoBox();
this.button8 = new RyzStudio.Windows.ThemedForms.TButton();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.menuStrip1.SuspendLayout();
this.contextMenuStrip1.SuspendLayout();
@ -346,7 +348,7 @@ namespace RandomFileRunner
//
// tHorizontalSeparator1
//
this.tHorizontalSeparator1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
this.tHorizontalSeparator1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tHorizontalSeparator1.AutoScrollMargin = new System.Drawing.Size(0, 0);
this.tHorizontalSeparator1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
@ -362,13 +364,12 @@ namespace RandomFileRunner
//
// button4
//
this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button4.BackColor = System.Drawing.Color.Transparent;
this.button4.DefaultImage = null;
this.button4.DownImage = null;
this.button4.IsSelected = false;
this.button4.LabelText = "&Clear";
this.button4.Location = new System.Drawing.Point(289, 154);
this.button4.Location = new System.Drawing.Point(296, 154);
this.button4.Margin = new System.Windows.Forms.Padding(10, 0, 10, 10);
this.button4.Name = "button4";
this.button4.OverImage = null;
@ -384,7 +385,7 @@ namespace RandomFileRunner
this.button3.DefaultImage = null;
this.button3.DownImage = null;
this.button3.IsSelected = false;
this.button3.LabelText = "";
this.button3.LabelText = "&Add";
this.button3.Location = new System.Drawing.Point(127, 154);
this.button3.Margin = new System.Windows.Forms.Padding(10, 0, 10, 10);
this.button3.Name = "button3";
@ -393,6 +394,38 @@ namespace RandomFileRunner
this.button3.Size = new System.Drawing.Size(149, 33);
this.button3.TabIndex = 47;
//
// memoBox1
//
this.memoBox1.AllowDrop = true;
this.memoBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.memoBox1.BackColor = System.Drawing.Color.Transparent;
this.memoBox1.Location = new System.Drawing.Point(13, 203);
this.memoBox1.Margin = new System.Windows.Forms.Padding(10, 6, 10, 6);
this.memoBox1.Name = "memoBox1";
this.memoBox1.Padding = new System.Windows.Forms.Padding(10, 10, 3, 9);
this.memoBox1.Size = new System.Drawing.Size(432, 376);
this.memoBox1.TabIndex = 48;
this.memoBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.memoBox1_DragDrop);
this.memoBox1.DragOver += new System.Windows.Forms.DragEventHandler(this.memoBox1_DragOver);
//
// button8
//
this.button8.BackColor = System.Drawing.Color.Transparent;
this.button8.DefaultImage = null;
this.button8.DownImage = null;
this.button8.IsSelected = false;
this.button8.LabelText = "&Run Next";
this.button8.Location = new System.Drawing.Point(127, 705);
this.button8.Margin = new System.Windows.Forms.Padding(10, 0, 10, 10);
this.button8.Name = "button8";
this.button8.OverImage = null;
this.button8.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3);
this.button8.Size = new System.Drawing.Size(149, 37);
this.button8.TabIndex = 49;
this.button8.MouseClick += new System.Windows.Forms.MouseEventHandler(this.button8_MouseClick);
//
// MainForm
//
this.AllowDrop = true;
@ -400,6 +433,8 @@ namespace RandomFileRunner
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(250)))), ((int)(((byte)(250)))), ((int)(((byte)(250)))));
this.ClientSize = new System.Drawing.Size(464, 761);
this.Controls.Add(this.button8);
this.Controls.Add(this.memoBox1);
this.Controls.Add(this.button3);
this.Controls.Add(this.button4);
this.Controls.Add(this.tHorizontalSeparator1);
@ -468,6 +503,7 @@ namespace RandomFileRunner
private RyzStudio.Windows.ThemedForms.TClearableTextBox textBox1;
private RyzStudio.Windows.ThemedForms.TButton tButton1;
private RyzStudio.Windows.ThemedForms.TMenuButton button3;
private RyzStudio.Windows.ThemedForms.TButton button8;
}
}

View File

@ -1,5 +1,6 @@
using RyzStudio.Windows.Forms;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
@ -13,20 +14,17 @@ namespace RandomFileRunner
protected OptionsForm optionsForm = null;
protected bool isBusy = false;
protected string videoFilename = null;
protected TimeSpan videoDuration = TimeSpan.FromSeconds(0);
protected Process currentProcess = null;
public MainForm()
{
InitializeComponent();
textBox1.Text = "*.*";
memoBox1.InnerTextBox.WordWrap = false;
randy = new Random();
//textBox1.InnerTextBox.ReadOnly = true;
//textBox1.InnerTextBox.BackColor = Color.White;
//textBox1.InnerTextBox.TextChanged += textBox1_TextChanged;
}
protected override void OnFormClosing(FormClosingEventArgs e)
@ -56,391 +54,9 @@ namespace RandomFileRunner
}
//private void button1_Click(object sender, EventArgs e)
//{
// //string searchPattern = "*.avi|*.mp4|*.ogm|*.mkv";
// //string[] parts = searchPattern.Split(',', ';', '|');
// //var inputFile = new MediaFile { Filename = videoFilename };
// ////var outputFile = new MediaFile { Filename = @"N:\#\invincible.2021.s01e02.here.goes.nothing.720p.webrip.hevc.x265.mkv.jpg" };
// //using (var engine = new Engine())
// //{
// // engine.GetMetadata(inputFile);
// // // Saves the frame located on the 15th second of the video.
// // var options = new ConversionOptions { Seek = TimeSpan.FromSeconds(150) };
// // engine.GetThumbnail(inputFile, outputFile, options);
// //}
// //int i = 0;
// //FFmpegLoader.FFmpegPath = @"L:\repos\WinFormsApp1\bin\Debug\net5.0-windows";
// //MediaFile file = MediaFile.Open(@"N:\#\invincible.2021.s01e03.who.you.calling.ugly.720p.webrip.hevc.x265.mkv");
// //FFMediaToolkit.Graphics.ImageData img;
// //if (file.Video.TryGetNextFrame(out img))
// //{
// // //img..ToBitmap()
// //}
// //while (file.Video.TryGetNextFrame(out var imageData))
// //{
// // imageData.ToBitmap().Save($@"C:\images\frame_{i++}.png");
// // // See the #Usage details for example .ToBitmap() implementation
// // // The .Save() method may be different depending on your graphics library
// //}
// //MessageBox.Show("!");
//}
//private async void button2_Click(object sender, EventArgs e)
//{
// //await Task.Run(() =>
// //{
// // if (string.IsNullOrWhiteSpace(textBox1.Text)) return;
// // if (!Directory.Exists(textBox1.Text)) return;
// // ThreadControl.Clear(richTextBox1);
// // //string[] extensionFilters = new string[] { ".avi", ".mp4", ".ogm", ".mkv" };
// // ThreadControl.SetText(textBox1, @"C:\Windows");
// // List<string> fileList = RyzStudio.IO.SmarterFileSystem.GetFiles(textBox1.Text, "*.avi|*.mp4|*.ogm|*.mkv", SearchOption.AllDirectories);
// // //string[] fileList = Directory.GetFiles(textBox1.Text, "*.avi|*.mp4|*.ogm|*.mkv", SearchOption.TopDirectoryOnly);
// // foreach (string item in fileList)
// // {
// // ThreadControl.AddLine(richTextBox1, item);
// // //if (IsMatchExtension(item, extensionFilters))
// // //{
// // // ThreadControl.AddLine(richTextBox1, item);
// // //}
// // }
// // MessageBox.Show("!");
// //});
//}
//private bool IsMatchExtension(string filename, string[] extensionFilters)
//{
// string ext = Path.GetExtension(filename)?.ToLower();
// foreach (var item in extensionFilters)
// {
// if (ext.Equals(item))
// {
// return true;
// }
// }
// return false;
//}
//private string[] Split(string lines)
//{
// string[] rs = new string[0];
// foreach (string item in lines.Split(',', ';', '|'))
// {
// if (string.IsNullOrWhiteSpace(item))
// {
// continue;
// }
// Array.Resize(ref rs, (rs.Length + 1));
// rs[(rs.Length - 1)] = item?.Trim();
// }
// return rs;
//}
//private void Form1_DragOver(object sender, DragEventArgs e)
//{
// e.Effect = (e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None);
//}
//private async void Form1_DragDrop(object sender, DragEventArgs e)
//{
// string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
// if (fileList == null)
// {
// return;
// }
// if (fileList.Length <= 0)
// {
// return;
// }
// //await ReadVideoFile(fileList[0]);
//}
//private async void textBox1_TextChanged(object sender, EventArgs e)
//{
// //await ReadVideoFile(textBox1.Text);
//}
public AppSession CurrentSession { get; set; } = new AppSession();
private void button1_MouseClick(object sender, MouseEventArgs e)
{
this.Close();
}
//private void button2_MouseClick(object sender, MouseEventArgs e)
//{
// if (this.IsBusy)
// {
// return;
// }
// if (optionsForm == null) optionsForm = new OptionsForm(this.CurrentSession);
// if (optionsForm.ShowDialog() == DialogResult.OK)
// {
// this.CurrentSession = optionsForm.Session;
// this.TopMost = this.CurrentSession.AlwaysOnTop;
// }
//}
//private async void button3_MouseClick(object sender, MouseEventArgs e)
//{
// //await ReadVideoFile(textBox1.Text);
//}
//protected TimeSpan CalcRandomTimeSpan(TimeSpan duration)
//{
// int mm = randy.Next(0, (int)Math.Floor(duration.TotalMinutes));
// int ss = randy.Next(0, duration.Seconds);
// return new TimeSpan(0, mm, ss);
//}
//protected void Clear()
//{
// videoFilename = null;
// videoDuration = TimeSpan.FromSeconds(0);
// //textBox1.Text = string.Empty;
// //ThreadControl.SetText(label5, "-");
// //ThreadControl.SetText(label7, "-");
// ThreadControl.SetText(label2, "-");
// //ThreadControl.Clear(flowLayoutPanel1);
//}
//protected Label CreateLabel(TimeSpan duration)
//{
// Label label = new Label();
// label.Padding = new Padding(0);
// label.Margin = new Padding(0, 0, 0, 10);
// label.Text = string.Format("{0}h {1}m {2}s", duration.Hours, duration.Minutes, duration.Seconds);
// return label;
//}
//protected PictureBox CreatePictureBox(string filename, int width, int height)
//{
// PictureBox imageBox = new PictureBox()
// {
// BackColor = Color.White,
// Margin = new Padding(0, 0, 0, 0),
// Padding = new Padding(0),
// SizeMode = PictureBoxSizeMode.Zoom,
// Width = width,
// Height = height,
// };
// imageBox.Load(filename);
// return imageBox;
//}
//protected void DeleteFile(string filename)
//{
// try
// {
// File.Delete(filename);
// }
// catch
// {
// // do nothing
// }
//}
//private void pictureBox1_Click(object sender, EventArgs e)
//{
//}
//protected string GetTempFolder()
//{
// string path = Path.Combine(Application.StartupPath, "tmp");
// if (Directory.Exists(path))
// {
// return path;
// }
// try
// {
// Directory.CreateDirectory(path);
// }
// catch
// {
// // do nothing
// }
// if (Directory.Exists(path))
// {
// return path;
// }
// path = Path.GetTempPath();
// if (Directory.Exists(path))
// {
// return path;
// }
// return null;
//}
//protected decimal ParseFrameSizeRatio(string videoSize)
//{
// if (string.IsNullOrWhiteSpace(videoSize))
// {
// return 0;
// }
// string[] parts = videoSize.Trim().Split("x");
// if (parts.Length != 2)
// {
// return 0;
// }
// int w;
// if (!int.TryParse(parts[0], out w))
// {
// return 0;
// }
// int h;
// if (!int.TryParse(parts[1], out h))
// {
// return 0;
// }
// try
// {
// return decimal.Divide(w, h);
// }
// catch
// {
// return 0;
// }
//}
//protected async Task ReadVideoFile(string filename)
//{
// await Task.Run(() =>
// {
// if (this.IsBusy)
// {
// return;
// }
// this.IsBusy = true;
// Clear();
// MediaFile inputFile = new MediaFile
// {
// Filename = filename
// };
// using (Engine engine = new Engine())
// {
// try
// {
// engine.GetMetadata(inputFile);
// }
// catch (Exception exc)
// {
// MessageBox.Show(exc.Message);
// this.IsBusy = false;
// return;
// }
// }
// videoFilename = filename;
// videoDuration = inputFile.Metadata.Duration;
// textBox1.Text = videoFilename;
// ThreadControl.SetText(label5, inputFile.Metadata.VideoData.Format ?? string.Empty);
// ThreadControl.SetText(label7, (inputFile.Metadata.VideoData.FrameSize ?? string.Empty) + " @ " + inputFile.Metadata.VideoData.Fps.ToString() + "FPS");
// ThreadControl.SetText(label2, string.Format("{0}h {1}m {2}s", videoDuration.Hours, videoDuration.Minutes, videoDuration.Seconds));
// // calculate frame dimensions ratio
// decimal frameRatio = ParseFrameSizeRatio(inputFile.Metadata.VideoData.FrameSize);
// if (frameRatio <= 0)
// {
// this.IsBusy = false;
// return;
// }
// int thumbnailWidth = flowLayoutPanel1.ClientSize.Width - flowLayoutPanel1.Padding.Horizontal - SystemInformation.VerticalScrollBarWidth;
// int thumbnailHeight = (int)Math.Round(decimal.Divide((decimal)thumbnailWidth, frameRatio));
// using (Engine engine = new Engine())
// {
// for (int i = 0; i < this.CurrentSession.NoFrames; i++)
// {
// TimeSpan ts = CalcRandomTimeSpan(videoDuration);
// string thumbnailFilename = Path.ChangeExtension(Path.GetTempFileName(), "jpg");
// ConversionOptions options = new ConversionOptions
// {
// Seek = ts,
// CustomWidth = thumbnailWidth,
// CustomHeight = thumbnailHeight
// };
// engine.GetThumbnail(inputFile, new MediaFile { Filename = thumbnailFilename }, options);
// PictureBox imageBox = CreatePictureBox(thumbnailFilename, thumbnailWidth, thumbnailHeight);
// ThreadControl.Add(flowLayoutPanel1, imageBox);
// Label label = CreateLabel(ts);
// ThreadControl.Add(flowLayoutPanel1, label);
// // clean-up
// DeleteFile(thumbnailFilename);
// }
// }
// this.IsBusy = false;
// });
//}
protected void AddSearchItem(string line)
{
memoBox1.Text = memoBox1.Text.Trim();
@ -503,8 +119,55 @@ namespace RandomFileRunner
memoBox1.Text = string.Empty;
}
private void memoBox1_DragOver(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
if (this.IsBusy)
{
e.Effect = DragDropEffects.None;
}
else
{
e.Effect = DragDropEffects.Copy;
}
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void memoBox1_DragDrop(object sender, DragEventArgs e)
{
if (this.IsBusy) return;
string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
if (fileList == null)
{
return;
}
foreach (string item in fileList)
{
AddSearchItem(item);
}
}
/// <summary>
/// Run next
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button8_MouseClick(object sender, MouseEventArgs e)
{
}
private void button1_MouseClick(object sender, MouseEventArgs e)
{
this.Close();
}
}
}