From 718572c8f59deb5ef4480d8ec288d16467b91b5b Mon Sep 17 00:00:00 2001 From: wj32 Date: Thu, 15 Oct 2009 02:47:24 +0000 Subject: [PATCH] * removed InformationBox "fix" - that's not PH's fault * fixed NativeUtils.ObjectExists git-svn-id: svn://svn.code.sf.net/p/processhacker/code@2183 21ef857c-d57f-4fe0-8362-d861dc6d29cd --- trunk/ProcessHacker.Native/NativeUtils.cs | 4 +-- trunk/ProcessHacker/Forms/InformationBox.cs | 1 - trunk/ProcessHacker/Program/Program.cs | 40 ++++++++------------- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/trunk/ProcessHacker.Native/NativeUtils.cs b/trunk/ProcessHacker.Native/NativeUtils.cs index 0e78c2e31..50db057ac 100644 --- a/trunk/ProcessHacker.Native/NativeUtils.cs +++ b/trunk/ProcessHacker.Native/NativeUtils.cs @@ -235,7 +235,7 @@ namespace ProcessHacker.Native string[] s = name.Split('\\'); string lastPart = s[s.Length - 1]; - string dirPart = name.Substring(0, name.Length - s.Length - 1); // -1 char to leave out the trailing backslash + string dirPart = name.Substring(0, name.Length - lastPart.Length - 1); // -1 char to leave out the trailing backslash try { @@ -249,7 +249,7 @@ namespace ProcessHacker.Native return true; } - return true; + return false; } } catch (WindowsException) diff --git a/trunk/ProcessHacker/Forms/InformationBox.cs b/trunk/ProcessHacker/Forms/InformationBox.cs index f4ca4580d..a85f1bbe2 100644 --- a/trunk/ProcessHacker/Forms/InformationBox.cs +++ b/trunk/ProcessHacker/Forms/InformationBox.cs @@ -79,7 +79,6 @@ namespace ProcessHacker SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = DefaultFileName; - sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); sfd.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"; if (sfd.ShowDialog() == DialogResult.OK) diff --git a/trunk/ProcessHacker/Program/Program.cs b/trunk/ProcessHacker/Program/Program.cs index 5aa769e5d..50d36d8d3 100644 --- a/trunk/ProcessHacker/Program/Program.cs +++ b/trunk/ProcessHacker/Program/Program.cs @@ -682,36 +682,26 @@ namespace ProcessHacker } public static bool CheckPreviousInstance() - { - //get the list of all processes by the name of our process - //if Length > 1 then there is more than one process running... - return (System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Process.GetCurrentProcess().ProcessName).Length > 1); - - - //GlobalMutex doesnt get released until all app instances have exited, - //we cant use that mutux for checking previous instances - //for this type of Previous Instance checking without mataining - //a list of instances and releasing the mutux when theres only one instance left running. - + { // Close the handle to the mutex. If the object still exists, // it means there is another handle to the mutex, and most likely // there is another instance of PH running. - - //if (GlobalMutex == null) - // return false; - //GlobalMutex.Dispose(); - //GlobalMutex = null; + if (GlobalMutex == null) + return false; - //try - //{ - // return NativeUtils.ObjectExists(GlobalMutexName); - //} - //finally - //{ - // try { GlobalMutex = new ProcessHacker.Native.Threading.Mutant(GlobalMutexName); } - // catch { } - //} + GlobalMutex.Dispose(); + GlobalMutex = null; + + try + { + return NativeUtils.ObjectExists(GlobalMutexName); + } + finally + { + try { GlobalMutex = new ProcessHacker.Native.Threading.Mutant(GlobalMutexName); } + catch { } + } } private static void ActivatePreviousInstance()