-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
165 lines (132 loc) · 5.06 KB
/
Program.cs
File metadata and controls
165 lines (132 loc) · 5.06 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SpigotGUI
{
static class Program
{
[DllImport("Shell32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);
public static Edition edition;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
if (File.Exists("licence.spigotgui"))
{
if (File.ReadAllText("licence.spigotgui").Equals(getProfessionalEdition(getSerialNumber() ) + ""))
{
edition = Edition.Professional;
}else
{
MessageBox.Show("Your activation code expired. If this is not right contact me with this message.");
edition = Edition.Standard;
}
}else
{
edition = Edition.Standard;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
public static bool isAssociated()
{
return(Registry.CurrentUser.OpenSubKey("Software\\Classes\\.spigotgui", false) == null);
}
public static void associate()
{
string dir = AppDomain.CurrentDomain.BaseDirectory;
RegistryKey filereg = Registry.CurrentUser.CreateSubKey("Software\\Classes\\.spigotgui");
RegistryKey appreg = Registry.CurrentUser.CreateSubKey("Software\\Classes\\Applications\\SpigotGUI.exe");
RegistryKey assoc = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.spigotgui");
filereg.CreateSubKey("DefaultIcon").SetValue("", dir + "\\icon.ico");
filereg.CreateSubKey("PerceivedType").SetValue("", "Server");
appreg.CreateSubKey("shell\\open\\command").SetValue("", "\"" + Application.ExecutablePath + "\"");
appreg.CreateSubKey("DefaultIcon").SetValue("", dir + "\\icon.ico");
assoc.CreateSubKey("UserChoice").SetValue("Progid", "Applications\\SpigotGUI.exe");
SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
}
public static int getProfessionalEdition(int serial)
{
int num = serial;
num *= num;
num += 5433;
num /= 4;
num *= 77;
return num;
}
public static int getSerialNumber()
{
PhysicalAddress mac = GetMacAddress();
int number = 0;
foreach (char c in mac.ToString().ToCharArray())
{
if (c != '-')
{
if (Char.IsDigit(c))
{
number += int.Parse(c + "");
number = number * 10;
}
if (c == 'A')
{
number += 10;
//number = number * 10;
}
if (c == 'B')
{
number += 11;
//number = number * 10;
}
if (c == 'C')
{
number += 12;
//number = number * 10;
}
if (c == 'D')
{
number += 13;
//number = number * 10;
}
if (c == 'E')
{
number += 14;
//number = number * 10;
}
if (c == 'F')
{
number += 15;
//number = number * 10;
}
}
}
return number;
}
/// <summary>
/// Gets the MAC address of the current PC.
/// </summary>
/// <returns></returns>
public static PhysicalAddress GetMacAddress()
{
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
// Only consider Ethernet network interfaces
if (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet &&
nic.OperationalStatus == OperationalStatus.Up)
{
return nic.GetPhysicalAddress();
}
}
return null;
}
}
}