2020-05-09 14:26:37 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2020-05-09 16:36:14 +02:00
|
|
|
|
using System.Runtime.InteropServices;
|
2020-05-09 14:26:37 +02:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2020-05-09 16:36:14 +02:00
|
|
|
|
using Microsoft.Win32;
|
2020-05-09 14:26:37 +02:00
|
|
|
|
|
|
|
|
|
namespace CompressH265 {
|
|
|
|
|
public partial class Form1 : Form {
|
2020-05-09 16:36:14 +02:00
|
|
|
|
|
|
|
|
|
private bool isFromContextMenu = false;
|
|
|
|
|
|
2020-05-09 14:26:37 +02:00
|
|
|
|
public Form1() {
|
|
|
|
|
InitializeComponent();
|
2020-05-09 16:36:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e) {
|
|
|
|
|
AddShieldToButton(buttonContextMenu);
|
|
|
|
|
|
|
|
|
|
string[] args = Environment.GetCommandLineArgs();
|
|
|
|
|
|
|
|
|
|
var isInputFilePath = false;
|
|
|
|
|
foreach (var arg in args) {
|
|
|
|
|
if (arg == "-i") {
|
|
|
|
|
isInputFilePath = true;
|
|
|
|
|
} else if (isInputFilePath) {
|
|
|
|
|
isFromContextMenu = true;
|
|
|
|
|
textBox1.Text = arg;
|
|
|
|
|
isInputFilePath = false;
|
|
|
|
|
button2_Click(null, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-09 14:26:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void button1_Click(object sender, EventArgs e) {
|
|
|
|
|
openFileDialog1.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void openFileDialog1_FileOk(object sender, CancelEventArgs e) {
|
|
|
|
|
textBox1.Text = openFileDialog1.FileName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Form1_DragDrop(object sender, DragEventArgs e) {
|
|
|
|
|
string[] fileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
|
|
|
|
|
textBox1.Text = fileList[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Form1_DragEnter(object sender, DragEventArgs e) {
|
|
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void button2_Click(object sender, EventArgs e) {
|
|
|
|
|
Process process = new Process();
|
|
|
|
|
process.EnableRaisingEvents = true;
|
|
|
|
|
// process.StartInfo.RedirectStandardOutput = true;
|
|
|
|
|
// process.StartInfo.RedirectStandardError = true;
|
|
|
|
|
|
|
|
|
|
var outputFilename = textBox1.Text + ".h265.mp4";
|
|
|
|
|
|
|
|
|
|
process.StartInfo.FileName = "cmd.exe";
|
2020-05-09 16:36:14 +02:00
|
|
|
|
process.StartInfo.Arguments = $"/K ffmpeg.exe -i \"{textBox1.Text}\" -vcodec hevc -map_metadata 0 \"{outputFilename}\"";
|
2020-05-09 14:26:37 +02:00
|
|
|
|
process.StartInfo.UseShellExecute = false;
|
|
|
|
|
// process.StartInfo.CreateNoWindow = true;
|
2020-05-09 16:36:14 +02:00
|
|
|
|
|
|
|
|
|
process.Exited += (sender2, e2) => {
|
|
|
|
|
System.Environment.Exit(1);
|
|
|
|
|
};
|
2020-05-09 14:26:37 +02:00
|
|
|
|
|
|
|
|
|
// process.OutputDataReceived += OnProcessOutput;
|
|
|
|
|
// process.ErrorDataReceived += OnProcessOutput;
|
|
|
|
|
process.Start();
|
|
|
|
|
|
|
|
|
|
// process.BeginErrorReadLine();
|
|
|
|
|
// process.BeginOutputReadLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnProcessOutput(object send, DataReceivedEventArgs args) {
|
|
|
|
|
// textBox2.Text += args.Data;
|
|
|
|
|
}
|
2020-05-09 16:36:14 +02:00
|
|
|
|
|
|
|
|
|
private void button3_Click(object sender, EventArgs e) {
|
|
|
|
|
ProcessStartInfo info = new ProcessStartInfo();
|
|
|
|
|
info.FileName = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
|
|
|
|
info.UseShellExecute = true;
|
|
|
|
|
info.Verb = "runas"; // Provides Run as Administrator
|
|
|
|
|
info.Arguments = "-contextmenu";
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (Process.Start(info) != null) {
|
|
|
|
|
MessageBox.Show("Installed successfully.");
|
|
|
|
|
} else {
|
|
|
|
|
MessageBox.Show("Error");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception exception) {
|
|
|
|
|
MessageBox.Show("Error: You have to allow UAC in order to install to the context menu.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
|
public static extern int SendMessage(IntPtr hWnd,
|
|
|
|
|
uint Msg, int wParam, int lParam);
|
|
|
|
|
|
|
|
|
|
// Make the button display the UAC shield.
|
|
|
|
|
public static void AddShieldToButton(Button btn)
|
|
|
|
|
{
|
|
|
|
|
const Int32 BCM_SETSHIELD = 0x160C;
|
|
|
|
|
|
|
|
|
|
// Give the button the flat style and make it
|
|
|
|
|
// display the UAC shield.
|
|
|
|
|
btn.FlatStyle = System.Windows.Forms.FlatStyle.System;
|
|
|
|
|
SendMessage(btn.Handle, BCM_SETSHIELD, 0, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Form1_Shown(object sender, EventArgs e) {
|
|
|
|
|
if (isFromContextMenu) {
|
|
|
|
|
Hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-09 14:26:37 +02:00
|
|
|
|
}
|
|
|
|
|
}
|