Browse Source

Bug fix: Failure when coping local custom command that works with remote files to clipboard

(cherry picked from commit c872a68bc6dd90255e56ff6ea73e3079f0268d27)

Source commit: cc94631020792f239cfa233e17b3ecca8a422d74
Martin Prikryl 8 years ago
parent
commit
9682fba07d
1 changed files with 24 additions and 14 deletions
  1. 24 14
      source/windows/GUITools.cpp

+ 24 - 14
source/windows/GUITools.cpp

@@ -218,7 +218,14 @@ static bool __fastcall DoExecuteShell(const UnicodeString Path, const UnicodeStr
 {
   bool Result = CopyCommandToClipboard(FormatCommand(Path, Params));
 
-  if (!Result)
+  if (Result)
+  {
+    if (Handle != NULL)
+    {
+      *Handle = NULL;
+    }
+  }
+  else
   {
     UnicodeString Directory = ExtractFilePath(Path);
 
@@ -280,24 +287,27 @@ void __fastcall ExecuteShellCheckedAndWait(const UnicodeString Command,
   }
   else
   {
-    if (ProcessMessages != NULL)
+    if (ProcessHandle != NULL) // only if command was copied to clipboard only
     {
-      unsigned long WaitResult;
-      do
+      if (ProcessMessages != NULL)
       {
-        // Same as in ExecuteProcessAndReadOutput
-        WaitResult = WaitForSingleObject(ProcessHandle, 200);
-        if (WaitResult == WAIT_FAILED)
+        unsigned long WaitResult;
+        do
         {
-          throw Exception(LoadStr(DOCUMENT_WAIT_ERROR));
+          // Same as in ExecuteProcessAndReadOutput
+          WaitResult = WaitForSingleObject(ProcessHandle, 200);
+          if (WaitResult == WAIT_FAILED)
+          {
+            throw Exception(LoadStr(DOCUMENT_WAIT_ERROR));
+          }
+          ProcessMessages();
         }
-        ProcessMessages();
+        while (WaitResult == WAIT_TIMEOUT);
+      }
+      else
+      {
+        WaitForSingleObject(ProcessHandle, INFINITE);
       }
-      while (WaitResult == WAIT_TIMEOUT);
-    }
-    else
-    {
-      WaitForSingleObject(ProcessHandle, INFINITE);
     }
   }
 }