Przeglądaj źródła

Using extension homepage as help page for its output and errors

Source commit: 1ed407212f3552c0ac7e19eaf033fb739fd48756
Martin Prikryl 9 lat temu
rodzic
commit
5febe9d5e2

+ 10 - 9
source/forms/CustomScpExplorer.cpp

@@ -1675,6 +1675,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
 
   TCustomCommandData Data(Terminal);
   UnicodeString Site = Terminal->SessionData->SessionKey;
+  UnicodeString HelpKeyword = ACommand.HomePage;
 
   std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
   if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
@@ -1780,7 +1781,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
 
     if (!LocalCustomCommand.IsFileCommand(Command))
     {
-      ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), POutput.get());
+      ExecuteProcessChecked(LocalCustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
     }
     // remote files?
     else if ((FCurrentSide == osRemote) || LocalFileCommand)
@@ -1890,7 +1891,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
               }
               else
               {
-                ExecuteProcessCheckedAndWait(ShellCommand, POutput.get());
+                ExecuteProcessCheckedAndWait(ShellCommand, HelpKeyword, POutput.get());
               }
             }
             else if (LocalFileCommand)
@@ -1904,7 +1905,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
                   UnicodeString FileName = RemoteFileList->Strings[Index];
                   TLocalCustomCommand CustomCommand(Data,
                     Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(), FileName, LocalFile, L"");
-                  ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), POutput.get());
+                  ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
                 }
               }
               else if (RemoteFileList->Count == 1)
@@ -1916,7 +1917,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
                   TLocalCustomCommand CustomCommand(
                     Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
                     FileName, LocalFileList->Strings[Index], L"");
-                  ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), POutput.get());
+                  ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
                 }
               }
               else
@@ -1932,7 +1933,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
                   TLocalCustomCommand CustomCommand(
                     Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
                     FileName, LocalFileList->Strings[Index], L"");
-                  ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), POutput.get());
+                  ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
                 }
               }
             }
@@ -1943,7 +1944,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
                 TLocalCustomCommand CustomCommand(Data,
                   Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
                   RemoteFileList->Strings[Index], L"", L"");
-                ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), POutput.get());
+                ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
               }
             }
           }
@@ -2053,7 +2054,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
         TLocalCustomCommand CustomCommand(
           Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
           L"", L"", FileList);
-        ExecuteProcessChecked(CustomCommand.Complete(Command, true), POutput.get());
+        ExecuteProcessChecked(CustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
       }
       else
       {
@@ -2071,7 +2072,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
             TLocalCustomCommand CustomCommand(
               Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory(),
               FileName, L"", L"");
-            ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), POutput.get());
+            ExecuteProcessCheckedAndWait(CustomCommand.Complete(Command, true), HelpKeyword, POutput.get());
           }
         }
         __finally
@@ -2099,7 +2100,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
       if (FLAGSET(ACommand.Params, ccShowResultsInMsgBox) &&
           !POutput->IsEmpty())
       {
-        MessageDialog(*POutput, qtInformation, qaOK);
+        MessageDialog(*POutput, qtInformation, qaOK, HelpKeyword);
       }
     }
   }

+ 18 - 6
source/windows/Tools.cpp

@@ -295,7 +295,8 @@ UnicodeString __fastcall StoreFormSize(TForm * Form)
   return FORMAT(L"%d,%d,%s", (Form->Width, Form->Height, SavePixelsPerInch()));
 }
 //---------------------------------------------------------------------------
-static void __fastcall ExecuteProcessAndReadOutput(const UnicodeString & Command, UnicodeString & Output)
+static void __fastcall ExecuteProcessAndReadOutput(const
+  UnicodeString & Command, const UnicodeString & HelpKeyword, UnicodeString & Output)
 {
   SECURITY_ATTRIBUTES SecurityAttributes;
   ZeroMemory(&SecurityAttributes, sizeof(SecurityAttributes));
@@ -353,7 +354,16 @@ static void __fastcall ExecuteProcessAndReadOutput(const UnicodeString & Command
     if (DebugAlwaysTrue(GetExitCodeProcess(ProcessInformation.hProcess, &ExitCode)) &&
         (ExitCode != 0))
     {
-      throw ExtException(MainInstructions(FMTLOAD(COMMAND_FAILED_CODEONLY, (static_cast<int>(ExitCode)))), Output);
+      UnicodeString Buf = Output;
+      UnicodeString Buf2;
+      if (ExtractMainInstructions(Buf, Buf2))
+      {
+        throw ExtException(Output, UnicodeString(), HelpKeyword);
+      }
+      else
+      {
+        throw ExtException(MainInstructions(FMTLOAD(COMMAND_FAILED_CODEONLY, (static_cast<int>(ExitCode)))), Output, HelpKeyword);
+      }
     }
   }
   __finally
@@ -363,7 +373,8 @@ static void __fastcall ExecuteProcessAndReadOutput(const UnicodeString & Command
   }
 }
 //---------------------------------------------------------------------------
-void __fastcall ExecuteProcessChecked(const UnicodeString & Command, UnicodeString * Output)
+void __fastcall ExecuteProcessChecked(
+  const UnicodeString & Command, const UnicodeString & HelpKeyword, UnicodeString * Output)
 {
   if (Output == NULL)
   {
@@ -371,11 +382,12 @@ void __fastcall ExecuteProcessChecked(const UnicodeString & Command, UnicodeStri
   }
   else
   {
-    ExecuteProcessAndReadOutput(Command, *Output);
+    ExecuteProcessAndReadOutput(Command, HelpKeyword, *Output);
   }
 }
 //---------------------------------------------------------------------------
-void __fastcall ExecuteProcessCheckedAndWait(const UnicodeString & Command, UnicodeString * Output)
+void __fastcall ExecuteProcessCheckedAndWait(
+  const UnicodeString & Command, const UnicodeString & HelpKeyword, UnicodeString * Output)
 {
   if (Output == NULL)
   {
@@ -383,7 +395,7 @@ void __fastcall ExecuteProcessCheckedAndWait(const UnicodeString & Command, Unic
   }
   else
   {
-    ExecuteProcessAndReadOutput(Command, *Output);
+    ExecuteProcessAndReadOutput(Command, HelpKeyword, *Output);
   }
 }
 //---------------------------------------------------------------------------

+ 4 - 2
source/windows/Tools.h

@@ -10,8 +10,10 @@
 #include <Vcl.Graphics.hpp>
 //---------------------------------------------------------------------------
 void __fastcall CenterFormOn(TForm * Form, TControl * CenterOn);
-void __fastcall ExecuteProcessChecked(const UnicodeString & Command, UnicodeString * Output);
-void __fastcall ExecuteProcessCheckedAndWait(const UnicodeString & Command, UnicodeString * Output);
+void __fastcall ExecuteProcessChecked(
+  const UnicodeString & Command, const UnicodeString & HelpKeyword, UnicodeString * Output);
+void __fastcall ExecuteProcessCheckedAndWait(
+  const UnicodeString & Command, const UnicodeString & HelpKeyword, UnicodeString * Output);
 bool __fastcall IsKeyPressed(int VirtualKey);
 bool __fastcall UseAlternativeFunction();
 bool __fastcall OpenInNewWindow();