Skip to content

Commit 8d6fc23

Browse files
committed
Refactored code.
1 parent 993df13 commit 8d6fc23

27 files changed

+405
-402
lines changed

SmartSystemMenu/AutoStarter.cs

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
52
using System.Diagnostics;
63
using Microsoft.Win32;
74

85
namespace SmartSystemMenu
96
{
107
static class AutoStarter
118
{
12-
private const String RUN_LOCATION = @"Software\Microsoft\Windows\CurrentVersion\Run";
9+
private const string RUN_LOCATION = @"Software\Microsoft\Windows\CurrentVersion\Run";
1310

14-
public static void SetAutoStartByRegister(String keyName, String assemblyLocation)
11+
public static void SetAutoStartByRegister(string keyName, string assemblyLocation)
1512
{
16-
RegistryKey key = Registry.CurrentUser.CreateSubKey(RUN_LOCATION);
17-
key.SetValue(keyName, assemblyLocation);
13+
using (var key = Registry.CurrentUser.CreateSubKey(RUN_LOCATION))
14+
{
15+
key.SetValue(keyName, assemblyLocation);
16+
}
1817
}
1918

20-
public static void UnsetAutoStartByRegister(String keyName)
19+
public static void UnsetAutoStartByRegister(string keyName)
2120
{
22-
RegistryKey key = Registry.CurrentUser.CreateSubKey(RUN_LOCATION);
23-
key.DeleteValue(keyName);
21+
using (var key = Registry.CurrentUser.CreateSubKey(RUN_LOCATION))
22+
{
23+
key.DeleteValue(keyName);
24+
}
2425
}
2526

26-
public static void SetAutoStartByScheduler(String keyName, String assemblyLocation)
27+
public static void SetAutoStartByScheduler(string keyName, string assemblyLocation)
2728
{
28-
String fileName = "schtasks.exe";
29-
String arguments = "/create /sc onlogon /tn \"{0}\" /rl highest /tr \"{1}\"";
30-
arguments = String.Format(arguments, keyName, assemblyLocation);
31-
Process scheduleProcess = new Process();
29+
var fileName = "schtasks.exe";
30+
var arguments = "/create /sc onlogon /tn \"{0}\" /rl highest /tr \"{1}\"";
31+
arguments = string.Format(arguments, keyName, assemblyLocation);
32+
var scheduleProcess = new Process();
3233
scheduleProcess.StartInfo.CreateNoWindow = true;
3334
scheduleProcess.StartInfo.UseShellExecute = false;
3435
scheduleProcess.StartInfo.FileName = fileName;
@@ -40,12 +41,12 @@ public static void SetAutoStartByScheduler(String keyName, String assemblyLocati
4041
}
4142
}
4243

43-
public static void UnsetAutoStartByScheduler(String keyName)
44+
public static void UnsetAutoStartByScheduler(string keyName)
4445
{
45-
String fileName = "schtasks.exe";
46-
String arguments = "/delete /tn \"{0}\" /f";
47-
arguments = String.Format(arguments, keyName);
48-
Process scheduleProcess = new Process();
46+
string fileName = "schtasks.exe";
47+
string arguments = "/delete /tn \"{0}\" /f";
48+
arguments = string.Format(arguments, keyName);
49+
var scheduleProcess = new Process();
4950
scheduleProcess.StartInfo.CreateNoWindow = true;
5051
scheduleProcess.StartInfo.UseShellExecute = false;
5152
scheduleProcess.StartInfo.FileName = fileName;
@@ -57,14 +58,16 @@ public static void UnsetAutoStartByScheduler(String keyName)
5758
}
5859
}
5960

60-
public static Boolean IsAutoStartByRegisterEnabled(String keyName, String assemblyLocation)
61+
public static bool IsAutoStartByRegisterEnabled(string keyName, string assemblyLocation)
6162
{
62-
RegistryKey key = Registry.CurrentUser.OpenSubKey(RUN_LOCATION);
63-
if (key == null) return false;
64-
String value = (String)key.GetValue(keyName);
65-
if (String.IsNullOrEmpty(value)) return false;
66-
Boolean result = (value == assemblyLocation);
67-
return result;
63+
using (var key = Registry.CurrentUser.OpenSubKey(RUN_LOCATION))
64+
{
65+
if (key == null) return false;
66+
string value = (string)key.GetValue(keyName);
67+
if (string.IsNullOrEmpty(value)) return false;
68+
var result = (value == assemblyLocation);
69+
return result;
70+
}
6871
}
6972
}
7073
}

SmartSystemMenu/EnumWindows.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ namespace SmartSystemMenu
1010
{
1111
static class EnumWindows
1212
{
13-
private static String[] _filterTitles;
13+
private static string[] _filterTitles;
1414
private static IntPtr[] _filterHandles;
1515
private static IList<Window> _windows;
1616

17-
public static IList<Window> EnumAllWindows(params String[] filterTitles)
17+
public static IList<Window> EnumAllWindows(params string[] filterTitles)
1818
{
19-
_filterTitles = filterTitles ?? new String[0];
19+
_filterTitles = filterTitles ?? new string[0];
2020
_filterHandles = new IntPtr[0];
2121
_windows = new List<Window>();
2222
NativeMethods.EnumWindows(EnumWindowCallback, 0);
2323
return _windows;
2424
}
2525

26-
public static IList<Window> EnumProcessWindows(Int32 processId, IntPtr[] filterHandles, params String[] filterTitles)
26+
public static IList<Window> EnumProcessWindows(int processId, IntPtr[] filterHandles, params string[] filterTitles)
2727
{
28-
_filterTitles = filterTitles ?? new String[0];
28+
_filterTitles = filterTitles ?? new string[0];
2929
_filterHandles = filterHandles ?? new IntPtr[0];
3030
_windows = new List<Window>();
3131
foreach (ProcessThread thread in Process.GetProcessById(processId).Threads)
@@ -35,13 +35,13 @@ public static IList<Window> EnumProcessWindows(Int32 processId, IntPtr[] filterH
3535
return _windows;
3636
}
3737

38-
private static Boolean EnumWindowCallback(IntPtr hwnd, Int32 lParam)
38+
private static bool EnumWindowCallback(IntPtr hwnd, int lParam)
3939
{
4040
if (_filterHandles.Any(h => h == hwnd)) return true;
4141
if (_windows.Any(w => w.Handle == hwnd)) return true;
4242

43-
Int32 pid;
44-
Boolean isAdd;
43+
int pid;
44+
bool isAdd;
4545
NativeMethods.GetWindowThreadProcessId(hwnd, out pid);
4646

4747
#if WIN32

SmartSystemMenu/Extensions/PriorityExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ namespace SmartSystemMenu.Extensions
77
{
88
static class PriorityExtensions
99
{
10-
public static Int32 GetMenuItemId(this Priority priority)
10+
public static int GetMenuItemId(this Priority priority)
1111
{
1212
switch (priority)
1313
{
14-
case Priority.RealTime: return (Int32)SystemMenu.SC_PRIORITY_REAL_TIME;
15-
case Priority.High: return (Int32)SystemMenu.SC_PRIORITY_HIGH;
16-
case Priority.AboveNormal: return (Int32)SystemMenu.SC_PRIORITY_ABOVE_NORMAL;
17-
case Priority.Normal: return (Int32)SystemMenu.SC_PRIORITY_NORMAL;
18-
case Priority.BelowNormal: return (Int32)SystemMenu.SC_PRIORITY_BELOW_NORMAL;
19-
case Priority.Idle: return (Int32)SystemMenu.SC_PRIORITY_IDLE;
20-
default: return (Int32)SystemMenu.SC_PRIORITY_NORMAL;
14+
case Priority.RealTime: return (int)SystemMenu.SC_PRIORITY_REAL_TIME;
15+
case Priority.High: return (int)SystemMenu.SC_PRIORITY_HIGH;
16+
case Priority.AboveNormal: return (int)SystemMenu.SC_PRIORITY_ABOVE_NORMAL;
17+
case Priority.Normal: return (int)SystemMenu.SC_PRIORITY_NORMAL;
18+
case Priority.BelowNormal: return (int)SystemMenu.SC_PRIORITY_BELOW_NORMAL;
19+
case Priority.Idle: return (int)SystemMenu.SC_PRIORITY_IDLE;
20+
default: return (int)SystemMenu.SC_PRIORITY_NORMAL;
2121
}
2222
}
2323

SmartSystemMenu/Extensions/ProcessExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ namespace SmartSystemMenu.Extensions
88
{
99
static class ProcessExtensions
1010
{
11-
public static Boolean ExistProcessWithSameNameAndDesktop(this Process currentProcess)
11+
public static bool ExistProcessWithSameNameAndDesktop(this Process currentProcess)
1212
{
1313
foreach (Process process in Process.GetProcessesByName(currentProcess.ProcessName))
1414
{
1515
if (currentProcess.Id != process.Id)
1616
{
17-
Int32 processThreadId = process.GetMainThreadId();
18-
Int32 currentProcessThreadId = currentProcess.GetMainThreadId();
17+
int processThreadId = process.GetMainThreadId();
18+
int currentProcessThreadId = currentProcess.GetMainThreadId();
1919
IntPtr processDesktop = NativeMethods.GetThreadDesktop(processThreadId);
2020
IntPtr currentProcessDesktop = NativeMethods.GetThreadDesktop(currentProcessThreadId);
2121
if (currentProcessDesktop == processDesktop) return true;
@@ -24,9 +24,9 @@ public static Boolean ExistProcessWithSameNameAndDesktop(this Process currentPro
2424
return false;
2525
}
2626

27-
public static Int32 GetMainThreadId(this Process currentProcess)
27+
public static int GetMainThreadId(this Process currentProcess)
2828
{
29-
Int32 mainThreadId = -1;
29+
int mainThreadId = -1;
3030
DateTime startTime = DateTime.MaxValue;
3131
foreach (ProcessThread thread in currentProcess.Threads)
3232
{

SmartSystemMenu/Forms/AboutForm.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ namespace SmartSystemMenu.Forms
66
{
77
partial class AboutForm : Form
88
{
9-
private const String URL = "http://illarionov.pro";
9+
private const string URL = "http://illarionov.pro";
1010

1111
public AboutForm()
1212
{
1313
InitializeComponent();
1414
Text = "About " + AssemblyUtils.AssemblyProductName;
15-
lblProductName.Text = String.Format("{0} v{1}", AssemblyUtils.AssemblyProductName, AssemblyUtils.AssemblyVersion);
16-
lblCopyright.Text = String.Format("{0}-{1} {2}", AssemblyUtils.AssemblyCopyright, DateTime.Now.Year, AssemblyUtils.AssemblyCompany);
15+
lblProductName.Text = string.Format("{0} v{1}", AssemblyUtils.AssemblyProductName, AssemblyUtils.AssemblyVersion);
16+
lblCopyright.Text = string.Format("{0}-{1} {2}", AssemblyUtils.AssemblyCopyright, DateTime.Now.Year, AssemblyUtils.AssemblyCompany);
1717
linkUrl.Text = URL;
1818
}
1919

SmartSystemMenu/Forms/InfoForm.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ private void InitializeControls()
2929
txtCaptionValue.Text = _window.WindowText;
3030
txtClassValue.Text = _window.ClassName;
3131
lblStyleValue.Text = _window.Style.ToString("X8");
32-
lblRectangleValue.Text = String.Format("({0},{1}) - ({2},{3}) - {4}x{5}", _window.Size.Left, _window.Size.Top, _window.Size.Right, _window.Size.Bottom, _window.Size.Width, _window.Size.Height);
33-
lblProcessIdValue.Text = String.Format("{0:X8} ({0})", _window.ProcessId);
34-
lblThreadIdValue.Text = String.Format("{0:X8} ({0})", _window.ThreadId);
32+
lblRectangleValue.Text = string.Format("({0},{1}) - ({2},{3}) - {4}x{5}", _window.Size.Left, _window.Size.Top, _window.Size.Right, _window.Size.Bottom, _window.Size.Width, _window.Size.Height);
33+
lblProcessIdValue.Text = string.Format("{0:X8} ({0})", _window.ProcessId);
34+
lblThreadIdValue.Text = string.Format("{0:X8} ({0})", _window.ThreadId);
3535
Process process = Process.GetProcessById(_window.ProcessId);
3636
txtModuleNameValue.Text = Path.GetFileName(process.MainModule.FileName);
3737
txtModulePathValue.Text = process.MainModule.FileName;

0 commit comments

Comments
 (0)