-
Notifications
You must be signed in to change notification settings - Fork 10
/
Program.cs
78 lines (62 loc) · 2.3 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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;
namespace CompressH265 {
static class Program {
private static string subkey = "*\\shell\\Compress to H.265 (HEVC)";
/// <summary>
/// The main entry point for the application.
/// </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);
if (item == "-contextmenu") {
installContextMenu();
System.Environment.Exit(1);
} else if (item == "-uninstallcontextmenu") {
uninstallContextMenu();
System.Environment.Exit(1);
}
}
// ***this line is added***
if (Environment.OSVersion.Version.Major >= 6)
SetProcessDPIAware();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
// ***also dllimport of that function***
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
public static void installContextMenu() {
RegistryKey item = null;
try {
item = Registry.ClassesRoot.CreateSubKey(subkey + "\\command");
item.SetValue("", System.Reflection.Assembly.GetExecutingAssembly().Location + " -i \"%1\"");
}
catch(Exception ex)
{
}
finally
{
if(item != null)
item.Close();
}
}
public static void uninstallContextMenu() {
Registry.ClassesRoot.DeleteSubKeyTree(subkey);
}
}
}