Skip to content

Commit

Permalink
add task list, carry created/modified date to new file
Browse files Browse the repository at this point in the history
  • Loading branch information
louislam committed May 10, 2020
1 parent cbe0525 commit 31c292f
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 27 deletions.
52 changes: 50 additions & 2 deletions Form1.Designer.cs

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

94 changes: 72 additions & 22 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<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) {
Expand Down Expand Up @@ -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);
}

}
}
}
6 changes: 6 additions & 0 deletions Form1.resx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
10 changes: 9 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,7 +17,13 @@ static class Program {
/// </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);
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 31c292f

Please sign in to comment.