diff --git a/CompressH265.csproj b/CompressH265.csproj index f495d22..9379aad 100644 --- a/CompressH265.csproj +++ b/CompressH265.csproj @@ -7,7 +7,7 @@ {880679DC-D0C5-4B1A-ADF4-8AA06B738BB5} WinExe CompressH265 - CompressH265 + LazyCompressH265 v4.8 512 true diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 2e639d3..b0e74c4 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -73,6 +73,7 @@ this.linkLabel1.TabIndex = 4; this.linkLabel1.TabStop = true; this.linkLabel1.Text = "https://github.com/louislam"; + this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked); // // buttonContextMenu // @@ -97,6 +98,7 @@ this.Controls.Add(this.button1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Name = "Form1"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Lazy Compress H.265 (HEVC)"; this.Load += new System.EventHandler(this.Form1_Load); this.Shown += new System.EventHandler(this.Form1_Shown); diff --git a/Form1.cs b/Form1.cs index e03061a..7c10a38 100644 --- a/Form1.cs +++ b/Form1.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; +using System.Reflection; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; @@ -16,12 +17,16 @@ namespace CompressH265 { public partial class Form1 : Form { private bool isFromContextMenu = false; + private bool installed = false; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { + var version = Assembly.GetExecutingAssembly().GetName().Version; + Text = Text + " v" + version.Major + "." + version.Minor; + AddShieldToButton(buttonContextMenu); string[] args = Environment.GetCommandLineArgs(); @@ -37,6 +42,20 @@ namespace CompressH265 { 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) { @@ -65,6 +84,17 @@ namespace CompressH265 { } 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.EnableRaisingEvents = true; // process.StartInfo.RedirectStandardOutput = true; @@ -98,11 +128,17 @@ namespace CompressH265 { info.FileName = System.Reflection.Assembly.GetExecutingAssembly().Location; info.UseShellExecute = true; info.Verb = "runas"; // Provides Run as Administrator - info.Arguments = "-contextmenu"; + + if (installed) { + info.Arguments = "-uninstallcontextmenu"; + } else { + info.Arguments = "-contextmenu"; + } try { if (Process.Start(info) != null) { MessageBox.Show("Installed successfully."); + UpdateContextMenuButton(); } else { MessageBox.Show("Error"); } @@ -133,5 +169,9 @@ namespace CompressH265 { Hide(); } } + + private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { + System.Diagnostics.Process.Start("https://github.com/louislam/lazy-compress-h265"); + } } } \ No newline at end of file diff --git a/Program.cs b/Program.cs index b112f17..019d8dd 100644 --- a/Program.cs +++ b/Program.cs @@ -8,6 +8,8 @@ using Microsoft.Win32; namespace CompressH265 { static class Program { + private static string subkey = "*\\shell\\Compress to H.265 (HEVC)"; + /// /// The main entry point for the application. /// @@ -21,6 +23,9 @@ namespace CompressH265 { if (item == "-contextmenu") { installContextMenu(); System.Environment.Exit(1); + } else if (item == "-uninstallcontextmenu") { + uninstallContextMenu(); + System.Environment.Exit(1); } } @@ -44,7 +49,7 @@ namespace CompressH265 { public static void installContextMenu() { RegistryKey item = null; 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\""); } catch(Exception ex) @@ -57,5 +62,9 @@ namespace CompressH265 { item.Close(); } } + + public static void uninstallContextMenu() { + Registry.ClassesRoot.DeleteSubKeyTree(subkey); + } } } \ No newline at end of file diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index db3d7b0..c51f56e 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -5,12 +5,12 @@ using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("CompressH265")] +[assembly: AssemblyTitle("Lazy Compress H.265 (HEVC)")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("CompressH265")] -[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyCompany("WhatSticker.online")] +[assembly: AssemblyProduct("Lazy Compress H.265 (HEVC)")] +[assembly: AssemblyCopyright("WhatSticker.online © 2020")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")]