Skip to content

Commit

Permalink
fixed coding standard
Browse files Browse the repository at this point in the history
  • Loading branch information
JanTvrdik committed Sep 6, 2015
1 parent 6b8a779 commit a185182
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/app/IProcessManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal interface IProcessManager
{
string Name { get; }
bool IsRunning();
string GroupName { get; }
string GroupName { get; }
Task Start();
Task Stop();
Task Restart();
Expand Down
6 changes: 3 additions & 3 deletions src/app/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ private static void Main()

private static void injectRunningProcesses(List<ProcessManager> processManagers, string fileName)
{
var list = new Dictionary<ProcessManager,List<Tuple<int,int>>>();
var list = new Dictionary<ProcessManager, List<Tuple<int, int>>>();
foreach (var processManager in processManagers)
{
list.Add(processManager, new List<Tuple<int,int>>());
list.Add(processManager, new List<Tuple<int, int>>());
}

string wmiQuery = string.Format("select CommandLine, ProcessId, ParentProcessID from Win32_Process where Name='{0}'", fileName);
ManagementObjectCollection managementObjects = (new ManagementObjectSearcher(wmiQuery)).Get();
foreach (ManagementObject managementObject in managementObjects)
{
string line = (string)(managementObject["CommandLine"]);
string line = (string) (managementObject["CommandLine"]);
foreach (var processManager in processManagers)
{
if (line != null && line.Contains(processManager.Arguments))
Expand Down
76 changes: 38 additions & 38 deletions src/app/Symlinks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@
namespace PhpVersionSwitcher
{
internal static class Symlinks
{
private const int CreationDispositionOpenExisting = 3;
private const int FileFlagBackupSemantics = 0x02000000;
private const int SymbolicLinkFlagDirectory = 1;

// http://msdn.microsoft.com/en-us/library/aa364962(v=vs.85).aspx
[DllImport("kernel32.dll", EntryPoint = "GetFinalPathNameByHandleW", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int GetFinalPathNameByHandle(IntPtr handle, [In, Out] StringBuilder path, int bufLen, int flags);

// http://msdn.microsoft.com/en-us/library/aa363858(v=vs.85).aspx
[DllImport("kernel32.dll", EntryPoint = "CreateFileW", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern SafeFileHandle CreateFile(string lpFileName, int dwDesiredAccess, int dwShareMode, IntPtr securityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);

// http://msdn.microsoft.com/en-us/library/aa363866(v=vs.85).aspx
[DllImport("kernel32.dll", EntryPoint = "CreateSymbolicLinkW", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, int dwFlags);
 
public static string GetTarget(string symlink)
{
SafeFileHandle fileHandle = CreateFile(symlink, 0, 2, IntPtr.Zero, CreationDispositionOpenExisting, FileFlagBackupSemantics, IntPtr.Zero);
if (fileHandle.IsInvalid) throw new Win32Exception(Marshal.GetLastWin32Error());

var path = new StringBuilder(512);
int size = GetFinalPathNameByHandle(fileHandle.DangerousGetHandle(), path, path.Capacity, 0);
if (size < 0) throw new Win32Exception(Marshal.GetLastWin32Error());

// The remarks section of GetFinalPathNameByHandle mentions the return being prefixed with "\\?\"
// More information about "\\?\" here -> http://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx
var pathStr = path.ToString();
if (pathStr.StartsWith(@"\\?\")) pathStr = pathStr.Substring(4);
return pathStr;
}

public static bool CreateDir(string symlink, string target)
{
return CreateSymbolicLink(symlink, target, SymbolicLinkFlagDirectory);
}
}
{
private const int CreationDispositionOpenExisting = 3;
private const int FileFlagBackupSemantics = 0x02000000;
private const int SymbolicLinkFlagDirectory = 1;

// http://msdn.microsoft.com/en-us/library/aa364962(v=vs.85).aspx
[DllImport("kernel32.dll", EntryPoint = "GetFinalPathNameByHandleW", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int GetFinalPathNameByHandle(IntPtr handle, [In, Out] StringBuilder path, int bufLen, int flags);

// http://msdn.microsoft.com/en-us/library/aa363858(v=vs.85).aspx
[DllImport("kernel32.dll", EntryPoint = "CreateFileW", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern SafeFileHandle CreateFile(string lpFileName, int dwDesiredAccess, int dwShareMode, IntPtr securityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile);

// http://msdn.microsoft.com/en-us/library/aa363866(v=vs.85).aspx
[DllImport("kernel32.dll", EntryPoint = "CreateSymbolicLinkW", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, int dwFlags);

public static string GetTarget(string symlink)
{
SafeFileHandle fileHandle = CreateFile(symlink, 0, 2, IntPtr.Zero, CreationDispositionOpenExisting, FileFlagBackupSemantics, IntPtr.Zero);
if (fileHandle.IsInvalid) throw new Win32Exception(Marshal.GetLastWin32Error());

var path = new StringBuilder(512);
int size = GetFinalPathNameByHandle(fileHandle.DangerousGetHandle(), path, path.Capacity, 0);
if (size < 0) throw new Win32Exception(Marshal.GetLastWin32Error());

// The remarks section of GetFinalPathNameByHandle mentions the return being prefixed with "\\?\"
// More information about "\\?\" here -> http://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx
var pathStr = path.ToString();
if (pathStr.StartsWith(@"\\?\")) pathStr = pathStr.Substring(4);
return pathStr;
}

public static bool CreateDir(string symlink, string target)
{
return CreateSymbolicLink(symlink, target, SymbolicLinkFlagDirectory);
}
}
}
2 changes: 1 addition & 1 deletion src/app/VersionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private Task UpdatePhpIni(Version version)
{
return Task.Run(() =>
{
var files = new string[]
var files = new[]
{
version.Major + ".x.x.ini",
version.Major + "." + version.Minor + ".x.ini",
Expand Down
14 changes: 7 additions & 7 deletions src/ui/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private void InitializeMainMenu()
this.notifyIconMenu.Items.Clear();
this.notifyIconMenu.Items.AddRange(this.CreateVersionsItems());
this.notifyIconMenu.Items.Add(new ToolStripSeparator());
var menuGroups = new Dictionary<string, List<ProcessMenu> >();
var menuGroups = new Dictionary<string, List<ProcessMenu>>();

var running = false;
foreach (var pm in this.processManagers)
Expand Down Expand Up @@ -57,15 +57,15 @@ private void InitializeMainMenu()
foreach (var pair in menuGroups)
{
var menu = new ProcessMenuGroup(pair.Key, pair.Value);
var startTasks = new Func<Task>[pair.Value.Count];
var stopTasks = new Func<Task>[pair.Value.Count];
var startTasks = new Func<Task>[pair.Value.Count];
var stopTasks = new Func<Task>[pair.Value.Count];
var restartTasks = new Func<Task>[pair.Value.Count];

var i = 0;
foreach (var processMenu in pair.Value)
{
startTasks[i] = processMenu.ProcessManager.Start;
stopTasks[i] = processMenu.ProcessManager.Stop;
startTasks[i] = processMenu.ProcessManager.Start;
stopTasks[i] = processMenu.ProcessManager.Stop;
restartTasks[i] = processMenu.ProcessManager.Restart;
i += 1;
}
Expand All @@ -79,7 +79,7 @@ private void InitializeMainMenu()
this.notifyIconMenu.Items.Add(new ToolStripSeparator());
this.notifyIconMenu.Items.Add("Refresh", null, (sender, args) => this.InitializeMainMenu());
this.notifyIconMenu.Items.Add("Close", null, (sender, args) => Application.Exit());
this.notifyIcon.Icon = running ? Resources.Icon_started : Resources.Icon_stopped;
this.notifyIcon.Icon = running ? Resources.Icon_started : Resources.Icon_stopped;
}

private ToolStripMenuItem[] CreateVersionsItems()
Expand Down Expand Up @@ -139,7 +139,7 @@ private async void Attempt(string description, Func<Task> action)
if (dialogResult != DialogResult.Retry) break;
}
}

this.InitializeMainMenu();
this.waitingForm.Hide();
this.notifyIconMenu.Enabled = true;
Expand Down

0 comments on commit a185182

Please sign in to comment.