Winify – Diff between revs 38 and 61

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
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);
23 if (key == null) return false; -  
24   -  
25 switch (enable) -  
26 { -  
27 case true: -  
28 key.SetValue(Constants.AssemblyName, Assembly.GetEntryAssembly().Location); -  
29 break; -  
30 default: -  
31 key.DeleteValue(Constants.AssemblyName, false); -  
32 break; -  
Line -... Line 22...
-   22 if (key == null) return false;
-   23  
33 } 24 switch (enable)
-   25 {
-   26 case true:
-   27 key.SetValue(Constants.AssemblyName, Assembly.GetEntryAssembly().Location);
-   28 break;
-   29 default:
34   30 key.DeleteValue(Constants.AssemblyName, false);
-   31 break;
-   32 }
35 return true; 33  
Line 36... Line 34...
36 } 34 return true;
37 } 35 }
38   36  
39 public static bool LaunchOnBootGet() 37 public static bool LaunchOnBootGet()
40 { -  
41 using (var key = Registry.CurrentUser.OpenSubKey 38 {
42 ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) -  
43 { 39 using var key = Registry.CurrentUser.OpenSubKey
Line 44... Line 40...
44 return key?.GetValue(Constants.AssemblyName) != null; 40 ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
45 } 41 return key?.GetValue(Constants.AssemblyName) != null;
46 } 42 }
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; -  
75 } 69 return icon;
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(); -  
87   79 var memoryStream = new MemoryStream();
Line 88... Line 80...
88 await manifestResourceStream.CopyToAsync(memoryStream); 80  
89   81 await manifestResourceStream.CopyToAsync(memoryStream);
90 memoryStream.Position = 0L; 82  
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(
160 string.Format("Key Not Found: {0}", location)); 150 string.Format("Key Not Found: {0}", location));
161   151  
162 var machineGuid = rk.GetValue(name); 152 var machineGuid = rk.GetValue(name);
163 if (machineGuid == null) 153 if (machineGuid == null)
164 throw new IndexOutOfRangeException( 154 throw new IndexOutOfRangeException(
Line 165... Line 155...
165 string.Format("Index Not Found: {0}", name)); 155 string.Format("Index Not Found: {0}", name));
166   -  
167 return machineGuid.ToString(); -  
168 } 156  
Line 169... Line 157...
169 } 157 return machineGuid.ToString();
170 } 158 }
171   159  
172 #endregion 160 #endregion