Winify – Diff between revs 38 and 61
?pathlinks?
Rev 38 | Rev 61 | |||
---|---|---|---|---|
Line 15... | Line 15... | |||
15 | { |
15 | { |
|
16 | #region Public Methods |
16 | #region Public Methods |
|
Line 17... | Line 17... | |||
17 | |
17 | |
|
18 | public static bool LaunchOnBootSet(bool enable) |
18 | public static bool LaunchOnBootSet(bool enable) |
|
19 | { |
19 | { |
|
20 | using (var key = Registry.CurrentUser.OpenSubKey |
20 | using var key = Registry.CurrentUser.OpenSubKey |
|
21 | ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) |
- | ||
22 | { |
21 | ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); |
|
Line 23... | Line 22... | |||
23 | if (key == null) return false; |
22 | if (key == null) return false; |
|
24 | |
23 | |
|
25 | switch (enable) |
24 | switch (enable) |
|
Line 32... | Line 31... | |||
32 | break; |
31 | break; |
|
33 | } |
32 | } |
|
Line 34... | Line 33... | |||
34 | |
33 | |
|
35 | return true; |
34 | return true; |
|
36 | } |
- | ||
Line 37... | Line 35... | |||
37 | } |
35 | } |
|
38 | |
36 | |
|
39 | public static bool LaunchOnBootGet() |
37 | public static bool LaunchOnBootGet() |
|
40 | { |
38 | { |
|
41 | using (var key = Registry.CurrentUser.OpenSubKey |
- | ||
42 | ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) |
39 | using var key = Registry.CurrentUser.OpenSubKey |
|
43 | { |
40 | ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); |
|
44 | return key?.GetValue(Constants.AssemblyName) != null; |
- | ||
Line 45... | Line 41... | |||
45 | } |
41 | return key?.GetValue(Constants.AssemblyName) != null; |
|
46 | } |
42 | } |
|
47 | |
43 | |
|
48 | /// <summary> |
44 | /// <summary> |
|
Line 64... | Line 60... | |||
64 | } |
60 | } |
|
Line 65... | Line 61... | |||
65 | |
61 | |
|
66 | public static async Task<Icon> CreateIconFromResource(string resource) |
62 | public static async Task<Icon> CreateIconFromResource(string resource) |
|
67 | { |
63 | { |
|
68 | var iconBytes = await LoadResource(resource); |
64 | var iconBytes = await LoadResource(resource); |
|
69 | using (var iconMemoryStream = new MemoryStream(iconBytes)) |
- | ||
70 | { |
65 | using var iconMemoryStream = new MemoryStream(iconBytes); |
|
71 | var bitmap = (Bitmap)Image.FromStream(iconMemoryStream); |
66 | var bitmap = (Bitmap)Image.FromStream(iconMemoryStream); |
|
72 | var bitmapIntPtr = bitmap.GetHicon(); |
67 | var bitmapIntPtr = bitmap.GetHicon(); |
|
73 | var icon = Icon.FromHandle(bitmapIntPtr); |
68 | var icon = Icon.FromHandle(bitmapIntPtr); |
|
74 | return icon; |
69 | return icon; |
|
75 | } |
- | ||
Line 76... | Line 70... | |||
76 | } |
70 | } |
|
77 | |
71 | |
|
78 | public static async Task<byte[]> LoadResource(string resource) |
72 | public static async Task<byte[]> LoadResource(string resource) |
|
Line 79... | Line 73... | |||
79 | { |
73 | { |
|
80 | var assembly = Assembly.GetExecutingAssembly(); |
- | ||
81 | |
74 | var assembly = Assembly.GetExecutingAssembly(); |
|
Line 82... | Line 75... | |||
82 | using (var manifestResourceStream = assembly.GetManifestResourceStream(resource)) |
75 | |
|
Line 83... | Line 76... | |||
83 | { |
76 | using var manifestResourceStream = assembly.GetManifestResourceStream(resource); |
|
Line 84... | Line 77... | |||
84 | if (manifestResourceStream == null) return null; |
77 | if (manifestResourceStream == null) return null; |
|
Line 85... | Line 78... | |||
85 | |
78 | |
|
86 | var memoryStream = new MemoryStream(); |
79 | var memoryStream = new MemoryStream(); |
|
87 | |
- | ||
Line 88... | Line 80... | |||
88 | await manifestResourceStream.CopyToAsync(memoryStream); |
80 | |
|
89 | |
81 | await manifestResourceStream.CopyToAsync(memoryStream); |
|
90 | memoryStream.Position = 0L; |
82 | |
|
91 | |
83 | memoryStream.Position = 0L; |
|
Line 148... | Line 140... | |||
148 | public static string GetMachineGuid() |
140 | public static string GetMachineGuid() |
|
149 | { |
141 | { |
|
150 | var location = @"SOFTWARE\Microsoft\Cryptography"; |
142 | var location = @"SOFTWARE\Microsoft\Cryptography"; |
|
151 | var name = "MachineGuid"; |
143 | var name = "MachineGuid"; |
|
Line 152... | Line 144... | |||
152 | |
144 | |
|
153 | using (var localMachineX64View = |
145 | using var localMachineX64View = |
|
154 | RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)) |
- | ||
155 | { |
146 | RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); |
|
156 | using (var rk = localMachineX64View.OpenSubKey(location)) |
- | ||
157 | { |
147 | using var rk = localMachineX64View.OpenSubKey(location); |
|
158 | if (rk == null) |
148 | if (rk == null) |
|
159 | throw new KeyNotFoundException( |
149 | throw new KeyNotFoundException( |
|
Line 160... | Line 150... | |||
160 | string.Format("Key Not Found: {0}", location)); |
150 | string.Format("Key Not Found: {0}", location)); |
|
Line 164... | Line 154... | |||
164 | throw new IndexOutOfRangeException( |
154 | throw new IndexOutOfRangeException( |
|
165 | string.Format("Index Not Found: {0}", name)); |
155 | string.Format("Index Not Found: {0}", name)); |
|
Line 166... | Line 156... | |||
166 | |
156 | |
|
167 | return machineGuid.ToString(); |
157 | return machineGuid.ToString(); |
|
168 | } |
- | ||
169 | } |
- | ||
Line 170... | Line 158... | |||
170 | } |
158 | } |
|
171 | |
159 | |
|
172 | #endregion |
160 | #endregion |
|
173 | } |
161 | } |