add task list, carry created/modified date to new file

This commit is contained in:
LouisLam 2020-05-10 19:27:39 +08:00
parent cbe0525228
commit 31c292f7be
6 changed files with 140 additions and 27 deletions

52
Form1.Designer.cs generated
View File

@ -30,6 +30,11 @@
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 @@
//
// 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 @@
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 @@
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 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

View File

@ -18,7 +18,10 @@ namespace CompressH265 {
private bool isFromContextMenu = false;
private bool installed = false;
private int nextTaskID = 0;
private int runningProcessCount = 0;
public Form1() {
InitializeComponent();
}
@ -84,43 +87,79 @@ namespace CompressH265 {
}
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<string>();
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 @@ namespace CompressH265 {
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);
}
}
}
}

View File

@ -120,4 +120,10 @@
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>23, 17</value>
</metadata>
<metadata name="FilePath.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Status.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -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 @@ namespace CompressH265 {
/// </summary>
[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);

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// 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")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]

View File

@ -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