improve and uninstall from context menu
This commit is contained in:
parent
b232647c78
commit
cbe0525228
|
@ -7,7 +7,7 @@
|
||||||
<ProjectGuid>{880679DC-D0C5-4B1A-ADF4-8AA06B738BB5}</ProjectGuid>
|
<ProjectGuid>{880679DC-D0C5-4B1A-ADF4-8AA06B738BB5}</ProjectGuid>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<RootNamespace>CompressH265</RootNamespace>
|
<RootNamespace>CompressH265</RootNamespace>
|
||||||
<AssemblyName>CompressH265</AssemblyName>
|
<AssemblyName>LazyCompressH265</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
|
|
|
@ -73,6 +73,7 @@
|
||||||
this.linkLabel1.TabIndex = 4;
|
this.linkLabel1.TabIndex = 4;
|
||||||
this.linkLabel1.TabStop = true;
|
this.linkLabel1.TabStop = true;
|
||||||
this.linkLabel1.Text = "https://github.com/louislam";
|
this.linkLabel1.Text = "https://github.com/louislam";
|
||||||
|
this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
|
||||||
//
|
//
|
||||||
// buttonContextMenu
|
// buttonContextMenu
|
||||||
//
|
//
|
||||||
|
@ -97,6 +98,7 @@
|
||||||
this.Controls.Add(this.button1);
|
this.Controls.Add(this.button1);
|
||||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||||
this.Name = "Form1";
|
this.Name = "Form1";
|
||||||
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
this.Text = "Lazy Compress H.265 (HEVC)";
|
this.Text = "Lazy Compress H.265 (HEVC)";
|
||||||
this.Load += new System.EventHandler(this.Form1_Load);
|
this.Load += new System.EventHandler(this.Form1_Load);
|
||||||
this.Shown += new System.EventHandler(this.Form1_Shown);
|
this.Shown += new System.EventHandler(this.Form1_Shown);
|
||||||
|
|
40
Form1.cs
40
Form1.cs
|
@ -6,6 +6,7 @@ using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -16,12 +17,16 @@ namespace CompressH265 {
|
||||||
public partial class Form1 : Form {
|
public partial class Form1 : Form {
|
||||||
|
|
||||||
private bool isFromContextMenu = false;
|
private bool isFromContextMenu = false;
|
||||||
|
private bool installed = false;
|
||||||
|
|
||||||
public Form1() {
|
public Form1() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Form1_Load(object sender, EventArgs e) {
|
private void Form1_Load(object sender, EventArgs e) {
|
||||||
|
var version = Assembly.GetExecutingAssembly().GetName().Version;
|
||||||
|
Text = Text + " v" + version.Major + "." + version.Minor;
|
||||||
|
|
||||||
AddShieldToButton(buttonContextMenu);
|
AddShieldToButton(buttonContextMenu);
|
||||||
|
|
||||||
string[] args = Environment.GetCommandLineArgs();
|
string[] args = Environment.GetCommandLineArgs();
|
||||||
|
@ -37,6 +42,20 @@ namespace CompressH265 {
|
||||||
button2_Click(null, null);
|
button2_Click(null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateContextMenuButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateContextMenuButton() {
|
||||||
|
var a = Registry.ClassesRoot.OpenSubKey("*\\shell\\Compress to H.265 (HEVC)");
|
||||||
|
|
||||||
|
if (a == null) {
|
||||||
|
buttonContextMenu.Text = "Install to Context Menu";
|
||||||
|
installed = false;
|
||||||
|
} else {
|
||||||
|
buttonContextMenu.Text = "Uninstall from Context Menu";
|
||||||
|
installed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button1_Click(object sender, EventArgs e) {
|
private void button1_Click(object sender, EventArgs e) {
|
||||||
|
@ -65,6 +84,17 @@ namespace CompressH265 {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button2_Click(object sender, EventArgs e) {
|
private void button2_Click(object sender, EventArgs e) {
|
||||||
|
|
||||||
|
if (textBox1.Text.Trim() == "") {
|
||||||
|
MessageBox.Show("Please select or drag-and-drop a file.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!File.Exists(textBox1.Text)) {
|
||||||
|
MessageBox.Show("File Not Found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Process process = new Process();
|
Process process = new Process();
|
||||||
process.EnableRaisingEvents = true;
|
process.EnableRaisingEvents = true;
|
||||||
// process.StartInfo.RedirectStandardOutput = true;
|
// process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
@ -98,11 +128,17 @@ namespace CompressH265 {
|
||||||
info.FileName = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
info.FileName = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
||||||
info.UseShellExecute = true;
|
info.UseShellExecute = true;
|
||||||
info.Verb = "runas"; // Provides Run as Administrator
|
info.Verb = "runas"; // Provides Run as Administrator
|
||||||
|
|
||||||
|
if (installed) {
|
||||||
|
info.Arguments = "-uninstallcontextmenu";
|
||||||
|
} else {
|
||||||
info.Arguments = "-contextmenu";
|
info.Arguments = "-contextmenu";
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (Process.Start(info) != null) {
|
if (Process.Start(info) != null) {
|
||||||
MessageBox.Show("Installed successfully.");
|
MessageBox.Show("Installed successfully.");
|
||||||
|
UpdateContextMenuButton();
|
||||||
} else {
|
} else {
|
||||||
MessageBox.Show("Error");
|
MessageBox.Show("Error");
|
||||||
}
|
}
|
||||||
|
@ -133,5 +169,9 @@ namespace CompressH265 {
|
||||||
Hide();
|
Hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
|
||||||
|
System.Diagnostics.Process.Start("https://github.com/louislam/lazy-compress-h265");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
11
Program.cs
11
Program.cs
|
@ -8,6 +8,8 @@ using Microsoft.Win32;
|
||||||
|
|
||||||
namespace CompressH265 {
|
namespace CompressH265 {
|
||||||
static class Program {
|
static class Program {
|
||||||
|
private static string subkey = "*\\shell\\Compress to H.265 (HEVC)";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -21,6 +23,9 @@ namespace CompressH265 {
|
||||||
if (item == "-contextmenu") {
|
if (item == "-contextmenu") {
|
||||||
installContextMenu();
|
installContextMenu();
|
||||||
System.Environment.Exit(1);
|
System.Environment.Exit(1);
|
||||||
|
} else if (item == "-uninstallcontextmenu") {
|
||||||
|
uninstallContextMenu();
|
||||||
|
System.Environment.Exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,7 +49,7 @@ namespace CompressH265 {
|
||||||
public static void installContextMenu() {
|
public static void installContextMenu() {
|
||||||
RegistryKey item = null;
|
RegistryKey item = null;
|
||||||
try {
|
try {
|
||||||
item = Registry.ClassesRoot.CreateSubKey("*\\shell\\Compress to H.265 (HEVC)\\command");
|
item = Registry.ClassesRoot.CreateSubKey(subkey + "\\command");
|
||||||
item.SetValue("", System.Reflection.Assembly.GetExecutingAssembly().Location + " -i \"%1\"");
|
item.SetValue("", System.Reflection.Assembly.GetExecutingAssembly().Location + " -i \"%1\"");
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
|
@ -57,5 +62,9 @@ namespace CompressH265 {
|
||||||
item.Close();
|
item.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void uninstallContextMenu() {
|
||||||
|
Registry.ClassesRoot.DeleteSubKeyTree(subkey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,12 +5,12 @@ using System.Runtime.InteropServices;
|
||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
// set of attributes. Change these attribute values to modify the information
|
// set of attributes. Change these attribute values to modify the information
|
||||||
// associated with an assembly.
|
// associated with an assembly.
|
||||||
[assembly: AssemblyTitle("CompressH265")]
|
[assembly: AssemblyTitle("Lazy Compress H.265 (HEVC)")]
|
||||||
[assembly: AssemblyDescription("")]
|
[assembly: AssemblyDescription("")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("WhatSticker.online")]
|
||||||
[assembly: AssemblyProduct("CompressH265")]
|
[assembly: AssemblyProduct("Lazy Compress H.265 (HEVC)")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2020")]
|
[assembly: AssemblyCopyright("WhatSticker.online © 2020")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue