forked from HearthSim/Hearthstone-Deck-Tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HDTProtocol.cs
66 lines (58 loc) · 1.29 KB
/
HDTProtocol.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
#region
using System;
using System.Linq;
using Microsoft.Win32;
#endregion
namespace HDTHelper
{
public class HDTProtocol
{
private static string Scheme
{
get { return "hdt"; }
}
private static string Path
{
get { return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "HDTHelper.exe"); }
}
internal static bool IsRegistered
{
get { return Registry.ClassesRoot.GetSubKeyNames().Any(x => x == Scheme); }
}
internal static void Register()
{
try
{
var key = Registry.ClassesRoot.CreateSubKey(Scheme);
key.CreateSubKey("DefaultIcon").SetValue("", System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "HDTHelper.exe"));
key.SetValue("", "URL: hdt Protocol Handler");
key.SetValue("URL Protocol", "");
key.CreateSubKey(@"shell\open\command").SetValue("", Path + " %1");
}
catch(Exception ex)
{
}
}
internal static void Delete()
{
if(IsRegistered)
{
try
{
Registry.ClassesRoot.DeleteSubKeyTree(Scheme);
}
catch(Exception)
{
}
}
}
public static bool Verify()
{
var key = Registry.ClassesRoot.OpenSubKey(Scheme);
if(key == null)
return false;
var path = key.OpenSubKey(@"shell\open\command").GetValue("").ToString();
return path.StartsWith(Path);
}
}
}