diff --git a/Form1.Designer.cs b/Form1.Designer.cs index b0e74c4..6e4fed4 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -30,6 +30,11 @@ private void InitializeComponent() { this.button2 = new System.Windows.Forms.Button(); this.linkLabel1 = new System.Windows.Forms.LinkLabel(); this.buttonContextMenu = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.FilePath = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Status = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize) (this.dataGridView1)).BeginInit(); this.SuspendLayout(); // // button1 @@ -66,7 +71,7 @@ private void InitializeComponent() { // // linkLabel1 // - this.linkLabel1.Location = new System.Drawing.Point(314, 93); + this.linkLabel1.Location = new System.Drawing.Point(315, 276); this.linkLabel1.Name = "linkLabel1"; this.linkLabel1.RightToLeft = System.Windows.Forms.RightToLeft.Yes; this.linkLabel1.Size = new System.Drawing.Size(284, 23); @@ -85,12 +90,49 @@ private void InitializeComponent() { this.buttonContextMenu.UseVisualStyleBackColor = true; this.buttonContextMenu.Click += new System.EventHandler(this.button3_Click); // + // label1 + // + this.label1.Location = new System.Drawing.Point(12, 99); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(100, 23); + this.label1.TabIndex = 7; + this.label1.Text = "Task List"; + // + // dataGridView1 + // + this.dataGridView1.AllowUserToAddRows = false; + this.dataGridView1.AllowUserToDeleteRows = false; + this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight; + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {this.FilePath, this.Status}); + this.dataGridView1.Location = new System.Drawing.Point(12, 120); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.ReadOnly = true; + this.dataGridView1.RowTemplate.Height = 24; + this.dataGridView1.Size = new System.Drawing.Size(587, 141); + this.dataGridView1.TabIndex = 8; + // + // FilePath + // + this.FilePath.HeaderText = "File Path"; + this.FilePath.Name = "FilePath"; + this.FilePath.ReadOnly = true; + // + // Status + // + this.Status.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Status.HeaderText = "Status"; + this.Status.Name = "Status"; + this.Status.ReadOnly = true; + // // Form1 // this.AllowDrop = true; this.AutoScaleDimensions = new System.Drawing.SizeF(120F, 120F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; - this.ClientSize = new System.Drawing.Size(610, 125); + this.ClientSize = new System.Drawing.Size(610, 307); + this.Controls.Add(this.dataGridView1); + this.Controls.Add(this.label1); this.Controls.Add(this.buttonContextMenu); this.Controls.Add(this.linkLabel1); this.Controls.Add(this.button2); @@ -100,10 +142,12 @@ private void InitializeComponent() { this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Lazy Compress H.265 (HEVC)"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Load += new System.EventHandler(this.Form1_Load); this.Shown += new System.EventHandler(this.Form1_Shown); this.DragDrop += new System.Windows.Forms.DragEventHandler(this.Form1_DragDrop); this.DragEnter += new System.Windows.Forms.DragEventHandler(this.Form1_DragEnter); + ((System.ComponentModel.ISupportInitialize) (this.dataGridView1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } @@ -111,8 +155,12 @@ private void InitializeComponent() { private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button buttonContextMenu; + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.DataGridViewTextBoxColumn FilePath; + private System.Windows.Forms.Label label1; private System.Windows.Forms.LinkLabel linkLabel1; private System.Windows.Forms.OpenFileDialog openFileDialog1; + private System.Windows.Forms.DataGridViewTextBoxColumn Status; private System.Windows.Forms.TextBox textBox1; #endregion diff --git a/Form1.cs b/Form1.cs index 7c10a38..60c3dcd 100644 --- a/Form1.cs +++ b/Form1.cs @@ -18,7 +18,10 @@ public partial class Form1 : Form { private bool isFromContextMenu = false; private bool installed = false; - + private int nextTaskID = 0; + + private int runningProcessCount = 0; + public Form1() { InitializeComponent(); } @@ -84,43 +87,79 @@ private void Form1_DragEnter(object sender, DragEventArgs e) { } private void button2_Click(object sender, EventArgs e) { - - if (textBox1.Text.Trim() == "") { + var inputFilename = textBox1.Text; + var shortName = Path.GetFileName(inputFilename); + + if (inputFilename.Trim() == "") { MessageBox.Show("Please select or drag-and-drop a file."); return; } - if (!File.Exists(textBox1.Text)) { + if (!File.Exists(inputFilename)) { MessageBox.Show("File Not Found"); return; } + + var creationTime = File.GetCreationTime(inputFilename); + var lastAccessTime = File.GetLastAccessTime(inputFilename); + var lastWriteTime = File.GetLastWriteTime(inputFilename); Process process = new Process(); process.EnableRaisingEvents = true; - // process.StartInfo.RedirectStandardOutput = true; - // process.StartInfo.RedirectStandardError = true; - var outputFilename = textBox1.Text + ".h265.mp4"; + var outputFilename = inputFilename + ".h265.mp4"; + + if (File.Exists(outputFilename)) { + MessageBox.Show("The output file name is existing. Please move or delete it before converting. " + outputFilename); + return; + } - process.StartInfo.FileName = "cmd.exe"; - process.StartInfo.Arguments = $"/K ffmpeg.exe -i \"{textBox1.Text}\" -vcodec hevc -map_metadata 0 \"{outputFilename}\""; + process.StartInfo.FileName = "ffmpeg.exe"; + process.StartInfo.Arguments = $"-i \"{inputFilename}\" -vcodec hevc -map_metadata 0 \"{outputFilename}\""; process.StartInfo.UseShellExecute = false; - // process.StartInfo.CreateNoWindow = true; + process.StartInfo.CreateNoWindow = true; - process.Exited += (sender2, e2) => { - System.Environment.Exit(1); + var rowID = nextTaskID++; + var msgQueue = new Queue(); + dataGridView1.Rows.Insert(rowID, shortName, "Preparing..."); + var row = dataGridView1.Rows[rowID]; + + process.StartInfo.RedirectStandardError = true; + process.ErrorDataReceived += (errorEvent,errorArgs) => { + if (errorArgs.Data == null || errorArgs.Data.Trim() == "") { + return; + } + + msgQueue.Enqueue(errorArgs.Data); + + if (msgQueue.Count == 5) { + msgQueue.Dequeue(); + } + + row.Cells[1].Value = String.Join(" | ", msgQueue.Reverse()); }; - // process.OutputDataReceived += OnProcessOutput; - // process.ErrorDataReceived += OnProcessOutput; - process.Start(); - - // process.BeginErrorReadLine(); - // process.BeginOutputReadLine(); - } + process.Exited += (sender2, e2) => { + + if (File.Exists(outputFilename)) { + File.SetCreationTime(outputFilename, creationTime); + File.SetLastAccessTime(outputFilename, lastAccessTime); + File.SetLastWriteTime(outputFilename, lastWriteTime); + } + + msgQueue.Enqueue("Finish"); + row.Cells[1].Value = String.Join(" | ", msgQueue.Reverse()); + + if (isFromContextMenu) { + //System.Environment.Exit(1); + } - private void OnProcessOutput(object send, DataReceivedEventArgs args) { - // textBox2.Text += args.Data; + runningProcessCount--; + }; + + runningProcessCount++; + process.Start(); + process.BeginErrorReadLine(); } private void button3_Click(object sender, EventArgs e) { @@ -166,12 +205,23 @@ public static void AddShieldToButton(Button btn) private void Form1_Shown(object sender, EventArgs e) { if (isFromContextMenu) { - Hide(); + //Hide(); } } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { System.Diagnostics.Process.Start("https://github.com/louislam/lazy-compress-h265"); } + + private void Form1_FormClosing(object sender, FormClosingEventArgs e) { + if (runningProcessCount > 0) { + var result = MessageBox.Show("Are you sure want to stop the processing?", "Stop process", + MessageBoxButtons.YesNo, + MessageBoxIcon.Question); + + e.Cancel = (result == DialogResult.No); + } + + } } } \ No newline at end of file diff --git a/Form1.resx b/Form1.resx index a229768..e295711 100644 --- a/Form1.resx +++ b/Form1.resx @@ -120,4 +120,10 @@ 23, 17 + + True + + + True + \ No newline at end of file diff --git a/Program.cs b/Program.cs index 019d8dd..d6d8a78 100644 --- a/Program.cs +++ b/Program.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; +using System.Reflection; using System.Threading.Tasks; using System.Windows.Forms; using Microsoft.Win32; @@ -15,7 +17,13 @@ static class Program { /// [STAThread] static void Main(string[] args) { - + var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + + if (path != null) { + Environment.CurrentDirectory = path; + } + + foreach(var item in args) { Console.WriteLine(item); diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index c51f56e..aafe802 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file +[assembly: AssemblyVersion("1.1.0.0")] +[assembly: AssemblyFileVersion("1.1.0.0")] \ No newline at end of file diff --git a/README.md b/README.md index 22ded4a..e6371ec 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ https://github.com/louislam/lazy-compress-h265/releases * No config is required * Easy to use, drag-and-drop and compress * Alternative, you could install to your Context Menu, one-click to compress +* Keep metadata, date created and date modified. * Output to the same folder with postfix ".h265.mp4" * Portable