Winify – Diff between revs 14 and 28

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 14 Rev 28
Line 15... Line 15...
15 #region Public Methods 15 #region Public Methods
Line 16... Line 16...
16   16  
17 public static TimeSpan GetIdleTime() 17 public static TimeSpan GetIdleTime()
18 { 18 {
19 var lastInPut = new Natives.LASTINPUTINFO(); 19 var lastInPut = new Natives.LASTINPUTINFO();
20 lastInPut.cbSize = (uint) Marshal.SizeOf(lastInPut); 20 lastInPut.cbSize = (uint)Marshal.SizeOf(lastInPut);
Line 21... Line 21...
21 Natives.GetLastInputInfo(ref lastInPut); 21 Natives.GetLastInputInfo(ref lastInPut);
22   22  
Line 23... Line 23...
23 return TimeSpan.FromMilliseconds((uint) Environment.TickCount - lastInPut.dwTime); 23 return TimeSpan.FromMilliseconds((uint)Environment.TickCount - lastInPut.dwTime);
24 } 24 }
25   25  
26 public static bool LaunchOnBootSet(bool enable) 26 public static bool LaunchOnBootSet(bool enable)
27 { 27 {
28 using (var key = Registry.CurrentUser.OpenSubKey -  
29 ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) -  
30 { 28 using (var key = Registry.CurrentUser.OpenSubKey
31 if (key == null) -  
Line 32... Line 29...
32 { 29 ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
33 return false; 30 {
34 } 31 if (key == null) return false;
35   32  
Line 48... Line 45...
48 } 45 }
Line 49... Line 46...
49   46  
50 public static bool LaunchOnBootGet() 47 public static bool LaunchOnBootGet()
51 { 48 {
52 using (var key = Registry.CurrentUser.OpenSubKey 49 using (var key = Registry.CurrentUser.OpenSubKey
53 ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) 50 ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
54 { 51 {
55 return key?.GetValue(Constants.AssemblyName) != null; 52 return key?.GetValue(Constants.AssemblyName) != null;
56 } 53 }
Line 62... Line 59...
62 /// <param name="control">the control to enable double buffering for</param> 59 /// <param name="control">the control to enable double buffering for</param>
63 /// <returns>true on success</returns> 60 /// <returns>true on success</returns>
64 /// <remarks>Do not enable double buffering on RDP: https://devblogs.microsoft.com/oldnewthing/20060103-12/?p=32793</remarks> 61 /// <remarks>Do not enable double buffering on RDP: https://devblogs.microsoft.com/oldnewthing/20060103-12/?p=32793</remarks>
65 public static bool SetDoubleBuffered(this Control control) 62 public static bool SetDoubleBuffered(this Control control)
66 { 63 {
67 if (SystemInformation.TerminalServerSession) 64 if (SystemInformation.TerminalServerSession) return false;
68 { -  
69 return false; -  
70 } -  
Line 71... Line 65...
71   65  
72 var dgvType = control.GetType(); 66 var dgvType = control.GetType();
73 var pi = dgvType.GetProperty("DoubleBuffered", 67 var pi = dgvType.GetProperty("DoubleBuffered",
74 BindingFlags.Instance | BindingFlags.NonPublic); -  
75 if (pi == null) -  
76 { 68 BindingFlags.Instance | BindingFlags.NonPublic);
77 return false; -  
Line 78... Line 69...
78 } 69 if (pi == null) return false;
Line 79... Line 70...
79   70  
80 pi.SetValue(control, true, null); 71 pi.SetValue(control, true, null);
Line 85... Line 76...
85 public static async Task<Icon> CreateIconFromResource(string resource) 76 public static async Task<Icon> CreateIconFromResource(string resource)
86 { 77 {
87 var iconBytes = await LoadResource(resource); 78 var iconBytes = await LoadResource(resource);
88 using (var iconMemoryStream = new MemoryStream(iconBytes)) 79 using (var iconMemoryStream = new MemoryStream(iconBytes))
89 { 80 {
90 var bitmap = (Bitmap) Image.FromStream(iconMemoryStream); 81 var bitmap = (Bitmap)Image.FromStream(iconMemoryStream);
91 var bitmapIntPtr = bitmap.GetHicon(); 82 var bitmapIntPtr = bitmap.GetHicon();
92 var icon = Icon.FromHandle(bitmapIntPtr); 83 var icon = Icon.FromHandle(bitmapIntPtr);
93 return icon; 84 return icon;
94 } 85 }
95 } 86 }
Line 98... Line 89...
98 { 89 {
99 var assembly = Assembly.GetExecutingAssembly(); 90 var assembly = Assembly.GetExecutingAssembly();
Line 100... Line 91...
100   91  
101 using (var manifestResourceStream = assembly.GetManifestResourceStream(resource)) 92 using (var manifestResourceStream = assembly.GetManifestResourceStream(resource))
102 { 93 {
103 if (manifestResourceStream == null) -  
104 { -  
105 return null; -  
Line 106... Line 94...
106 } 94 if (manifestResourceStream == null) return null;
Line 107... Line 95...
107   95  
Line 117... Line 105...
117   105  
118 public static void InvokeIfRequired<T>(this T control, Action<T> action) where T : Control 106 public static void InvokeIfRequired<T>(this T control, Action<T> action) where T : Control
119 { 107 {
120 if (control.InvokeRequired) 108 if (control.InvokeRequired)
121 { 109 {
122 control.BeginInvoke((MethodInvoker) delegate { action(control); }); 110 control.BeginInvoke((MethodInvoker)delegate { action(control); });
123 return; 111 return;
Line 124... Line 112...
124 } 112 }
125   113  
Line 126... Line 114...
126 action(control); 114 action(control);
127 } 115 }
128   116  
129 public static T MapValueToRange<T>(this T value, T xMin, T xMax, T yMin, T yMax) 117 public static T MapValueToRange<T>(this T value, T xMin, T xMax, T yMin, T yMax)
130 where T : struct, IComparable<T>, IConvertible 118 where T : struct, IComparable<T>, IConvertible
131 { 119 {
132 return (dynamic) yMin + 120 return (dynamic)yMin +
Line 133... Line 121...
133 ((dynamic) yMax - (dynamic) yMin) * ((dynamic) value - (dynamic) xMin) / 121 ((dynamic)yMax - (dynamic)yMin) * ((dynamic)value - (dynamic)xMin) /
134 ((dynamic) xMax - (dynamic) xMin); 122 ((dynamic)xMax - (dynamic)xMin);
135 } 123 }
136   124  
137 public static IEnumerable<TU> SequenceSubtract<TU, TV>(this IEnumerable<TU> a, 125 public static IEnumerable<TU> SequenceSubtract<TU, TV>(this IEnumerable<TU> a,
Line 138... Line 126...
138 IEnumerable<TV> b, 126 IEnumerable<TV> b,
139 Func<TU, TV, bool> cmp) 127 Func<TU, TV, bool> cmp)
140 { 128 {
141 var eb = new List<TV>(b); 129 var eb = new List<TV>(b);
142   130  
143 using (var ea = a.GetEnumerator()) -  
144 { -  
145 while (ea.MoveNext()) -  
Line 146... Line 131...
146 { 131 using (var ea = a.GetEnumerator())
147 if (ea.Current == null) 132 {
148 { 133 while (ea.MoveNext())
149 continue; -  
150 } -  
151   -  
Line 152... Line 134...
152 foreach (var ib in eb) 134 {
Line 153... Line 135...
153 { 135 if (ea.Current == null) continue;
154 if (cmp.Invoke(ea.Current, ib)) 136  
Line 173... Line 155...
173 { 155 {
174 var location = @"SOFTWARE\Microsoft\Cryptography"; 156 var location = @"SOFTWARE\Microsoft\Cryptography";
175 var name = "MachineGuid"; 157 var name = "MachineGuid";
Line 176... Line 158...
176   158  
177 using (var localMachineX64View = 159 using (var localMachineX64View =
178 RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)) 160 RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
179 { 161 {
180 using (var rk = localMachineX64View.OpenSubKey(location)) 162 using (var rk = localMachineX64View.OpenSubKey(location))
181 { 163 {
182 if (rk == null) -  
183 { 164 if (rk == null)
184 throw new KeyNotFoundException( 165 throw new KeyNotFoundException(
185 string.Format("Key Not Found: {0}", location)); -  
Line 186... Line 166...
186 } 166 string.Format("Key Not Found: {0}", location));
187   167  
188 var machineGuid = rk.GetValue(name); -  
189 if (machineGuid == null) 168 var machineGuid = rk.GetValue(name);
190 { 169 if (machineGuid == null)
191 throw new IndexOutOfRangeException( -  
Line 192... Line 170...
192 string.Format("Index Not Found: {0}", name)); 170 throw new IndexOutOfRangeException(
193 } 171 string.Format("Index Not Found: {0}", name));
194   172  
195 return machineGuid.ToString(); 173 return machineGuid.ToString();